<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Adam La Rosa</title>
    <description>The latest articles on DEV Community by Adam La Rosa (@adamlarosa).</description>
    <link>https://dev.to/adamlarosa</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F256561%2F23a9f5a3-f043-4001-a02a-d401e27a5d0d.jpeg</url>
      <title>DEV Community: Adam La Rosa</title>
      <link>https://dev.to/adamlarosa</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adamlarosa"/>
    <language>en</language>
    <item>
      <title>Parallax Scrolling</title>
      <dc:creator>Adam La Rosa</dc:creator>
      <pubDate>Sun, 12 Jul 2020 06:30:40 +0000</pubDate>
      <link>https://dev.to/adamlarosa/parallax-scrolling-m28</link>
      <guid>https://dev.to/adamlarosa/parallax-scrolling-m28</guid>
      <description>&lt;p&gt;Surfing around the web I've come across sites where when scrolling down the background seems to scroll at a different speed than the rest of the site.  This is a technique called "Parallax Scrolling".  Which can easily be done with only CSS.  First what we can do is outline our HTML with a few layers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;body&amp;gt;
    &amp;lt;div class="parallax"&amp;gt;

        &amp;lt;div class="parallax__layer parallax__layer--back"&amp;gt;
          &amp;lt;div class="title"&amp;gt;This is the background&amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="parallax__layer parallax__layer--base"&amp;gt;
          &amp;lt;div class="title"&amp;gt;This is the foreground&amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;

    &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here we set aside a couple of containers for our text, each with a class "title".  Both of them are nested inside another class, "parallax__layer", then individualized by which layer they are in, in this case base &amp;amp; back.  All of which is nested inside a container that is for all of our parallax scrolling content. Now for a bit of CSS!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.parallax {
    height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-perspective: 1px;
    perspective: 1px;
}

