{"id":341,"date":"2019-04-01T19:20:48","date_gmt":"2019-04-01T19:20:48","guid":{"rendered":"http:\/\/www.hoopchuk.org\/wordpress\/?page_id=341"},"modified":"2019-04-02T13:06:56","modified_gmt":"2019-04-02T13:06:56","slug":"code-stuff","status":"publish","type":"page","link":"https:\/\/www.hoopchuk.org\/wordpress\/code-stuff\/","title":{"rendered":"Code Stuff"},"content":{"rendered":"<h1>Summary<\/h1>\n<p>Stuff I getted asked about on interviews. It&#8217;s a compilation of things I learned across talking to many folks about paying me to do what I find interesting and am passionate about. I can never directly thank these people stumping me and prompting me to keep on learning and growing and getting better &#8230; <em>THANK YOU !!!<\/em><\/p>\n<h1>TODOs<\/h1>\n<p>There are no &#8220;TODOs&#8221; I can think of on 01APR2019MON:<\/p>\n<ol>\n<li>One<\/li>\n<\/ol>\n<h1>Networking<\/h1>\n<p>Never ever have I talked with somebody and not had an exciting conversation about the various &#8220;network models&#8221; and &#8220;name the protocol&#8221; \ud83d\ude42<\/p>\n<h2>Protocols<\/h2>\n<p>ICMP is a control protocol, meaning that it designed to not carry application data, but rather information about the status of the network itself. The best known example of ICMP in practice is the ping utility, that uses ICMP to probe remote hosts for responsiveness and overall round-trip time of the probe messages.<\/p>\n<p>Both Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) are transportation protocols, they are used to pass the actual data. The main difference between TCP and UDP is that TCP is a connection oriented protocol, it guarantees that all sent packets will reach the destination in the correct order.<\/p>\n<p>UDP, on the other hand, is a connection-less protocol. Communication is datagram oriented, so the integrity is guaranteed only on the single datagram. Datagrams reach destination and can arrive out of order or don&#8217;t arrive at all. It&#8217;s generally used for real time communication, where a little percentage of packet loss rate is preferable to the overhead of a TCP connection.<\/p>\n<h2>Internet protocol suite<\/h2>\n<h3>Application layer<\/h3>\n<p>BGP DHCP DNS FTP HTTP HTTPS IMAP LDAP MGCP MQTT NNTP NTP POP ONC\/RPC RTP RTSP RIP SIP SMTP SNMP SSH Telnet TLS\/SSL XMPP more&#8230;<\/p>\n<h3>Transport layer<\/h3>\n<p>TCP UDP DCCP SCTP RSVP more&#8230;<\/p>\n<h3>Internet layer<\/h3>\n<p>IP IPv4 IPv6 ICMP ICMPv6 ECN IGMP IPsec more&#8230;<\/p>\n<h3>Link layer<\/h3>\n<p>ARP NDP OSPF Tunnels L2TP PPP MAC Ethernet Wi-Fi DSL ISDN FDDI<\/p>\n<h3>ICMP<\/h3>\n<p>Internet Control Message Protocol<\/p>\n<ol>\n<li>ping<\/li>\n<\/ol>\n<h3>UDP<\/h3>\n<p>User Datagram Protocol<\/p>\n<ol>\n<li>Domain Name System (DNS)<\/li>\n<li>Simple Network Management Protocol (SNMP)<\/li>\n<li>Routing Information Protocol (RIP)<\/li>\n<li>Dynamic Host Configuration Protocol (DHCP)<\/li>\n<\/ol>\n<h3>TCP<\/h3>\n<p>Transmission Control Protocol<\/p>\n<ol>\n<li>World Wide Web (WWW)<\/li>\n<li>email<\/li>\n<li>File Transfer Protocol<\/li>\n<li>Secure Shell<\/li>\n<li>peer-to-peer file sharing<\/li>\n<li>streaming media<\/li>\n<\/ol>\n<h2>Classless Inter Domain Routing<\/h2>\n<p>CIDR &#8211; Classless Inter Domain Routing <\/p>\n<p>Classless InterDomain Routing (CIDR) was invented to keep the Internet from running out of IP Addresses. The use of a CIDR notated address can easily represent classful addresses (Class A = \/8, Class B = \/16, and Class C = \/24).<\/p>\n<h2>Private Addresses<\/h2>\n<p>There exist &#8220;ranges&#8221; of IP addresses that are reserved and you should know them in case you&#8217;re debugging stuff and you see for instance <code>192.168.1.100<\/code> which can&#8217;t be a &#8220;service on the web&#8221;.<\/p>\n<div id=\"privateaddressestable-link-341\" class=\"wp-showhide sh-link privateaddressestable-link sh-hide\"><button type=\"button\" class=\"sh-toggle\" aria-expanded=\"false\" aria-controls=\"privateaddressestable-content-341\" data-sh-more=\"show private addresses table\" data-sh-less=\"hide private addresses table\">show private addresses table<\/button><\/div><div id=\"privateaddressestable-content-341\" class=\"wp-showhide sh-content privateaddressestable-content sh-hide\" hidden><\/p>\n<table>\n<caption>Address Ranges For Private Networks<\/caption>\n<tr>\n<th>RFC1918 name<\/th>\n<th>IP address range<\/th>\n<th>number of addresses<\/th>\n<th>largest CIDR block (subnet mask)<\/th>\n<th>host id size<\/th>\n<th>mask bits<\/th>\n<th>classful description<\/th>\n<\/tr>\n<tr>\n<td>24-bit block<\/td>\n<td>10.0.0.0 &#8211; 10.255.255.255<\/td>\n<td>16,777,216<\/td>\n<td>10.0.0.0\/8 (255.0.0.0)<\/td>\n<td>24 bits<\/td>\n<td>8 bits<\/td>\n<td>single class A network<\/td>\n<\/tr>\n<tr>\n<td>20-bit block<\/td>\n<td>172.16.0.0 &#8211; 172.31.255.255<\/td>\n<td>1,048,576<\/td>\n<td>172.16.0.0\/12 (255.240.0.0)<\/td>\n<td>20 bits<\/td>\n<td>12 bits<\/td>\n<td>16 contiguous class B networks<\/td>\n<\/tr>\n<tr>\n<td>16-bit block<\/td>\n<td>192.168.0.0 &#8211; 192.168.255.255<\/td>\n<td>65,536<\/td>\n<td>192.168.0.0\/16 (255.255.0.0)<\/td>\n<td>16 bits<\/td>\n<td>16 bits<\/td>\n<td>256 contiguous class C networks<\/td>\n<\/tr>\n<\/table>\n<p><\/div>\n<p>Should you be so inclined you can use <code>sipcalc<\/code> (will probably have to install) to generate the ranges of IPs above like:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsipcalc 10.0.0.0\/8\n\nsipcalc 172.16.0.0\/12\n\nsipcalc 192.168.0.0\/16\n<\/pre>\n<p>In April 2012, IANA allocated <code>100.64.0.0\/10<\/code> for use in dedicated carrier-grade NAT scenarios.<\/p>\n<p>Personally I think &#8220;localhost&#8221; (&#8220;home&#8221;) at <code>127.0.0.1<\/code> is private. Actually, any IPv4 address in <code>127.0.0.0\/8<\/code> is a loopback address.<\/p>\n<p>Additionally .0 (network space) and .255 (broadcast address) can&#8217;t be used. It&#8217;s slight more complicated and &#8220;<a href=\"https:\/\/en.wikipedia.org\/wiki\/IPv4#Addresses_ending_in_0_or_255\">addresses ending in 0 or 255<\/a>&#8221; goes into greater detail.<\/p>\n<p>And finally there is a largish set of addresses considered &#8220;<a href=\"https:\/\/en.wikipedia.org\/wiki\/IPv4#Special-use_addresses\">special-use addresses<\/a>&#8220;.<\/p>\n<h1>Linux<\/h1>\n<h2>Load<\/h2>\n<p>Never ever have I talked with somebody and not had an exciting conversation about &#8220;load average&#8221; \ud83d\ude42<\/p>\n<p>Put very simply if you &#8220;magically&#8221; had all available CPU[s] 100% running process[es] (one process per CPU) and nothing else was wanting\/needing those CPU[s] (unlikely but go with me here) then &#8220;<em>load would equal the number of CPU[s]<\/em>&#8220;.<\/p>\n<p>Let&#8217;s make this real easy and <em>forget the &#8220;average&#8221; part<\/em>. It&#8217;s over 1, 5 and 15 minutes and uses a gnarly formula &#8220;exponentially damped\/weighted moving average&#8221;<span id='easy-footnote-1-341' class='easy-footnote-margin-adjust'><\/span><span class='easy-footnote'><a href='https:\/\/www.hoopchuk.org\/wordpress\/code-stuff\/#easy-footnote-bottom-1-341' title='&lt;a href=&quot;https:\/\/en.wikipedia.org\/wiki\/Moving_average#Exponential_moving_average&quot;&gt;https:\/\/en.wikipedia.org\/wiki\/Moving_average#Exponential_moving_average&lt;\/a&gt;'><sup>1<\/sup><\/a><\/span> and it doesn&#8217;t matter for the explanation.<\/p>\n<p>Simply put &#8220;load&#8221; is &#8220;number of processes using or wanting to use the CPU[s]&#8221;. More specifically here are the possible &#8220;CPU states&#8221; (from <code>man top<\/code> search on <code>Process Status<\/code>) and the first three highlighted count towards &#8220;load&#8221;:<\/p>\n<ol>\n<li><span style=\"background-color:yellow;\">D = uninterruptible sleep<\/span><\/li>\n<li><span style=\"background-color:yellow;\">I = idle<\/span><\/li>\n<li><span style=\"background-color:yellow;\">R = running<\/span><\/li>\n<li>S = sleeping<\/li>\n<li>T = stopped by job control signal<\/li>\n<li>t = stopped by debugger during trace<\/li>\n<li>Z = zombie<\/li>\n<\/ol>\n<p>Here&#8217;s a link<span id='easy-footnote-2-341' class='easy-footnote-margin-adjust'><\/span><span class='easy-footnote'><a href='https:\/\/www.hoopchuk.org\/wordpress\/code-stuff\/#easy-footnote-bottom-2-341' title='&lt;a href=&quot;http:\/\/www.brendangregg.com\/blog\/2017-08-08\/linux-load-averages.html&quot;&gt;http:\/\/www.brendangregg.com\/blog\/2017-08-08\/linux-load-averages.html&lt;\/a&gt;'><sup>2<\/sup><\/a><\/span> that shows the addition of &#8220;the origin of uninterruptible&#8221;.<\/p>\n<p>The OS computes it and iterally stores it in file <code>\/proc\/loadavg<\/code>. <code>man 5 proc<\/code> and search on (go figure) <code>\/proc\/loadavg<\/code> for details.<\/p>\n<p>By the way an easy way to get the number of CPUs is <code>nproc<\/code>. There are a bunch of other ways that a web search on <code>linux number of cpu<\/code> will be helpful.<\/p>\n<h2>Servers In Virtualized Environments<\/h2>\n<h2>Fundamentals Of Scripting Languages<\/h2>\n<h2>Boot Process<\/h2>\n<p>I definitely would not use this as the &#8220;end all of knowledge&#8221; for this. I use this to review stuff before I interview.<\/p>\n<p>By the way this is found at <code>man bootup 7<\/code> but it&#8217;s not the easiest to decipher in my opinion.<\/p>\n<p>Here&#8217;s the basics<span id='easy-footnote-3-341' class='easy-footnote-margin-adjust'><\/span><span class='easy-footnote'><a href='https:\/\/www.hoopchuk.org\/wordpress\/code-stuff\/#easy-footnote-bottom-3-341' title='&lt;a href=&quot;https:\/\/opensource.com\/article\/17\/2\/linux-boot-and-startup&quot;&gt;https:\/\/opensource.com\/article\/17\/2\/linux-boot-and-startup&lt;\/a&gt;'><sup>3<\/sup><\/a><\/span>:<\/p>\n<ol>\n<li>BIOS POST (Basic I\/O System &#8211; Power On Self Test)<\/li>\n<li>MBR (Master Boot Record) &#8211; 512 byte<\/li>\n<li>GRUB2 &#8211; loads the selected kernel into memory and turns control of the computer over to the kernel<\/li>\n<li>kernel<\/li>\n<li>systemd &#8211; responsible for bringing the Linux host up to a state in which productive work can be done<\/li>\n<li>runlevel<\/li>\n<\/ol>\n<p>And more on runlevels &#8230; I would seriously do more research on this topic but:<br \/>\n<div id=\"runlevelstable-link-341\" class=\"wp-showhide sh-link runlevelstable-link sh-hide\"><button type=\"button\" class=\"sh-toggle\" aria-expanded=\"false\" aria-controls=\"runlevelstable-content-341\" data-sh-more=\"show long runlevels table\" data-sh-less=\"hide long runlevels table\">show long runlevels table<\/button><\/div><div id=\"runlevelstable-content-341\" class=\"wp-showhide sh-content runlevelstable-content sh-hide\" hidden><\/p>\n<table>\n<caption>Comparison of SysV Runlevels with systemd Targets<\/caption>\n<tr>\n<th>Runlevel<\/th>\n<th>Target Units<\/th>\n<th>Description<\/th>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>runlevel0.target, poweroff.target<\/td>\n<td>Shut down and power off the system.<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>runlevel1.target, rescue.target<\/td>\n<td>Set up a rescue shell.<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>runlevel2.target, multi-user.target<\/td>\n<td>Set up a non-graphical multi-user system.<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>runlevel3.target, multi-user.target<\/td>\n<td>Set up a non-graphical multi-user system.<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>runlevel4.target, multi-user.target<\/td>\n<td>Set up a non-graphical multi-user system.<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>runlevel5.target, graphical.target<\/td>\n<td>Set up a graphical multi-user system.<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>runlevel6.target, reboot.target<\/td>\n<td>Shut down and reboot the system.<\/td>\n<\/tr>\n<\/table>\n<p>[text]<br \/>\nTraditional runlevel      New target name     Symbolically linked to&#8230;<br \/>\nRunlevel 0           |    runlevel0.target -> poweroff.target<br \/>\nRunlevel 1           |    runlevel1.target -> rescue.target<br \/>\nRunlevel 2           |    runlevel2.target -> multi-user.target<br \/>\nRunlevel 3           |    runlevel3.target -> multi-user.target<br \/>\nRunlevel 4           |    runlevel4.target -> multi-user.target<br \/>\nRunlevel 5           |    runlevel5.target -> graphical.target<br \/>\nRunlevel 6           |    runlevel6.target -> reboot.target<br \/>\n[\/text]<\/p>\n<table>\n<tr>\n<th>SystemV Runlevel<\/th>\n<th>systemd target<\/th>\n<th>systemd target aliases<\/th>\n<th>Description<\/th>\n<\/tr>\n<tr>\n<td><\/td>\n<td>halt.target<\/td>\n<td><\/td>\n<td>Halts the system without powering it down.<\/td>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>poweroff.target<\/td>\n<td>runlevel0.target<\/td>\n<td>Halts the system and turns the power off.<\/td>\n<\/tr>\n<tr>\n<td>S<\/td>\n<td>emergency.target<\/td>\n<td><\/td>\n<td>Single user mode. No services are running; filesystems are not mounted. This is the most basic level of operation with only an emergency shell running on the main console for the user to interact with the system.<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>rescue.target<\/td>\n<td>runlevel1.target<\/td>\n<td>A base system including mounting the filesystems with only the most basic services running and a rescue shell on the main console.<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td><\/td>\n<td>runlevel2.target<\/td>\n<td>Multiuser, without NFS but all other non-GUI services running.<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>multi-user.target<\/td>\n<td>runlevel3.target<\/td>\n<td>All services running but command line interface (CLI) only.<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td><\/td>\n<td>runlevel4.target<\/td>\n<td>Unused.<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>graphical.target<\/td>\n<td>runlevel5.target<\/td>\n<td>multi-user with a GUI.<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td>reboot.target<\/td>\n<td>runlevel6.target<\/td>\n<td>Reboot<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>default.target<\/td>\n<td><\/td>\n<td>This target is always aliased with a symbolic link to either multi-user.target or graphical.target. systemd always uses the default.target to start the system. The default.target should never be aliased to halt.target, poweroff.target, or reboot.target.<\/td>\n<\/tr>\n<\/table>\n<p><\/div><\/p>\n<p>Some quick commands worth having fresh:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n## display the default target unit\nsystemctl get-default\n\n## list all currently loaded target units\nsystemctl list-units --type target\n<\/pre>\n<h3>Problem Diagnosis<\/h3>\n<h2>Installing Configuring Maintaining Services<\/h2>\n<p>I think I need to restructure this section but for now &#8230;<\/p>\n<p>There are many services that can do Layer 4 load balancing: Nginx\/Nginx Plus, HAProxy, and the one we\u2019ll look at today, IPVS.<\/p>\n<h3>Apache<\/h3>\n<h3>MySQL<\/h3>\n<h3>Nginx<\/h3>\n<h3>SNMP<\/h3>\n<h2>Network Tools<\/h2>\n<h3>Iptables<\/h3>\n<h3>IPVS<\/h3>\n<h3>HAProxy<\/h3>\n<h2>Build And Monitor Services On Production Servers<\/h2>\n<h1>Print Friendly<\/h1>\n<div class=\"printfriendly pf-button  pf-alignleft\">\n                    <a href=\"https:\/\/www.hoopchuk.org\/wordpress\/code-stuff\/?pfstyle=wp\" rel=\"nofollow\" onclick=\"\" title=\"Printer Friendly, PDF & Email\">\n                    <img data-recalc-dims=\"1\" decoding=\"async\" class=\"pf-button-img\" src=\"https:\/\/i0.wp.com\/cdn.printfriendly.com\/buttons\/printfriendly-button.png?w=840&#038;ssl=1\" alt=\"Print Friendly, PDF & Email\" style=\"width: 112px;height: 24px;\"  \/>\n                    <\/a>\n                <\/div>\n<p><!-- [sc name=\"htmlbr\"][sc name=\"htmlbr\"] --><\/p>\n<h1>Subversion<\/h1>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$Id: code-stuff.txt 4075 2019-04-02 13:06:52Z hoopchuk $\n<\/pre>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>Summary Stuff I getted asked about on interviews. It&#8217;s a compilation of things I learned across talking to many folks about paying me to do what I find interesting and am passionate about. I can never directly thank these people stumping me and prompting me to keep on learning and growing and getting better &#8230; &hellip; <a href=\"https:\/\/www.hoopchuk.org\/wordpress\/code-stuff\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Code Stuff&#8221;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"nf_dc_page":"","wprm-recipe-roundup-name":"","wprm-recipe-roundup-description":"","nfd_onboarding_generated":"","footnotes":""},"class_list":["post-341","page","type-page","status-publish","hentry"],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/PaQUmf-5v","_links":{"self":[{"href":"https:\/\/www.hoopchuk.org\/wordpress\/wp-json\/wp\/v2\/pages\/341","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hoopchuk.org\/wordpress\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.hoopchuk.org\/wordpress\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.hoopchuk.org\/wordpress\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hoopchuk.org\/wordpress\/wp-json\/wp\/v2\/comments?post=341"}],"version-history":[{"count":5,"href":"https:\/\/www.hoopchuk.org\/wordpress\/wp-json\/wp\/v2\/pages\/341\/revisions"}],"predecessor-version":[{"id":402,"href":"https:\/\/www.hoopchuk.org\/wordpress\/wp-json\/wp\/v2\/pages\/341\/revisions\/402"}],"wp:attachment":[{"href":"https:\/\/www.hoopchuk.org\/wordpress\/wp-json\/wp\/v2\/media?parent=341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}