<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by The Fidelity Salesman on Medium]]></title>
        <description><![CDATA[Stories by The Fidelity Salesman on Medium]]></description>
        <link>https://medium.com/@thefidelitysalesman?source=rss-9ac28ed84a72------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Q9lb56pxeUO-KJ5S.</url>
            <title>Stories by The Fidelity Salesman on Medium</title>
            <link>https://medium.com/@thefidelitysalesman?source=rss-9ac28ed84a72------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 00:46:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thefidelitysalesman/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[PROMISE me you will CALLBACK]]></title>
            <link>https://medium.com/@thefidelitysalesman/promise-me-you-will-callback-8901083f9a14?source=rss-9ac28ed84a72------2</link>
            <guid isPermaLink="false">https://medium.com/p/8901083f9a14</guid>
            <category><![CDATA[callback]]></category>
            <category><![CDATA[js-promise]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[The Fidelity Salesman]]></dc:creator>
            <pubDate>Tue, 15 Mar 2016 15:53:26 GMT</pubDate>
            <atom:updated>2016-03-15T18:25:35.700Z</atom:updated>
            <content:encoded><![CDATA[<p>The world of callback functions, promises, and the perennial struggle that is synchronous and asynchronous programming.</p><p>One of the biggest discussion points about javascript that I have read about (for the good and bad ) is the use of synchronous and asynchronous programming. So let’s do an overview about it.</p><p>SYNCHRONOUS</p><p>Let’s say you are in a line at a supermarket (if it gives you solace, imagine it as a Wal-Mart or a WholeFoods depending on your favorite political color scheme) with a group of people you know (a block of code). This supermarket only has one lane open, so you have to wait for every single person in your group to finish one at a time. This is <em>synchronous execution</em>.</p><p>Here is an example of synchronous execution in node.js.</p><pre>function foo() {<br>    var returnValue = bar();<br>    console.log(returnValue);<br>}<br><br>function bar() {<br>    return &quot;bar&quot;;<br>}</pre><p>If the amount of groceries being bought by each person(i.e. the level of programming) isn’t that much then no big deal. Everything get’s done orderly. In fact, javascript is a synchronous design based on a single-thread framework.</p><p>But what happens when you let Grandma go first (i.e. server requests and animations) with her 80 cans of creamed corn , and she has astigmatism, is paying with a personal check (GOD WHY WOULD YOU STILL DO THAT!), and she has arthritic little hands and can barely grip a friggin pen...then she realizes she had a coupon for half of the stuff after she’s almost done being rung up. The rest of your group (the remaining code) can’t get on their way until Bea Arthur finishes running her corn code. That can be the negative of synchronous programming not using an asynchronous API.</p><p>But what if there suddenly were other checkout lanes in the supermarket where the other members of the group could go ahead while less-funny Estelle Getty shovels through the purse she has had since prohibition and rambles on about how much she loves Pat Sajak (I’m getting to the point I swear). That is what <em>asynchronous execution</em> is all about.</p><p>Asynchronous programming is allowing multiple code tasks to be completed in the background through the use of callback functions.</p><p>A callback function is a function that is simply passed to another function as a type of parameter. When it is executed, it will be called inside the other function. It does not happen immediately, but at a specified point. That specified point is usually known as a closure, which is the inner function’s access to outer function’s variables (i.e. scope chain). Here is a quick example of a callback being used from <a href="http://www.javascriptissexy.com/">www.javascriptissexy.com</a></p><pre>​// A function that takes two parameters, the last one a callback function​</pre><pre>​function getInput (options, callback) {</pre><pre>allUserData.push (options);</pre><pre>callback (options);</pre><pre>​</pre><pre>}</pre><p>Now so far it would appear that asynchronous is the faster method, but it’s biggest drawback is what is known as ‘callback hell’. It is when you have a line of code that can be so convoluted in callback functions, that it is borderline impossible to follow the logic of the code. Now, some would argue that if you are the one writing the code and you understand it, there should be no problem. That logic dies at any type of profession that involves group project design (e.g. EVERYTHING IN PROGRAMMING FOR THE MOST PART). It would be like having a construction crew split up doing a list of tasks, but having no idea how to organize them after their task is completed. This is an example of callback hell I found:</p><pre>fs.readdir(source, <strong>function</strong> (err, files) {<br>  <strong>if</strong> (err) {<br>    console.log(&#39;Error finding files: &#39; <strong>+</strong> err)<br>  } <strong>else</strong> {<br>    files.<strong>forEach</strong>(<strong>function</strong> (filename, fileIndex) {<br>      console.log(filename)<br>      gm(source <strong>+</strong> filename).size(<strong>function</strong> (err, values) {<br>        <strong>if</strong> (err) {<br>          console.log(&#39;Error identifying file size: &#39; <strong>+</strong> err)<br>        } <strong>else</strong> {<br>          console.log(filename <strong>+</strong> &#39; : &#39; <strong>+</strong> values)<br>          aspect <strong>=</strong> (values.width / values.height)<br>          widths.<strong>forEach</strong>(<strong>function</strong> (width, widthIndex) {<br>            height <strong>=</strong> Math.round(width / aspect)<br>            console.log(&#39;resizing &#39; <strong>+</strong> filename <strong>+</strong> &#39;to &#39; <strong>+</strong> height <strong>+</strong> &#39;x&#39; <strong>+</strong> height)<br>            <strong>this</strong>.resize(width, height).write(dest <strong>+</strong> &#39;w&#39; <strong>+</strong> width <strong>+</strong> &#39;_&#39; <strong>+</strong> filename, <strong>function</strong>(err) {<br>              <strong>if</strong> (err) console.log(&#39;Error writing file: &#39; <strong>+</strong> err)<br>            })<br>          }.bind(<strong>this</strong>))<br>        }<br>      })<br>    })<br>  }<br>})</pre><p>So there has to be a healthy medium here (see what I did there) where we can have asynchronous programming, but can still follow a synchronous design. That’s where <em>Promises</em> comes in to save the day.</p><p>PROMISES</p><p>A Promise is an object that is used for the use of asynchronous methods to be implemented in a synchronous order. A promise represents an operation that has not been completely finished, but will be in the future of the code. Doing this allows asynchronous methods to return values like synchronous methods. A promise is similar to a foreman on a construction site (to use the previous metaphor) that allows it’s crew to do multiple tasks asynchronously while still ordering it properly for formatting.</p><pre><strong>function</strong> readJSON(filename){<br>  <strong>return</strong> <strong>new</strong> Promise(<strong>function</strong> (fulfill, reject){<br>    readFile(filename, &#39;utf8&#39;).done(<strong>function</strong> (res){<br>      <strong>try</strong> {<br>        fulfill(JSON.parse(res));<br>      } <strong>catch</strong> (ex) {<br>        reject(ex);<br>      }<br>    }, reject);<br>  });<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8901083f9a14" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[THOUGHTS ON CHAPTER SEVEN OF HEAD_FIRST_SQL]]></title>
            <link>https://medium.com/@thefidelitysalesman/thoughts-on-chapter-seven-of-head-first-sql-262b5125ba8a?source=rss-9ac28ed84a72------2</link>
            <guid isPermaLink="false">https://medium.com/p/262b5125ba8a</guid>
            <category><![CDATA[normalization]]></category>
            <category><![CDATA[database-relationships]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[The Fidelity Salesman]]></dc:creator>
            <pubDate>Thu, 10 Mar 2016 16:32:10 GMT</pubDate>
            <atom:updated>2016-03-14T21:47:44.016Z</atom:updated>
            <content:encoded><![CDATA[<p>Yesterday evening, we were assigned to read over chapter seven of the book <em>Head First SQL. </em>I have really enjoyed the book so far because even though it is lengthy (in regards to pages, not really material), the material is very user friendly and has great explanations. Here are my thoughts on chapter seven:</p><p>Key points of chapter seven (<em>Head First SQL</em>);</p><p>The purpose of chapter seven is to discuss the downsides of conveluted data with data put together that is not Atomic data. Atomic data are elements that simply represent the lowest level of detail. In other words, you don’t want to have a table with mutliple types of various data (i.e. first name, last name, interests, fears, etc). The first name and last name won’t be difficult since we only have one of those for the most part, but interests and fears will ultimately have a sundry of responses. In order to simplify our query searches, it will help us to create new tables that will properly organize our data and make it atomic. The chapter also reiterated database relationships which I will discuss below. Lastly, the chapter reiterated the discussion of normalization.</p><p>(pg. 284)</p><p>The query below uses the AND command to make go through major requirements. When it gets to the birthdays, why not just use BETWEEN? It seems that would be a simpler command.</p><pre>SELECT * FROM my_contacts</pre><pre>WHERE gender = ‘F’</pre><pre>AND status = ‘single’</pre><pre>AND state = ‘MA’</pre><pre>AND seeking LIKE ‘%single M%’</pre><pre>AND birthday &gt; ‘1950–08–28’</pre><pre>AND birthday &lt; ‘1960–08–28’</pre><pre>AND SUBSTRING_INDEX(interests, ‘,’,1) = ‘animals’;</pre><p>This could also use OR to differentiate between interests, but it is instead used to find match with ALL interests.</p><p>I’m a bit confused about the comma problem on page 288. When it creates the substring for interests, why does it need two commas? The answer is a little confusing to me.</p><pre>SUBSTRING_INDEX(interests, ‘,’,1);</pre><p>I love this book. Has wonderfully geeky humor.</p><p>“The next day, Regis shows up at Greg’s door, clearly upset. Regis shouts, “she was definitely interested in animals. But you didn’t tell me that one of her interests was TAXIDERMY. Dead animals everywhere!”</p><p>“Use your ALTER and the SUBSTRING_INDEX function to end up with these columns. WRITE as many queries as it takes.</p><p>//First you need to create the new columns:</p><pre>ALTER TABLE my_cotacts</pre><pre>ADD COLUMN interest1 VARCHAR(50),</pre><pre>ADD COLUMN interest2 VARCHAR(50),</pre><pre>ADD COLUMN interest3 VARCHAR(50),</pre><pre>ADD COLUMN interest4 VARCHAR(50),</pre><p>//Then you need to move the first interest to the new interest column.</p><pre>UPDATE my_contacts</pre><pre>SET interest1 = SUBSTRING_INDEX(interests, ‘,’,1);</pre><p>//Next we need to remove the first interest from the interests field since it’s sorted in interest!</p><p>//We remove everything until right after the first comma with a string function.</p><pre>UPDATE my_contacts SET interests = TRIM(RIGHT(interests, LENGTH(interests) = LENGTH(interest1) — 1)));</pre><p>/*TRIM removes the space left in front of the string after we removed everything in front of the comma. RIGHT returns part of the interests column starting from the righthand side.</p><p>THE LENGTH (interests) part compute how much of the interests column we need. It takes the total length of the interests column and subtracts the length of the part we moved to interest! Then we subtract one more so we start after the comma</p><p>NOW REPEAT THE STEPS FOR THE OTHER INTERESTS COLUMNS!*/</p><p>Finally, all we have left is a single value:</p><pre>UPDATE my_contacts SET interest4 = interests;</pre><p>Now we can drop the interests column entirely. We also could have just renamed it interest4 and not needed the ADD COLUMN (assuming we just have four interests).</p><p>CREATE a table with a foreign key: the foreign key is a column that references your primary key in another table.</p><pre>CREATE TABLE interests (</pre><pre>init_id NOT NULL AUTO-INCREMENT PRIMARY KEY, /*This command is a quicker way to designate your primary key*/</pre><pre>interest VARCHAR(50) NOT NULL,</pre><pre>contact_id INT NOT NULL,</pre><pre>CONSTRAINT my_contacts_contact_id_fk </pre><p>/*This is named CONSTRAINT in a way that tells us which table the key comes from (my_contacts), what we’ve named the key (contact_id), and that it’s a foreign key(fk) */</p><pre>FOREIGN KEY (contact_id) </pre><p>/*The column name in parentheses is what will become a foreign key. You can name it whatever you like*/</p><pre>REFERENCES my_contacts (contact_id);</pre><p>/*Specifies where foreign key came from and what it’s called in another table*/</p><p>UNIQUE is also considered a constraint</p><p>CHECK constraint is NOT available in mySQL. It allows you to specify a condition that must be met on a column before you can insert a value into that column.</p><p>When a column’s data must change when another column’s data is modified, the first column is functionally dependent on the second.</p><p>Functional dependency shorthand</p><pre>T.x -&gt;; T.y</pre><pre>superheroes.name -&gt;; super_heroes.initials.</pre><p>A partial functional dependency means that a non-key column is dependent on some, but not all, of the columns in a composite primary key. (i.e. name and power), Initials depend on the name, but not on the power.</p><p>Transitive dependency.</p><p>If changing any of the non-key columns might cause any of the other columns to change, you have a transitive dependency. (i.e. a superhero changes his arch_enemy. Thus the enemy_id would change and possibly change the city of the arch enemy).</p><p>Now if the update of the arch enemy id changes the value in the arch enemy city column then it is a transitive functional dependency because the non-key arch enemy column is related to arch enemy id, which is another of the non-key columns.</p><h3>DATA BASE RELATIONSHIPS</h3><p>One-to-One: exactly one row of a parent table is related to one row of a child table.</p><p>One-to-Many: a record in table A can have MANY matching records in Table B, but a record in Table B can only match ONE record in Table A.</p><p>For example: the prof_id for Programmer may show up more than once in my_contacts, but each person in my_contacts will only have one prof_id.</p><p>Many-to-Many. It’s usually made up to TWO ONE-TO-MANY RELATIONSHIPS with a JUNCTION TABLE IN BETWEEN. This allows many rows in the first to match many rows in the second, and vice versa. A junction table is a table that is like a step in between two many-to-many tables and simplify the relationships to one-to-many. Ultimately it will contain the primary key columns we want to connect.</p><h3>NORMALIZATION</h3><p>First Normal form (1NF):</p><p>Columns contain only atomic values, and no repeating groups of data are permitted in a column.</p><p>Transitive Functional Dependency:</p><p>This means any NON-KEY column is related to any other of the non-key columns</p><p>Second Normal Form (2NF):</p><p>Your table must be in 1NF and contain no partial functional dependencies to be in 2NF</p><p>Third Normal Form (3NF):</p><p>Your table must be in 2NF and have no transitive dependencies.</p><p>Composite Key:</p><p>This is a primary key made up of multiple columns, which create a unique key value. (e.g. the superhero table with the columns (name, power).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=262b5125ba8a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Databases PART II, THE SQL]]></title>
            <link>https://medium.com/@thefidelitysalesman/databases-part-ii-the-sql-170b1cae7c38?source=rss-9ac28ed84a72------2</link>
            <guid isPermaLink="false">https://medium.com/p/170b1cae7c38</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[sql-setup]]></category>
            <dc:creator><![CDATA[The Fidelity Salesman]]></dc:creator>
            <pubDate>Thu, 10 Mar 2016 16:16:36 GMT</pubDate>
            <atom:updated>2016-03-10T16:44:13.446Z</atom:updated>
            <content:encoded><![CDATA[<p>9 Cuauhtli (1-) Mazatl 4- Tecpatl</p><h4>I have to say that I have been pleasantly surprised with the simplicity of SQL so far (I say that then I’ll find out that Advanced SQl is basically reading Sanskrit). I thought it would be a good idea to give an overview of some of the basic commands. Structured query language (SQL) is a language that is used to easily communicate with any type of database, but is primarily the standard language for relational database management systems.</h4><h3>CREATING THE DATABASE</h3><p>CREATE</p><p>This is by far the most fundamental component of SQL. First you must create a database where the data can be stored, altered, updated, etc.</p><pre>CREATE DATABASE contacts;</pre><p>When you make a table, it has rows that represent types of data and components that represent (well, a component) of said data. Thus the create table structures the tables based on the data being used.</p><pre>CREATE TABLE contact(<br> id INT(10) unsigned NOT NULL AUTO_INCREMENT,<br> nameLast VARCHAR(30),<br> nameFirst VARCHAR(25),<br> email VARCHAR(50),<br> cell VARCHAR(15),<br> PRIMARY KEY (id)<br>);</pre><p>Notice that I have added unique columns based on average data. I also gave them character limits based on whether it is a number (INT) or a string (VARCHAR). We also have what is called the primary key. A primary key is a field in a table which MUST UNIQUELY identify each row in a database table. Here we used the field (id) since it will be a number unique solely to the individual.</p><p>ALTER</p><p>If later on, you are looking at a table and you realize you need to add another column for your table, you simply use the ALTER TABLE statement is used to add, delete, or modify columns in an existing table.</p><p># USED with ALTER: <br>CHANGE both name and data type<br>MODIFY data type or position of column<br>ADD add column to table, with data type<br>DROP kill column<br>* can hurt data</p><pre>ALTER TABLE table_name<br>ADD column_name datatype</pre><pre>ALTER TABLE myTable<br>CHANGE COLUMN someColumnName newColumnname INT NOT NULL, AUTO_INCREMENT,<br>ADD PRIMARY KEY (‘newColumnname’);</pre><p>If I want to delete a table, I do this:</p><pre>ALTER TABLE table_name<br>DROP COLUMN column_name</pre><p>INSERT INTO</p><p>But now, how do I put in my data now that the data has been made. That’s where INSERT comes into play. The INSERT INTO statement is used to insert new records in a table. Here we insert where the information will go based on their columns. then the VALUES will be placed in afterward. Similar to making function parameters then calling said function and plugging in the arguments. One other point of order: columns can be in any order as long as values provided are in sync.columns. Leaving out column names means ALL values must be provided and in EXACT order.</p><pre>INSERT INTO <em>table_name</em> (<em>column1</em>,<em>column2</em>,<em>column3</em>,…)<br>VALUES (<em>value1</em>,<em>value2</em>,<em>value3</em>,…);</pre><h3>QUERYING</h3><p>SELECT</p><p>The select statement is used to select data from a database and placed in what is called a result table.</p><pre>SELECT * FROM contact;</pre><p>Here I also used the ‘*’ to signify “all”. This command is selecting all data stored in the contact table.</p><p>Now let’s say that you want to narrow your search down to a particular category. Here you can use the WHERE function. The example below filters my selection to the gender column to where I find only females.</p><pre>SELECT * FROM contact WHERE gender = ‘F’;</pre><p>AND/OR</p><p>The AND operator will display a record if both the first condition asked for and the condition are true.</p><p>The OR operator displays a record if either the first or second condition are true.</p><pre>SELECT * FROM Customers<br>WHERE Country=’Germany’<br>AND City=’Berlin’;</pre><p>IN</p><p>Lets say you want to know if a value is in your particular table of data, use the IN operator to specify values in a WHERE clause.</p><pre>SELECT <em>column_name(s)</em><br>FROM <em>table_name</em><br>WHERE <em>column_name</em> IN (<em>value1</em>,<em>value2</em>,…);</pre><p>ORDER BY</p><p>Now if you wanted to look at your result set but make sure it was properly ordered, you can use the ORDER BY keyword. It will sort the sets by one or more columns. If you use ORDER BY, it will automatically put the records in ascending order by default. If you want to put them in descending order, then you must follow it with the DESC keyword.</p><pre>SELECT * FROM Customers<br>ORDER BY Country;</pre><pre>SELECT * FROM Customers<br>ORDER BY Country DESC;</pre><p>GROUP BY</p><p>The GROUP BY statement is used in conjunction with the aggregate functions (COUNT, SUM, etc….I’ll get to those later) to group the result-set by one or more columns.</p><pre>SELECT column_name, aggregate_function(column_name)<br>FROM table_name<br>WHERE column_name operator value<br>GROUP BY column_name;</pre><p>BETWEEN</p><p>The BETWEEN operator is used to select values within a range.</p><pre>SELECT * FROM Products<br>WHERE Price BETWEEN 10 AND 20;</pre><p>Its opposite is the NOT BETWEEN OPERATOR.</p><pre>SELECT * FROM Products<br>WHERE Price NOT BETWEEN 10 AND 20;</pre><p>LIKE</p><p>The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. Here we use the % sign to define wildcards (missing letters) both before and after the pattern. In this case, it is being used after the s. Just like BETWEEN, you can also use the NOT LIKE pattern to find the opposite.</p><pre>SELECT * FROM Customers<br>WHERE City LIKE ‘s%’;</pre><pre>SELECT * FROM Customers<br>WHERE Country NOT LIKE ‘%land%’;</pre><p>DELETE</p><p>The DELETE statement is used to delete rows in a table. Be very careful when deleting ANYTHING. ONCE DONE, IT CANNOT BE UNDONE. It’s also possible to delete data from a table without deleting the table.</p><pre>DELETE * FROM <em>table_name</em>;</pre><pre>DELETE FROM Customers<br>WHERE CustomerName=’Alfreds Futterkiste’ AND ContactName=’Maria Anders’;</pre><p>DISTINCT</p><p>In a table, a column may contain many duplicate values; and sometimes you only want to list the different (distinct) values.</p><p>The DISTINCT keyword can be used to return only distinct (different) values.</p><pre>SELECT DISTINCT City FROM Customers;</pre><h3>AGGREGATE FUNCTIONS</h3><p>Aggregate functions are used to compute against a “returned column of numeric data” from your SELECT statement. Here are the most commonly used ones thus far:</p><p>MINreturns the smallest value in a given column</p><pre>SELECT MIN(Price) AS SmallestOrderPrice FROM Products;</pre><p>MAXreturns the largest value in a given column</p><pre>SELECT MAX(Price) AS HighestPrice FROM Products;</pre><p>SUMreturns the sum of the numeric values in a given column</p><pre>SELECT SUM(Quantity) AS TotalItemsOrdered FROM OrderDetails;</pre><p>AVGreturns the average value of a given column</p><pre>SELECT AVG(Price) AS PriceAverage FROM Products;</pre><p>COUNTreturns the total number of values in a given column</p><pre>SELECT COUNT(CustomerID) AS OrdersFromCustomerID7 FROM Orders<br>WHERE CustomerID=7;</pre><p>COUNT(*)returns the number of rows in a table</p><pre>SELECT COUNT(*) AS NumberOfOrders FROM Orders;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=170b1cae7c38" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQ(HEL)L]]></title>
            <link>https://medium.com/@thefidelitysalesman/sq-hel-l-47b00c55ba62?source=rss-9ac28ed84a72------2</link>
            <guid isPermaLink="false">https://medium.com/p/47b00c55ba62</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[installation]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[The Fidelity Salesman]]></dc:creator>
            <pubDate>Wed, 09 Mar 2016 14:56:44 GMT</pubDate>
            <atom:updated>2016-03-09T17:57:22.777Z</atom:updated>
            <content:encoded><![CDATA[<p>jaj chorgh ma’rIch (I looked up Klingon for the date…I was just bored..shut up).</p><p>So, I hit myself quite the snafoo when I was attempting to install SQL and run in on my ol’ buddy the command line interface (CLI). It basically involved a smorgasbord of problems that for the sake of my mental being, I would rather not discuss. What I do want to chat about is doing it the right way. So let’s begin.</p><p>The first thing you need to do is go to <a href="https://dev.mysql.com/downloads/mysql">https://dev.mysql.com/downloads/mysql</a> and download this suckah. Specifically download the archive file that is closest to your heart (also known as most compatible to your OS).</p><p>After this, open the DMG file and run the installer package. The great thing is that this part is very self-explanatory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Y0CuUhs3eDYzznT5zK_y6A.png" /></figure><p>Now, once installation is complete, you will be given a temporary password. HOLD ON TO THIS LIKE IT IS THE HOLY FRIGGIN GRAIL!!! Best practice is to copy paste file into a plain text file on something like sublimetext or notepad. Don’t put it on something that is more about formatting (i.e pages/microsoft word).</p><p>After this, you want to open up your terminal and make sure that bad boy made it in safely. So open up your friendly neighborhood terminal (or iTerm for my Mac people out there) and use the following command:</p><pre>$ cd /usr/local/mysql/bin/</pre><p>Now once this is done, you can see all the programs available. One other important thing to do is to make sure the sql is actually running! Here, you have two options: One simple way is to go to your system preferences, click on the mySQL icon, then simply click the start mySQL button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*aqSgr0i8bbNajzCeA3Mc5w.png" /></figure><p>Now for those of you a wee bit more daring (i.e. what you need to know how to do with the terminal anyway), go to your command line and start it up through the command line. You have a couple options:</p><p>First, try this bad boy out:</p><pre>$ mysql -u root -p</pre><p>This command will ask you to put in that godless abomination you call a temporary password. Once you have done that and have seen their original atari-looking welcome screen, you will then need to reset that password IMMEDIATELY (I can’t stress this enough). To do so, use the following command.</p><pre>mysql&gt; SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(‘password’);</pre><p>Now, some other options for starting up mySQL are the following:</p><pre>sudo /usr/local/mysql/support-files/mysql.server start</pre><p>Now this uses the sudo command. The purpose of sudo is to execute the command you give the terminal with what is called ‘root privileges’. Ultimately, root is the user name that has access to all the commands…so this really…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*pxA8LoZMYcGnkHKl3xt9Vg.gif" /></figure><p>You can also start your sql in safe mode as well:</p><pre>sudo msqld_safe</pre><p>Now, I named this little diatribe (maybe that’s a little too strong a word, but oh well) SQ(HEL)L because the process of removing mySQL from your OS once you’ve have improperly installed it and/or lost the dreaded temporary password is the emotional equivalent of waterboarding for a novice programmer like myself. So, my followers (in the blogging sense, not the follow me to the promise land sense), please follow directions closely so you can avoid the headache of improperly installing SQL. It’s a really simple program when it’s installed, so make sure you follow along to avoid a bad sequel…i’m actually angry about that pun. I feel like potential employers will read this one day and immediately dismiss me based solely on puns…anyway, see ya.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47b00c55ba62" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Merge Sort (Pizza Friday Presentation)]]></title>
            <link>https://medium.com/@thefidelitysalesman/merge-sort-efaadaa934b0?source=rss-9ac28ed84a72------2</link>
            <guid isPermaLink="false">https://medium.com/p/efaadaa934b0</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[The Fidelity Salesman]]></dc:creator>
            <pubDate>Fri, 04 Mar 2016 15:54:57 GMT</pubDate>
            <atom:updated>2016-03-04T17:24:20.419Z</atom:updated>
            <content:encoded><![CDATA[<p>I had to make a lesson where I needed to explain the mergeSort algorithm in javascript. A link to my presentation is below, but I want to go ahead and give a gist of the merge sort algorithm.</p><p>Merge sort is a recursive sorting algorithm that breaks a list of data into smaller and smaller lists until their length is 1 (index 0), then compares each element (list of one) to its neighbor returning a sorted small list. Once the small list is sorted, it iterates over the small lists, comparing them and merging them into a larger list.</p><p>The efficiency follows n*log(base2)n time. Each time the list is broken in two, that is one step. Therefore the number of steps for this part is equal to the log base 2 of the number of elements in the set. For example a set of 4 will be split twice, a set of 8 will be split 3 times, and so on.</p><p>The second part involves comparing elements of the lists, and there are a number of comparisons equal to the number of elements in the arrays. Therefore the number of steps each time the array is split is equal to the number of elements n. In order to fully explain merge sort, you must first understand the merge function I used with it.</p><pre>PSEUDOCODE FOR MERGE:</pre><pre>1. Merge is basically a function that will compare two lists to see which has the greater value, then merge in the appropriate order. Our parameters will be left and right.</pre><pre>2. Next, create an empty array where the result of your function can go when completed. It also helps to create variables for your original array lengths and index. Before the merging of the lists can happen, all lists must be at index</pre><pre>3. Using a while loop for this one, the index of each parameter must be less than the length (in other words, the length of the array must be One [index 0]). Using a conditional, if the list on the list on the left is less than the list on the right, push left. If the right list is less than the left, push the right in to the result.</pre><pre>4. You must then return the result using the ‘concat’ method. The concat() method returns a new array comprised of the array on which it is called joined with the array(s) and/or value(s) provided as arguments. You must also also slice each side based on the zero index.</pre><p>Here is the code implemented:</p><pre><br>   function merge(left, right){ <br>      var result = [],<br>      lLen = left.length, <br>      rLen = right.length, <br>      l = 0, <br>      r = 0; <br>   while(l &lt; lLen &amp;&amp; r &lt; rLen){ <br>     if(left[l] &lt; right[r]){ <br>       result.push(left[l++]); <br>   } <br>   else{ <br>     result.push(right[r++]); <br>   } <br>  } <br>  //remaining part needs to be added to the result <br>  return result.concat(left.slice(l)).concat(right.slice(r)); <br>}</pre><p>So, let’s break down the merge sort algorithm I used as an example:</p><pre>1. A method that recursively sorts an input array of comparable data <br>Here we will create the function and put in its parameter. Here we call it array.</pre><pre>2. If the list is less than 2 indices, return the array. I decided to create a variable for the array length as well. This is simply saying that if your list has one index, then return because there is nothing else you need to do here. </pre><pre>3. Since we will not have the fortune of having an array with just one index, we will have to split up the list. Here we can use the Math.floor function. The Math.floor() function returns the largest integer less than or equal to a given number. In this case, it’s argument is the length of the array divided by two. Also found it easier and cleaner to make a variable. When the list is split, I found it is better to create a variable that divides each new list. Left and Right seemed the easiest. With each list, you then call for the array to be sliced . With the left side, the parameters are index zero and the Math.floor variable. With the right, the parameter is just the Math.floor variable. Here I used the chain method to put all of my variables together. </pre><pre>4. Send left and right to the mergeSort to broke it down into pieces<br>   then merge those by returning the merge function (which was explained previously.)</pre><p>Here is the implemented code:</p><pre>function mergeSort(arr){ <br>var len = arr.length; </pre><pre>if(len &lt;2) <br>  return arr; <br>var mid = Math.floor(len/2), <br>    left = arr.slice(0,mid), <br>    right =arr.slice(mid); </pre><pre>//send left and right to the mergeSort to broke it down into pieces //then merge those </pre><pre>return merge(mergeSort(left),mergeSort(right)); </pre><pre>}</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fprezi.com%2Fembed%2Fucwwgm5_nujq%2F%3Fbgcolor%3Dffffff%26lock_to_path%3D0%26autoplay%3D0%26autohide_ctrls%3D0%26features%3Dundefined%26disabled_features%3Dundefined&amp;url=https%3A%2F%2Fprezi.com%2Fucwwgm5_nujq%2Fcopy-of-merge-sort%2F&amp;image=https%3A%2F%2F0701.static.prezi.com%2Fpreview%2Ftb6g3su4b7qp3glopkbqx32ryd6jc3sachvcdoaizecfr3dnitcq_0_0.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=prezi" width="800" height="581" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fd725f30216e71e5890268590613560/href">https://medium.com/media/7fd725f30216e71e5890268590613560/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efaadaa934b0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My brother, the CEO/Janitor]]></title>
            <link>https://medium.com/@thefidelitysalesman/my-brother-the-ceo-janitor-57004777dc91?source=rss-9ac28ed84a72------2</link>
            <guid isPermaLink="false">https://medium.com/p/57004777dc91</guid>
            <category><![CDATA[fitness]]></category>
            <category><![CDATA[life-lessons]]></category>
            <dc:creator><![CDATA[The Fidelity Salesman]]></dc:creator>
            <pubDate>Thu, 03 Mar 2016 15:19:11 GMT</pubDate>
            <atom:updated>2016-03-03T15:19:11.773Z</atom:updated>
            <content:encoded><![CDATA[<p>This is something my brother wrote a couple years ago while working on his start-up in California. I remember reading it for the first time and thinking of two things: First, “Holy shit. This is my little brother”. Ever since we were kids, he has had a type of tenacity that I must admit I’ve always admired in him. He constantly pushes himself to be the best at everything he can. Second, “Kinda sad that this isn’t common sense”. Maybe it was because we were raised by two people who pushed hard work and humility, but in an age of such entitlement and expectation, I find myself grateful to know that some ideals of our youth stay with us. Just food for thought:</p><h3><a href="http://www.zachbruhnke.com/youre-not-the-ceo-youre-the-fucking-janitor">You’re not the CEO — you’re the Fucking Janitor</a></h3><p>June 27th, 2012 <a href="http://www.zachbruhnke.com/youre-not-the-ceo-youre-the-fucking-janitor#respond">§ 0</a></p><p>So this post comes to you after me reading a string of one too many “<strong>Life of a CEO</strong>” or “<strong>What its like to be a CEO</strong>” posts.</p><p>I’m about to hit you with a major dose of <strong>REALITY</strong>, and you might not like it.</p><p>If you’re dreaming about being the CEO of a company you probably aren’t fit to run one. If you think its a lavish lifestyle filled with private planes and swimming pools full of money, you might just have a rude awakening coming.</p><p><strong>The life of a CEO is not always glamorous</strong>. TechCrunch would like you to think so and so would many of the people who write about it on Hacker News but the reality is you probably are the CEO in title alone. When your company consists of three people but you sign documents as the CEO you should probably put that in prospective, you are TECHNICALLY the CEO but what kind of real power or reach does that give you. It means you were the most capable of a three person team, or perhaps just the one with the most generalized skillset and since you had no specialty CEO was the interim role you filled.</p><p><strong>This post first crossed my mind several months ago when I was talking to a startup CEO who I will leave unnamed</strong>. he and I were talking about interns and their role in a small organization(this particular one was less than 5) I was encouraging him to be open and let interns have full insight into all facets of the business, openly present ideas and consider them.</p><p><em>I’ll never forget the response he gave me.</em> <strong>“Zach, I want you to think about this, how many interns get to go sit down and talk to the CEO of a company about its inner-workings every day? it just does not make sense”</strong></p><p>At that point in the conversation I knew it would end soon and in fact it already had in my head. Someone who did not understand something as simple as being humble enough to realize that his small organization needed all the help it could get from any parties interested and invested in giving feedback would probably never see my point of view.</p><p>When you’re the CEO of a startup you’re the person who will do ANYTHING, and I do mean ANYTHING to make it succeed.</p><p><strong>And here’s how it is in reality:</strong></p><p>If you want to be a CEO in the sense that you dream of them you should remember to be the <strong>Fucking Janitor</strong> too.</p><p>What I mean by this is simple and I’ll illustrate it in a quick story when a slightly younger version of myself sat down to get a small business loan at a young age.</p><p>As we sifted through the paperwork it took to do a loan the question came up. It was the first time anyone had ever asked me, but its not one I’ll soon forget.</p><p><em>The loan officer looked at me and said</em><strong><em> “So Zach, what’s your title? Are you the President? The CEO?”</em></strong></p><p><em>It didn’t take too long for me to spit out what came next. In a tone that could only be used by someone with the inexperience of a person my age (19 or 20 at the time) I looked at him and said </em><strong>“Ryan, last night when I was sweeping the floor I was the Fucking Janitor”.</strong></p><p><em>Ryan laughed, then paused shook his head and said</em> <strong>“We’ll go with owner on this one.”</strong></p><p>The story is one that displays a combination of things, some arrogance, lots of inexperience and some humility. But one thing I still take away from that years later is that no matter what I do I will always be the Janitor.</p><p>My employees never looked at me as a boss but always as a colleague. They knew that if they didn’t pick up that broom to sweep the floor then I certainly would and that led to a much more productive work environment. Everyone knew of the willingness of others to do anything necessary to help make our business a success and that is the kind of attitude that makes winners.</p><p>I’d encourage you the next time you start thinking of yourself as the CEO to also remember to always be the Janitor too. It’s great to become someone who is looked up to, or to make an impact, but its even more important to remember where you started and stay true to who you wanted to be before you got to where you are.</p><p><strong>So I hope if you’re reading this, you’ll remember to always be the Janitor.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57004777dc91" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keep your mind RESTful (Immersion Day 2)]]></title>
            <link>https://medium.com/@thefidelitysalesman/keep-your-mind-restful-immersion-day-2-2b9bb61d793?source=rss-9ac28ed84a72------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b9bb61d793</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[The Fidelity Salesman]]></dc:creator>
            <pubDate>Thu, 03 Mar 2016 15:08:13 GMT</pubDate>
            <atom:updated>2016-03-03T15:08:13.282Z</atom:updated>
            <content:encoded><![CDATA[<p>The year of our lord: 03/01/16</p><p>Today instills the second day of our immersion program. The gist of today was implementing Post, Put, and Delete. We began with Post, and got a little help from the wonderful google chrome app, Postman. So let’s get to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zqrLdYMur0vReVsjqgaKnQ.jpeg" /><figcaption>I’ve made peace with the fact that almost everything I use as a headline is cheesy as hell…although, is hell cheesy? Maybe if you’re an atheist…or lactose intolerant…I’m gonna shut up now..</figcaption></figure><p>As I talked about on yesterday’s post (no pun intended), POST is used to create new resources. Here you need to create a new, unique id for each resource. Here is the code I made for post:</p><pre>//POST takes JSON bodies, so we use jsonParser as middleware//<br>router.post(‘/product’, jsonParser, function(req, res) {<br> products.create(req.body);<br> res.setHeader(‘Content-Type’, ‘application/json’);<br> var result = {message: ‘in development’};<br> res.end(JSON.stringify(result));<br>});</pre><p>So the main mission here is that we already have a JSON file of “products” that we are using from a previous project. We want to use the post method to add a new id and object into our existing array of objects in the JSON file. This is where Postman comes into play.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t8jkAuJOCm-C-JOYmnpWOA.png" /></figure><p>what I need to do is use the post setting on Postman, put in my host url so it knows where the new resource information should, and use the header setting to create my header (i.e. ‘Content-Type’: ‘application/json’ that you saw in my code above). In the raw body portion, i put in the new product information wrapped in an object. We then send the object, and it should return with my result message “In development”.</p><h3>DON’T “PUT” ME, CAUSE I’M CLOSE TO THE EDGE..</h3><p>Next, we use the put method. As I put in my day one blog, put is basically used to update or alter a new resource. From what I have read, some programmers have used it in the place of post, but, again, not recommended for the quality of practice and for the sake of future programmers who may have to look at your code and decipher whatever cropcircle-esque (patent pending on that word) nightmare you just designed. Put also should return, like other commands, status codes to let the client know whether or not the command has been done properly. Whether it be code 200 (meaning all is well), 204 (meaning there is no content), or the ever popular/disconcerting 404 (content not found). Here is my code for put:</p><pre>router.put(‘/product/:id’, function(req, res){<br> products.update(parseInt(req.params.id, 10), req.body);<br> res.setHeader(‘Content-Type’, ‘application/json’);<br> var result = {message: ‘in development’};<br> res.end(JSON.stringify(result));<br>});</pre><h3>Delete…nothing cute, just delete.</h3><p>Delete is just that. A method to remove a resource. Here is the code for delete:</p><pre>router.delete(‘/product/:id’, function (req, res){<br> products.removeProduct(parseInt(req.params.id, 10));<br> res.setHeader(‘Content-Type’, ‘application/json’);<br> var result = {message: ‘It is deleted’};<br> res.end(JSON.stringify(result));<br>});</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b9bb61d793" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Those who node, do…(Immersion Day 1)]]></title>
            <link>https://medium.com/@thefidelitysalesman/those-who-node-do-immersion-day-1-ef24a802f67c?source=rss-9ac28ed84a72------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef24a802f67c</guid>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[The Fidelity Salesman]]></dc:creator>
            <pubDate>Tue, 01 Mar 2016 15:08:20 GMT</pubDate>
            <atom:updated>2016-03-14T22:28:08.216Z</atom:updated>
            <content:encoded><![CDATA[<p>Star date: 022916 (not accurate, so calm down trekkies)</p><p>Today is the first day of a new frontier: the world of Node.js. Node is basically an open-source environment that is used for developing a server side web application in a javascript framework. It’s major purpose is to pick up I/O (input/output) requests, listen for an event, and then send it back to the client side. Since it is a Javascript framework, it helps because it is the same type of code that powers applications like Gmail. One thing I researched about node is that it is also driven by what is called “Asynchronous Design”. Asynchronous designed is a basically a type of self-timed circuit. Most modern digital devices run on a synchronous circuit, a.k.a. clock circuit, which is run by repetitive pulses to create signal changes. Clock circuits basically create certain limits on speed/processing and also use up more power. To put in simple terms, node is a program that is faster, lower on power consumption, and has a high level of adaptability with the javascript framework.</p><h3>LOOK AT WHAT I HAVE CREATED!!</h3><p>Through the world of node.js, I have been able to start working on creating my first RESTful web service. And thanks to node, it’s nowhere near as daunting as I thought it would be.</p><p>REST, Representational State Transfer, is a type of web architecture that uses HTTP protocol. It uses resources where almost every major component is a type of resource. These resources can also be accessed by using HTTP standard methods (Get, Head, Put, Post, and Delete).</p><pre>Get: This is used to find or fetch a particular resource. They should only be used to retrieve data.</pre><pre>Head: Head is basically the same thing as get, but the only difference is that the server MUST NOT return a message-body in the response.</pre><pre>Put: Put is where you update an existing resource. You do this by replacing it with a new representation of the resource. Basically like an overwrite. I read that you technically can use put to insert new resources (i.e. Post), but it isn’t a good practice to get into for the most part.</pre><pre>Post: Post is used to create new resources. Here you need to create a new, unique id for each resource.</pre><pre>Delete: Sending that godless abomination you call a resource to darkest trenches of Tartarus…it seemed pretty self-explanatory by the name.</pre><h3>Is that an NPM in your API or are you just..okay that got weird…</h3><p>So one other thing I learned about node is that it originally wasn’t made for creating websites, but was originally made for handling server tasks, so it requires additional libraries. This is where the NPM comes in to play. NPM is a fantastic command-line interface used to manage different node.js libraries. One great feature is</p><pre>npm init</pre><p>This feature creates a JSON file for you after a couple inquiries about what exactly you are trying to make and have done. It will then write a package.json file with what you have selected. Make sure that when you are writing your api that you use the ‘require’ function to list the various packages, aka dependencies, you will need to use that will be required for production.</p><p>In order to begin our server, we must declare and launch a built-in http module.</p><pre>var http = require(‘http’);</pre><p>After that, we need use the built-in command ‘createServer’ to listen on a port:</p><p>http.createServer(onRequest).listen(8080);</p><p>In order for the event listener function to work, we must define it . Basically the callback function will listen for someone to visit the port on my local host. So we define the function with the parameters ‘request’ and ‘response’. When someone issues a request, the server will respond. When they do, clearly we need something to respond with. In order to do this, we use ‘response.writeHead’. What this basically does is gives a type of context code that gives an idea of what will actually be in the response. After that comes the response using ‘response.write’. you finish the response by using the command response.end. In all, it looks like the following:</p><pre>var http = require(‘http’);</pre><pre>function onRequest(request, response) {</pre><pre>response.writeHead(200, {“Context-Type”: “text/plain”});</pre><pre>response.write(“Here is some data.”);</pre><pre>response.end();</pre><pre>}</pre><pre>http.createServer(onRequest).listen(8080);</pre><p>After this, we needed to install some different packages from npm (node package manager). We installed ‘router’ and ‘firsthandler’. Once installed using ‘npm install’, we implemented them using the same declaration and initiation as http. To make it look a little cleaner, we used chain method to put the variables together. Also included is our ‘products’ JSON file where our array of objects will be placed, and we also have a separate js file to keep our higher order functions and algorithms that will be implemented during the building of the web server.</p><pre>var <br> products = require(‘./data/product.json’),<br> util = require(‘./js/util’),<br> http = require(‘http’),<br> finalhandler = require(‘finalhandler’),<br> Router = require(‘router’);</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef24a802f67c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>