.parallax__layer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This sets our container &amp;amp; the base for the layers underneath by setting their positions to "absolute".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.parallax__layer--base {

    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

.parallax__layer--back {
    -webkit-transform: translateZ(-1px);
    transform: translateZ(-1px);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here is where we have the distinction between our layers.  By setting our transform property to different values on the Z axis we can differentiate between the two layers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;* {
    margin:0;
    padding:0;
}

body {
    font: 100% / 1.5 Arial;
}
.parallax {
    font-size: 200%;
}
.parallax__layer {
    padding: 100vh 0;
}

.title {
    position: absolute;
    left: 50%;
    top: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With this last bit of formatting we can set the format of our layers and voila!  Smooth scrolling at different speeds for our site!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>CSS Clock</title>
      <dc:creator>Adam La Rosa</dc:creator>
      <pubDate>Sun, 05 Jul 2020 05:11:47 +0000</pubDate>
      <link>https://dev.to/adamlarosa/css-clock-m80</link>
      <guid>https://dev.to/adamlarosa/css-clock-m80</guid>
      <description>&lt;p&gt;I had absolutely no idea how cool CSS could be until I looked around and found a few things to play with.  Here we take a look at faking div's to look like a clock face &amp;amp; making the hands turn.&lt;/p&gt;

&lt;p&gt;First a bit of html to create containers to style with.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;html&amp;gt;

&amp;lt;head&amp;gt;
    &amp;lt;link rel="stylesheet" type="text/css" href="index.css"&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;div id="clock"&amp;gt;

        &amp;lt;div class="hours-container"&amp;gt;
            &amp;lt;div class="hours"&amp;gt;&amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="minutes-container"&amp;gt;
            &amp;lt;div class="minutes"&amp;gt;&amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;div class="seconds-container"&amp;gt;
            &amp;lt;div class="seconds"&amp;gt;&amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;

    &amp;lt;/div&amp;gt;
    &amp;lt;script type="text/javascript" src="index.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;First, we'll create a circle to act as our clock's "face".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#clock{
    border: solid black 10px;
    border-radius: 50%;
    height: 20em;
    width: 20em;
    position: relative;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Next we can stack each container for the clock's "hands" on each other above the clock face.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.minutes-container, .hours-container, .seconds-container {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With each hand, we can change the styling gently to make each div a slightly different shape, mimicking the clock's hands.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.hours {
    background: #000;
    height: 20%;
    left: 48.75%;
    position: absolute;
    top: 30%;
    transform-origin: 50% 100%;
    width: 2.5%;
  }

  .minutes {
    background: #000;
    height: 40%;
    left: 49%;
    position: absolute;
    top: 10%;
    transform-origin: 50% 100%;
    width: 2%;
  }

  .seconds {
    background: #000;
    height: 45%;
    left: 49.5%;
    position: absolute;
    top: 14%;
    transform-origin: 50% 80%;
    width: 1%;
    z-index: 8;
  }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now that we have our hands, we can use one keyframe to move the hands around 360 degrees.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  @keyframes rotate {
    100% {
      transform: rotateZ(360deg);
    }
  }

  .hours-container {
    animation: rotate 43200s infinite linear;
  }
  .minutes-container {
    animation: rotate 3600s infinite linear;
  }
  .seconds-container {
    animation: rotate 60s infinite linear;
  }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;...and presto!  Our clock is moving with the hands adjusting for one hour as they move around the clock.  With a bit of javascript we can get the hands to point at the correct time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function clockStart() {

    var date = new Date;
    var seconds = date.getSeconds();
    var minutes = date.getMinutes();
    var hours = date.getHours();

    var hands = [
      {
        hand: 'hours',
        angle: (hours * 30) + (minutes / 2)
      },
      {
        hand: 'minutes',
        angle: (minutes * 6)
      },
      {
        hand: 'seconds',
        angle: (seconds * 6)
      }
    ];

    for (var j = 0; j &amp;lt; hands.length; j++) {
      var elements = document.querySelectorAll('.' + hands[j].hand);
      for (var k = 0; k &amp;lt; elements.length; k++) {
          elements[k].style.webkitTransform = 'rotateZ('+ hands[j].angle +'deg)';
          elements[k].style.transform = 'rotateZ('+ hands[j].angle +'deg)';
          if (hands[j].hand === 'minutes') { elements[k].parentNode.setAttribute('data-second-angle', hands[j + 1].angle);}
      }
    }
  }
  clockStart();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Iterating through the hands we can set their angle dynamically with the #style method for each element.&lt;/p&gt;

&lt;p&gt;A far cry from just fonts and borders, CSS is indeed a powerful tool for front end development. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Infinite Scroll</title>
      <dc:creator>Adam La Rosa</dc:creator>
      <pubDate>Sun, 28 Jun 2020 04:55:05 +0000</pubDate>
      <link>https://dev.to/adamlarosa/infinite-scroll-258b</link>
      <guid>https://dev.to/adamlarosa/infinite-scroll-258b</guid>
      <description>&lt;p&gt;Concerning infinite scroll in JavaScript I happened to come across this solution.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var listElm = document.querySelector('#infinite-list');

// Add 20 items.
var nextItem = 1;
var loadMore = function() {
  for (var i = 0; i &amp;lt; 20; i++) {
    var item = document.createElement('li');
    item.innerText = 'Item ' + nextItem++;
    listElm.appendChild(item);
  }
}

// Detect when scrolled to bottom.
listElm.addEventListener('scroll', function() {
  if (listElm.scrollTop + listElm.clientHeight &amp;gt;= listElm.scrollHeight) {
    loadMore();
  }
});

// Initially load some items.
loadMore();
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here we have three javascript methods that are ran against our main element:  scrollTop, clientHeight, and scrollHeight.&lt;/p&gt;

&lt;p&gt;scrollTop, when applied to an HTML element, is a measurement of the distance from the top of the element to its top most visible content.&lt;/p&gt;

&lt;p&gt;clientHeight, on the other hand, is the inner height of the element in pixels.&lt;/p&gt;

&lt;p&gt;scrollHeight then is the height of an element's content, including that which is not visible on the screen.&lt;/p&gt;

&lt;p&gt;In our solution we identify the element in question, labeled by the "infinite-list" id.  Next we define our function which will add new items to the unordered list, declaring which item we are at then defining a function which will add more items to the list.&lt;/p&gt;

&lt;p&gt;Finally, we add an event listener to our initial element, listElm.  This takes the size of our initial element and checks to see if after scrolling the inner height is greater than or equal to the total height of the element.  &lt;/p&gt;

&lt;p&gt;If it is, run our function again to add more elements!  Forever!!  :)&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Linked Lists</title>
      <dc:creator>Adam La Rosa</dc:creator>
      <pubDate>Sat, 20 Jun 2020 23:50:49 +0000</pubDate>
      <link>https://dev.to/adamlarosa/linked-lists-10b0</link>
      <guid>https://dev.to/adamlarosa/linked-lists-10b0</guid>
      <description>&lt;p&gt;When it comes to data types the array &amp;amp; linked list are birds of a feather.  Both have their strengths &amp;amp; weaknesses.  With an array, it's quick to access the required data with the help of an index.  By contrast to request data from a linked list you have to traverse the entire data structure until the related data is found.&lt;/p&gt;

&lt;p&gt;That being said, the linked list is faster when it comes to inserting a value in the middle of the data structure.  All one would have to do is change the "next" value of the linked list's previous node.  To do the same with an array all values after the insertion would have to be shifted over one index.&lt;/p&gt;

&lt;p&gt;Here is a ruby implementation that shows how a linked list can be implemented with two classes.  First the node:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Node
    attr_accessor :next
    attr_reader   :value

    def initialize(value)
        @value = value
        @next  = nil
    end

    def to_s
        "Node with value: #{@value}"
    end
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We create two variables, "value" and "next" with value as read-only, &amp;amp; "next" with read / write access as to insert a value into the list, one would only have to change the value of "next".&lt;/p&gt;

&lt;p&gt;Now for the list itself:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class LinkedList
    def initialize
        @head = nil
    end

    def append(value)
        if @head
        find_tail.next = Node.new(value)
        else
        @head = Node.new(value)
        end
    end

    def find_tail
        node = @head
        return node if !node.next
        return node if !node.next while (node = node.next)
    end

    def append_after(target, value)
        node = find(target)
        return unless node
        old_next = node.next
        node.next = Node.new(value)
        node.next.next = old_next
    end

    def find(value)
        node = @head
        return node if node.value == value
        return false if !node.next
        while (node = node.next)
        return node if node.value == value
        end
    end

    def delete(value)
        if @head.value == value
        @head = @head.next
        return
        end
        node = find_before(value)
        node.next = node.next.next
    end

    def find_before(value)
        node = @head
        return false if !node.next
        return node  if node.next.value == value
        while (node = node.next)
        return node if node.next &amp;amp;&amp;amp; node.next.value == value
        end
    end

    def print
        node = @head
        puts node
        while (node = node.next)
        puts node
        end
    end
end
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here we find a number of helper methods which allow the linked list to be updated or maintained.  #append iterates through the list, having #find_tail use a while statement to locate the node with a value equal to "null".  &lt;/p&gt;

&lt;p&gt;The method #append_after does the same iteration looking for a node with the help of #find.  #find locates a value first by checking to see if it is the first node in the list, then check to see if there's no following nodes returning false if so, if not then using another while statement for iteration.&lt;/p&gt;

&lt;p&gt;The #delete method doesn't necessarily "delete" the node, but changes the values of "node.next" in the previous and following nodes.&lt;/p&gt;

&lt;p&gt;Searching with #find_before does the same iterations as above, this time only checking to see if the value asked for is equal to node.next.&lt;/p&gt;

&lt;p&gt;As you can see a good linked list implementation can be done with only a way to represent the node, &amp;amp; a way to organize, search, &amp;amp; append to said list.  Creating and maintaining a hash table as the list is created &amp;amp; updated is one way to solve for the search inadequacies.&lt;/p&gt;

&lt;p&gt;Happy storing!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Blocking the Lamerz</title>
      <dc:creator>Adam La Rosa</dc:creator>
      <pubDate>Fri, 12 Jun 2020 17:42:36 +0000</pubDate>
      <link>https://dev.to/adamlarosa/blocking-the-lamerz-29df</link>
      <guid>https://dev.to/adamlarosa/blocking-the-lamerz-29df</guid>
      <description>&lt;p&gt;After setting up a test server and getting it online I noticed some unwanted guests trying to gain access to the root account.  From the logfile /var/log/authlog:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Jun 12 10:15:27 sshd[92881]: Disconnected from authenticating user root 188.226.202.13 port 36477 [preauth]
Jun 12 10:16:37 sshd[30913]: Failed password for root from 121.66.224.90 port 45994 ssh2
Jun 12 10:16:38 sshd[30913]: Received disconnect from 121.66.224.90 port 45994:11: Bye Bye [preauth]
Jun 12 10:16:38 sshd[30913]: Disconnected from authenticating user root 121.66.224.90 port 45994 [preauth]
Jun 12 10:18:16 sshd[38068]: Invalid user qqding from 188.35.187.50 port 58726
Jun 12 10:18:16 sshd[38068]: Failed password for invalid user qqding from 188.35.187.50 port 58726 ssh2
Jun 12 10:18:16 sshd[38068]: Received disconnect from 188.35.187.50 port 58726:11: Bye Bye [preauth]
Jun 12 10:18:16 sshd[38068]: Disconnected from invalid user qqding 188.35.187.50 port 58726 [preauth]
Jun 12 10:18:27 sshd[48451]: Failed password for root from 145.239.72.142 port 57066 ssh2
Jun 12 10:18:28 sshd[48451]: Received disconnect from 145.239.72.142 port 57066:11: Bye Bye [preauth]
Jun 12 10:18:28 sshd[48451]: Disconnected from authenticating user root 145.239.72.142 port 57066 [preauth]
Jun 12 10:18:34 sshd[12756]: Failed password for root from 181.30.99.114 port 55752 ssh2
Jun 12 10:18:35 sshd[12756]: Received disconnect from 181.30.99.114 port 55752:11: Bye Bye [preauth]
Jun 12 10:18:35 sshd[12756]: Disconnected from authenticating user root 181.30.99.114 port 55752 [preauth]
Jun 12 10:18:56 sshd[76176]: Invalid user admin from 188.226.202.13 port 65405
Jun 12 10:18:56 sshd[76176]: Failed password for invalid user admin from 188.226.202.13 port 65405 ssh2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;...etc, etc.  As we can see not only is a bruteforce attempt being made against the root account, but the same is being tried against other usernames.  While strong passwords are one such defense against these attacks, I'd like to make sure the IP can never log in again.  Luckily the distro I'm using comes with a tool installed and enabled by default called the Packet Filter.  From the man page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Packet filtering takes place in the kernel.  A pseudo-device, /dev/pf,
allows userland processes to control the behavior of the packet filter
through an ioctl(2) interface.  There are commands to enable and disable
the filter, load rulesets, add and remove individual rules or state table
entries, and retrieve statistics.  The most commonly used functions are
covered by pfctl(8).
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The Packet Filter (or "PF") has its configuration file located at /etc/pf.conf.  By adding a couple of lines we can create a new database table to PF &amp;amp; give it a rule to block any IP addresses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;table &amp;lt;lamerz&amp;gt; persist file "/etc/lamerz"
block in from &amp;lt;lamerz&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here we've created the table named "lamerz" from a file in our /etc directory then told PF to block all inbound traffic from addresses in that file.  Next we can quickly create the file...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch /etc/lamerz
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now with our file created and ruleset established all that's left is to add addresses!  This can be done with the "pfctl" tool.  From pfctl's man:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The pfctl utility communicates with the packet filter device using the
ioctl interface described in pf(4).  It allows ruleset and parameter
configuration, and retrieval of status information from the packet
filter.  Packet filtering restricts the types of packets that pass
through network interfaces entering or leaving the host based on filter
rules as described in pf.conf(5).  The packet filter can also replace
addresses and ports of packets.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The command pfctl would use to add a ip address to the database table would be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pfctl -t lamerz -T add 145.239.72.142
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Our "t" flag is used to specify the table to use, then the capital "T" flag specifies the command.  In this case adding an entry.  Although this does NOT add the IP address to the file in our /etc directory.  A different command used with the "T" flag, plus some redirection would accomplish this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pfctl -t lamerz -T show &amp;gt;&amp;gt; /etc/lamerz
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now if our machine reboots or if PF is restarted it will remember the "lamerz" you're trying to keep out!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Playing With Files</title>
      <dc:creator>Adam La Rosa</dc:creator>
      <pubDate>Sun, 07 Jun 2020 03:27:33 +0000</pubDate>
      <link>https://dev.to/adamlarosa/playing-with-files-23ln</link>
      <guid>https://dev.to/adamlarosa/playing-with-files-23ln</guid>
      <description>&lt;p&gt;Everyone has to deal with file management at some point.  But archives?  Compression?  Splits &amp;amp; concatenation?  This is where the fun begins!&lt;/p&gt;

&lt;p&gt;Got a bunch of files?  Want to put them together in one file for transfer or some such?  Tar to the rescue!  From the man page...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The tar command creates, adds files to, or extracts files from an archive
file in "tar" format.  A tar archive is often stored on a magnetic tape,
but can be stored equally well on a floppy, CD-ROM, or in a regular disk
file.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Tar got its name from the days where data was stored on mag tape.  A command such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tar -cvf name.of.file.to.create.tar /home/user/*
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;would (c) create a new archive file, (v) provide "verbose" output to view progress, and (f) output to a file.  The following parameters are the name of the file you're creating and the target to make the archive from.&lt;/p&gt;

&lt;p&gt;While creating archives is great and all, sometimes the amount of data is too big for comfort and compression is needed.  Luckily tar has an option to use gzip, a common compression algorithm.  From the gzip man...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The gzip utility reduces the size of the named files using adaptive
Lempel-Ziv coding, in deflate mode.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;There are different compression methods to choose from but if you're not particular adding a "z" flag to the above tar command will include compression using gzip.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tar -zcvf name.of.file.to.create.tar.gz /home/user/*
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now say you've got your archive, all zipped up, and it's still too big.  It might make sense to split that file into more reasonable sized chunks.  Well, there's a "split" command for that!&lt;/p&gt;

&lt;p&gt;Split it fairly straight forward.  There's one particular flag, -b, which specifies how big you'd like each portion to be.  For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;split -b 100m superhugefile.tar.gz "prefix-of-split-"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;What this does is tell split you'd like to take "superhugefile.tar.gz", split it into 100 megabyte files, and begin each filename with "prefix-of-split-".  What this will then do is create a number of files named as such:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;prefix-of-split-aa
prefix-of-split-ab
prefix-of-split-ac
prefix-of-split-ad
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;...etc.&lt;/p&gt;

&lt;p&gt;But what now?  You've got all these files &amp;amp; it's time to put them back together.  Cat to the rescue!&lt;/p&gt;

&lt;p&gt;For as long as I can remember the "cat" command was my way of viewing the contents of a file.  By itself a command such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat readme.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;will display the contents of readme.txt to the screen.  Little did I know that with the help of a output redirection operator cat can join the files together!  From the cat man page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The cat utility reads files sequentially, writing them to the standard
output.  The file operands are processed in command-line order.  If file
is a single dash (`-') or absent, cat reads from the standard input.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So a simple command like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat prefix-of-split-* &amp;gt; superhugefile.tar.gz
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;will reassemble your file!&lt;/p&gt;

&lt;p&gt;Command line tools like these are why I've come to love unix &amp;amp; unix-like operating systems.  If it's the macOS, Linux, or a BSD, having these familiar tools available provides a sense of comfort.  &lt;/p&gt;

</description>
    </item>
    <item>
      <title>OpenBSD and httpd</title>
      <dc:creator>Adam La Rosa</dc:creator>
      <pubDate>Sat, 30 May 2020 23:48:44 +0000</pubDate>
      <link>https://dev.to/adamlarosa/openbsd-and-httpd-1f55</link>
      <guid>https://dev.to/adamlarosa/openbsd-and-httpd-1f55</guid>
      <description>&lt;p&gt;One of the major reasons I like having a server available is being able to host my own content.  Keeping a few boxes in the closet to store all the data I hoard wouldn't go very far if there was no access.  For a web solution I've gone with OpenBSD (of course) and it's pre-installed web server, httpd.&lt;/p&gt;

&lt;p&gt;OpenBSD's security comes not only through tireless audits, but by not having any network facing software turned on by default.  Setting up httpd (like most things on OpenBSD) really is no more difficult than carefully editing a few text files.&lt;/p&gt;

&lt;p&gt;For this I'm using OpenBSD 6.7 on a Pentium 4.&lt;/p&gt;

&lt;p&gt;First one has to create a config file for httpd in the /etc directory called httpd.conf.  An example is located in /etc/examples as such:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# $OpenBSD: httpd.conf,v 1.20 2018/06/13 15:08:24 reyk Exp $

server "example.com" {
    listen on * port 80
    location "/.well-known/acme-challenge/*" {
        root "/acme"
        request strip 2
    }
    location * {
        block return 302 "https://$HTTP_HOST$REQUEST_URI"
    }
}

server "example.com" {
    listen on * tls port 443
    tls {
        certificate "/etc/ssl/example.com.fullchain.pem"
        key "/etc/ssl/private/example.com.key"
    }
    location "/pub/*" {
        directory auto index
    }
    location "/.well-known/acme-challenge/*" {
        root "/acme"
        request strip 2
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;From this I stripped it down to only what I needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# $OpenBSD: httpd.conf,v 1.20 2018/06/13 15:08:24 reyk Exp $
ext_ip = "egress"

server "&amp;lt;name of my domain&amp;gt;" {
    listen on $ext_ip port 80
    root "/htdocs"
}

types {
    include "/usr/share/misc/mime.types"
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;By setting the IP address to a variable called "ext_ip" and assigning it a value of "egress" the web server only allows incoming connectivity to the primary IP address of the network interface.  By default httpd keeps its files in /var/&lt;a href="http://www"&gt;www&lt;/a&gt;.  Setting our root directory in httpd.conf to "/htdocs" makes anyone going to our website see the files in /var/www/htdocs.  With our server configured all that was left was to allow it to know common file types, stored in /usr/share/misc/mime.types.  &lt;/p&gt;

&lt;p&gt;Next we have to enable httpd.  In the past this has been done by directly editing configuration files in /etc, in this case /etc/rc.conf.local.  Now this is done with the rcctl utility.  From the man page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     The rcctl utility can enable or disable a base system service or a base
     system or package daemon in rc.conf.local(8) or display its configuration
     and status.  For a daemon, it can also change the command line arguments,
     the user to run as, the rc.d(8) action timeout or call its rc.d(8) daemon
     control script.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Enabling httpd is then as easy as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rcctl enable httpd
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This should add the line "httpd_flags=" to /etc/rc.conf.local.  Then to start httpd we use rcctl again.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rcctl start httpd
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;All that's left now is to create an index.html file in /var/www/htdocs and point a web browser to our new web server!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Refurbished Wifi Access Points</title>
      <dc:creator>Adam La Rosa</dc:creator>
      <pubDate>Sun, 24 May 2020 06:15:59 +0000</pubDate>
      <link>https://dev.to/adamlarosa/refurbished-wifi-access-points-33nb</link>
      <guid>https://dev.to/adamlarosa/refurbished-wifi-access-points-33nb</guid>
      <description>&lt;p&gt;Loving a good project I once had the idea of taking a spare wifi card and using it as a wifi access point.  I plugged it into a box running OpenBSD (of course) and found the following solution.&lt;/p&gt;

&lt;p&gt;First enable IP forwarding by uncommenting the line in /etc/sysctl.conf&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;net.inet.ip.forwarding=1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then enable PF in /etc/pf.conf to use Network Address Translation.  Adding the following lines.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ext_if=em0 #ethernet
int_if=ath0 #wireless
pass out on $ext_if from !($ext_if) to any nat-to ($ext_if)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Update /etc/dhcpd.conf to assign IP addresses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;option domain-name-servers 192.168.1.1, 8.8.8.8;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Enable DNS &amp;amp; DHCP in /etc/rc.conf.local, also adding the following additional lines.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;named_flags=""  # this enables DNS
dhcpd_flags="ath0"  # this enables DHCP
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Finally the wifi adapter needs to be told how to treat incoming logins.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;inet 192.168.1.1 255.255.255.0 NONE media autoselect mediaopt hostap
nwid NETWORK wpakey PASSWORD chan 11
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;...and with a quick reboot we now have our OpenBSD server acting as a wifi access point!  With all the tools such as tcpdump or pfctl available to manipulate data from the device.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Adventures in Readability</title>
      <dc:creator>Adam La Rosa</dc:creator>
      <pubDate>Sun, 17 May 2020 05:45:39 +0000</pubDate>
      <link>https://dev.to/adamlarosa/adventures-in-readability-4k17</link>
      <guid>https://dev.to/adamlarosa/adventures-in-readability-4k17</guid>
      <description>&lt;p&gt;Take for example, this block of code that takes info from a COVID api &amp;amp; organizes it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;processData = (results) =&amp;gt; {
        let states = {};
        for (const result in results){
            const info = results[result];
            const state = info.Province
            const city = info.City
            if (Object.keys(states).includes(state)) {
                if (Object.keys(states[state]).includes(city)) {
                    states[state][city].push({
                        date: info.Date,
                        cases: info.Cases
                    })
                } else {
                    states[state][city] = []
                    states[state][city].push({
                        date: info.Date,
                        cases: info.Cases
                    })
                }
            } else {
                states[state] = {}
                states[state][city] = []
                states[state][city].push({
                    date: info.Date,
                    cases: info.Cases
                })
            }

        }
        return states;
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The results are given to this function and sorted into a new object, organized by State and City.  During iteration we check to see if the new object being created already has certain keys.  Adding to those keys if they exist and creating them if not.  But how does this look?  Readability-wise I'd say it leaves something to be desired.  By separating some concerns we can make this a little easier to look at.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    provinceInStates = (entry) =&amp;gt; {
        const { states } = this.state
        return Object.keys(states).includes(entry.Province)
    }

    countyInState = (entry) =&amp;gt; {
        const { states } = this.state
        return Object.keys(states[entry["Province"]]).includes(entry.City)
    }
    addEntryToState = (entry) =&amp;gt; {
        const { Province, City } = entry;
        let newStates = this.state.states
        newStates[Province][City].push(entry) 
    }
    createEntryInState = (entry) =&amp;gt; {
        const { Province, City } = entry
        let newStates = this.state.states
        newStates[Province] = {}
        newStates[Province][City] = []
        newStates[Province][City].push(entry);
        this.setState({ states: newStates })
    }
    createCountyInState = (entry) =&amp;gt; {
        const { Province, City } = entry;
        let newStates = this.state.states;
        newStates[Province][City] = []
        newStates[Province][City].push(entry)
        this.setState({ states: newStates })
    }

    sortDataToStates = (data) =&amp;gt; {
        const {
            provinceInStates, countyInState, addEntryToState, 
            createCountyInState, createEntryInState 
        } = this;

        for (const info in data) {
            const entry = data[info];
            if (provinceInStates(entry)) {
                countyInState(entry) ? 
                    addEntryToState(entry) 
                : 
                    createCountyInState(entry);
            } else {
                createEntryInState(entry);
            }
        }
    }
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This last function, sortDataToStates, looks a bit easier to read.  The logic to determine if the appropriate keys have been added to the final result have been separated out.  This in turn has made reading the if condition that much smoother.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Debugging SSH logins</title>
      <dc:creator>Adam La Rosa</dc:creator>
      <pubDate>Sun, 10 May 2020 06:35:22 +0000</pubDate>
      <link>https://dev.to/adamlarosa/debugging-ssh-logins-3jne</link>
      <guid>https://dev.to/adamlarosa/debugging-ssh-logins-3jne</guid>
      <description>&lt;p&gt;One of the main reasons I got into unix systems was the ability to remotely log into another machine.  While this is common now amongst most operating systems, the ability to telnet into another machine was once a novelty.  Before long people discovered that telnet's use of plain text was a security issue, and ssh became the dominate remote execution protocol.  &lt;/p&gt;

&lt;p&gt;I love being able to ssh into one of my machines at home from where ever I like (or can find a client to use).  Having recently installed OpenBSD 6.6 on a box laying around the house I of course enabled ssh during the installation.  Everything seemed fine from the machine itself.  It wasn't until I tried to log in remotely that I got this gem.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Connection Refused
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Not exactly my dreams of having the resources of my server available at the touch of a button.  After a reboot it worked fine, then after another I get the same error message.  Then after waiting a while I can log in again.  But where to look for answers?  My first clue was to check the dmesg buffer from boot and see what network device all this was happening under.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rl0 at pci2 dev 2 function 0 "Realtek 8139" rev 0x10: apic 2 int 22
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;So I know to look in the "rl" manual page for any resources.  After a brief glance I find this bit of knowledge.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BUGS
     Since outbound packets must be longword aligned, the transmit routine has
     to copy an unaligned packet into an mbuf cluster buffer before
     transmission.  The driver abuses the fact that the cluster buffer pool is
     allocated at system startup time in a contiguous region starting at a
     page boundary.  Since cluster buffers are 2048 bytes, they are longword
     aligned by definition.  The driver probably should not be depending on
     this characteristic.

     The Realtek data sheets are of especially poor quality: the grammar and
     spelling are awful and there is a lot of information missing,
     particularly concerning the receiver operation.  One particularly
     important fact that the data sheets fail to mention relates to the way in
     which the chip fills in the receive buffer.  When an interrupt is posted
     to signal that a frame has been received, it is possible that another
     frame might be in the process of being copied into the receive buffer
     while the driver is busy handling the first one.  If the driver manages
     to finish processing the first frame before the chip is done DMAing the
     rest of the next frame, the driver may attempt to process the next frame
     in the buffer before the chip has had a chance to finish DMAing all of
     it.

     The driver can check for an incomplete frame by inspecting the frame
     length in the header preceding the actual packet data: an incomplete
     frame will have the magic length of 0xFFF0.  When the driver encounters
     this value, it knows that it has finished processing all currently
     available packets.  Neither this magic value nor its significance are
     documented anywhere in the Realtek data sheets.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Which made me focus on this...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;One particularly important fact that the data sheets fail to mention relates to the way 
in which the chip fills in the receive buffer.  When an interrupt is posted to signal 
that a frame has been received, it is possible that another frame might be in the process of 
being copied into the receive buffer while the driver is busy handling the first one.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Swap out the network cards and voila!  No more refused connections.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Subtle Differences</title>
      <dc:creator>Adam La Rosa</dc:creator>
      <pubDate>Sun, 03 May 2020 05:31:35 +0000</pubDate>
      <link>https://dev.to/adamlarosa/subtle-differences-2ndo</link>
      <guid>https://dev.to/adamlarosa/subtle-differences-2ndo</guid>
      <description>&lt;p&gt;In the United States people say "hello", in France people might say "bonjour".  Programming languages seem to have the same nuance.  Just as different languages might have the same way of saying "hello", programming&lt;br&gt;
languages have different ways of achieving the same results.&lt;/p&gt;

&lt;p&gt;For example, in Ruby to declare an array one can easily give the instruction&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name_of_my_array = []
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In C++ things are a little different.  C++ has an array, but the size must be declared at the time of declaration, as well as the variable type.  So if you wanted to create an array with five locations of integers, it would be done like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int name_of_my_array [5];
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The same little differences can be found in Ruby and R.  In Ruby, as with many popular languages, assignment is done with an equals sign.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name_of_my_variable = "string"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Where as in R, assignment can be done with an arrow.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name of my variable &amp;lt;- "string"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;With learning new languages there's a sense of security in the knowledge that while you may have to learn new ways of doing something, the things you do always seem the same.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Git &amp; Branches</title>
      <dc:creator>Adam La Rosa</dc:creator>
      <pubDate>Sun, 26 Apr 2020 05:58:08 +0000</pubDate>
      <link>https://dev.to/adamlarosa/git-branches-1946</link>
      <guid>https://dev.to/adamlarosa/git-branches-1946</guid>
      <description>&lt;p&gt;I for one seem to always get carried away with my work.  By noon a project will be working fine &amp;amp; come evening for some reason a change I've made will cause enough errors that I have to backtrack to find the bug.  For far too long this entailed looking through directories of different saved files named with timestamps.  Then my life turned around...&lt;/p&gt;

&lt;p&gt;...then I discovered Git.&lt;/p&gt;

&lt;p&gt;Git is a wonderful tool for working on a project and saving your progress at different times.  Once it is installed on your system, just navigate into the project you'd like Git to work with and invoke a simple command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git init
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This will make the directory a working Git repository.  What this means is that Git will keep track of changes you make to files, and when you're ready, take a "snapshot" of the differences.  While Git has many MANY commands available to help in this task, my favorite is branches.&lt;/p&gt;

&lt;p&gt;Git branches allow you to create a mirror of what you're working on.  This way you can make any number of changes without worrying about breaking your project.  It is if a parallel universe is created for your project for you to tinker in.  Then, when you're satisfied with your changes you can "merge" them into your main branch.&lt;/p&gt;

&lt;p&gt;All Git repositories start on a branch called "master".  A new branch is created with the command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch name-of-new-branch
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;By then typing "git branch" alone you can see a list of branches your repository has.  To switch to the new branch one would type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout name-of-new-branch
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now you are actively working on the different branch.  Make all the changes you like!  None of these will affect the "master" branch.  Once you are done with your modifications the changes can be "merged" into the master branch!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
