<?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 Adames H. on Medium]]></title>
        <description><![CDATA[Stories by Adames H. on Medium]]></description>
        <link>https://medium.com/@adames?source=rss-423a21f3d302------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*JYRFpQaWnL_4ZMvW.jpg</url>
            <title>Stories by Adames H. on Medium</title>
            <link>https://medium.com/@adames?source=rss-423a21f3d302------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 06:19:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@adames/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[Generating Unique IDs]]></title>
            <link>https://medium.com/@adames/generating-unique-ids-4c18dcf26a79?source=rss-423a21f3d302------2</link>
            <guid isPermaLink="false">https://medium.com/p/4c18dcf26a79</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[uuid]]></category>
            <category><![CDATA[bitwise-operator]]></category>
            <dc:creator><![CDATA[Adames H.]]></dc:creator>
            <pubDate>Fri, 16 Feb 2018 23:18:33 GMT</pubDate>
            <atom:updated>2018-04-04T04:15:01.677Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*llLwfrkZKGAwVKjtR9HFJA.jpeg" /></figure><p>I recently found the need to generate universally unique identifier (IDs used to uniquely identify data) for a project at work, and found myself knee deep in unfamiliar material: blog post time! Let’s walk through one ferocious implementation I found online.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e72b8b8fea5294862556975b3ad79b2/href">https://medium.com/media/4e72b8b8fea5294862556975b3ad79b2/href</a></iframe><p>The first half of our function uses time to add additional randomness to our pseudo-random number generator. The second half generates random hex values based on our numbers. But before we break down how each line accomplishes this, let’s learn a bit about what UUIDs are.</p><p><strong>UUIDs</strong></p><p>Universally unique identifier (<em>UUID a.k.a. GUID</em>) a is a 128-bit number that can be used to identify unique items online. A 128-bit number can hold a lot of data: 340,282,366,920,938,463,463,374,607,431,768,211,455 (3.4 * 10³⁸) ones and zeroes. Counting by tens takes a lot of characters (39). We can cut it down to 32 characters if we just count by 16s (hexadecimal <em>a.k.a</em> hex) instead of by 10s (decimals). Hexadecimals accomplish 16 digits before starting over by using 16 possible characters: ‘0’ through ‘9’ and ‘A’ through ‘F’. Hexadecimals are used everywhere — even in this blog post’s URL! But you’re not here for the math! Let’s summarize:</p><ul><li>Hexadecimal (<em>base 16</em>): 16^³² = 128-bits</li><li>Decimal (<em>base 10</em>): 3.4 * 10³⁸ = 128-bits</li><li>2¹²⁸ (<em>base 2</em>): 2¹²⁸ = 128-bits</li></ul><p>Whew. I’m eager to talk code, but there’s one more thing about UUIDs I must mention before we continue: they are a standard. An all volunteer group called the Internet Engineering Task Force (<em>IETF</em>) came up with a standard for IDs called <a href="http://www.ietf.org/rfc/rfc4122.txt">RFC 4122</a>. The format looks like so:</p><p>xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx</p><p>That 4 is strange, right? It’s part of the standard. It means these numbers are generated from <a href="https://en.wikipedia.org/wiki/Pseudorandomness">pseudo-random</a> numbers. Version 1: generates a unique ID based on a network card MAC address and a timer. This version is intended to be unique, but is not secure. Version 3: generates a unique ID from an <a href="https://en.wikipedia.org/wiki/MD5">MD5</a> hash of a namespace and name. Version 5: generates a unique ID from a <a href="https://en.wikipedia.org/wiki/SHA-1">SHA-1</a> hash of a namespace and name.</p><p><strong>Lines 2</strong></p><p>let time = new Date().getTime();</p><p>Javascript’s Date object holds time based on Unix time, or the amount of seconds since 00:00:00 UTC on January 1st, 1970 (minus a leap second here and there). The getTime method simply displays current Unix time. <em>Factoid</em>: if you type date +%s into your terminal you’ll also see current Unix time.</p><p><strong>Line 3–5</strong></p><p>if ( performance &amp;&amp; typeof performance.now === &#39;function&#39; ){<br> time += performance.now();<br>}</p><p>The performance.now() function returns the time that has elapsed since the web page loaded with accuracy between a millisecond and five thousandths of a millisecond. The gap in accuracy is due constraints in the computer. And that is how the first half of our UUID generator functions.</p><p><strong>Line 6</strong></p><p>&#39;xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx&#39;.replace(/[xy]/g, function)</p><p>Let’s break down the second half of our function: the generator mechanism. We start with a string with the UUID format you see above, but we perform a Javascript String method called <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace">replace</a> to substitute the x and y characters using a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions">regular expression</a>. With our second and final replace argument we unveil the superstar of our function.</p><p>function (c) {<br> let random = ( time + Math.random() * 16 ) % 16 | 0;<br> time = Math.floor( time / 16 );<br> return ( c === &#39;x&#39; ? random: ( random &amp; 0x3 | 0x8)).toString( 16 );<br>}</p><p>If you’re unfamiliar with Math.random, it returns a <em>psuedo-</em>random number between 0 and nearly 1. Pseudo-random number generation is not truly random! Its randomness is also determined by the current time. We’re going to do the same, and by doing so we defend ourselves from <a href="https://en.wikipedia.org/wiki/Rainbow_table">rainbow table attacks</a>. We multiply our pseudo-random value by 16, then add our time calculation (integer time&gt; 1,500,000,000). Finally, we use the <a href="https://medium.com/@adames/super-modulo-37669627108">modulo</a> operator to get the remainder after dividing the number by 16 (getting a number between 0–16).</p><p><strong>Line 7</strong></p><p>let random = ( time + Math.random() * 16 ) % 16 | 0</p><p>So we end up with a decimal between 0 and 15. But what’s that strange looking pipe (|) between the 16 and our semicolon? It’s a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators">bitwise operator</a>! Remember our old friend hex? It’s back with cryptographic vengeance. But first, a refresher on names for data:</p><ul><li>1 bit is the smallest unit of information (can be 0 or 1)</li><li>4 bits = hex</li><li>8 bits = 1 byte</li></ul><p>A hex has 16 possible values. Why isn’t it 2 possible numbers times 4 different locations resulting in 8 pieces of information? Because there are 16 possible <em>combinations</em> of 1s and 0s when you have 4 units to fill, making it 2⁴ instead of 2 * 4.</p><p>But back to the bitwise operator. Bitwise operations are just like <a href="https://en.wikipedia.org/wiki/Boolean_data_type">boolean</a> operations, only you compare two series of 1s and 0s.</p><p>1 OR 1 = 1<br>1 OR 0 = 1<br>0 OR 0 = 0<br>1 AND 1 = 1<br>1 AND 0 = 0<br>0 AND 0 = 0</p><p>So if you have a hex bitwise operation, it will look like this:</p><p>1011 <br><a href="http://underline">0000 OR</a><br>1011</p><p>We’ve got a decimal between 0–15 that needs to be turned into an integer between 0–15. We could just round it, but then we have to call Math, which imports a library, then performs a function depending on arguments… Using the bitwise operator OR (|), we can ensure we get a bit-friendly integer as a result.</p><p>Now that we’ve replaced a single x in our UUID, it’s time to change our time variable to hide its origin.</p><p><strong>Line 8</strong></p><p>time = Math.floor( time / 16 )</p><p>You’re probably wondering why we use Math.floor instead of just the bitwise OR operation, like the line above it. The bitwise OR results begin to diverge from the Math.floor() due to something called the Year 2038 problem. Sometime in the year 2038, Unix time will hit 2³¹– 1 (the maximum value 32 bits can hold), which causes the date to wrap around and become stored internally as a negative number, which these systems will interpret as having occurred on 13 December 1901 rather than 19 January 2038. It then begins to count backward toward 0.</p><p><strong>Line 9</strong></p><p>Now, for our grand finale:<br>return ( c === &#39;x&#39; ? random: ( random &amp; 0x3 | 0x8 )).toString( 16 )</p><p>We’ve got a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator">ternary</a> operation that converts our random number into a hex number using the .toString(16) method, the argument in the toString method informing us of which radix (base of numeration) we want to use. Hexadecimals use 16. There is only one character that will hit the second half of our ternary: y. In Javascript, we prepend the hex number with 0x to indicate that the number is in base 16. For example:</p><p><em>Decimal /Hex</em><br>1 = 0x1 <br>2 = 0x2 <br>10 = 0xA <br>11 = 0xB</p><p>Our y character is AND bitwise operated against to 0x3 (hex-3/ 0011 binary) then OR bitwise operated against 0x8(hex-8/1000 binary). This makes the y character especially random.</p><p>Now stand back and smile; you’ve just generated yourself a UUID!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4c18dcf26a79" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Concise Quicksort]]></title>
            <link>https://medium.com/@adames/quicksort-partition-and-method-methods-f904417af5ee?source=rss-423a21f3d302------2</link>
            <guid isPermaLink="false">https://medium.com/p/f904417af5ee</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Adames H.]]></dc:creator>
            <pubDate>Mon, 16 Oct 2017 17:29:30 GMT</pubDate>
            <atom:updated>2017-10-19T14:16:47.811Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*YWHxUHtqVqcGciFbqVcopw.png" /></figure><p>While preparing for interviews, decided it would be wise to learn how to sort arrays quickly in Ruby, and boy did I find what I was looking for.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80cd8a94a9161e8f57ef3f40bcf00a84/href">https://medium.com/media/80cd8a94a9161e8f57ef3f40bcf00a84/href</a></iframe><p>If you are a beginner like me, you’ll find this tiny function is dense. The act of unpacking the code was an adventure so educational, I decided to write a post seven times longer than the quicksort method the post is about.</p><p><strong>Line 1..2</strong></p><p>class Array<br> def quicksort</p><p>First, we’re editing the Array class. This is called monkey-patching (likely derived from “guerrilla patch” or sneakily changing code). It means we’re extending the original system software locally. And since we’re editing the Array class, the Array methods we use like partition, size, empty, and delete_at apply to the instance of Array we call quicksort on, decluttering our method.</p><p><strong>Line 3..4</strong></p><p>return [] if empty?<br>pivot = delete_at(rand(size))</p><p>This method is recursive and will stop calling itself when it receives an empty array. The return of the empty array on this line begins the process of returning all values back “up” the stack. Next, we pull one element off our array and assign it to pivot, which we will eventually use to anchor that element’s place in the array, placing all values higher on one side, and lower on the other.</p><p><strong>Line 5</strong></p><p>left, right = partition(&amp;pivot.method(:&gt;))</p><p>Now comes the tricky part: we split the remaining array into two arrays with all the items less than the pivot on the left, and the rest on the right. Before we get to the fancy arguments, let’s breakdown the partition method.</p><p>left, right = partition()</p><p>Below, you’ll find I built my own version of the partition to better understand how it works.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20158749bd5810a428f6fcae041f4a35/href">https://medium.com/media/20158749bd5810a428f6fcae041f4a35/href</a></iframe><p>It walks through an array, swapping any element less than or equal to the pivot with the j value. After each swap, the j value increments, which makes it a bit like a wall separating less-than and greater-than values. Ruby’s partition is fancier and more dynamic than mine, allowing you to pass in any block instead of just the less-than-or-equal-to operator (partition.rb:line 5). Which brings us to the most interesting section of our little quicksort.</p><p>&amp;pivot.method(:&gt;)</p><p>The method method turns the greater-than (&gt;) method into a lambda. This lets you pass the method around with one of the arguments being the item you called the method on. Let’s say you want to pass the method Math.sqrt around. Simply assign square_root = Math.method(:sqrt) to a function and you can use it as an argument in a method. If you apply the method method on an expression like 0.method(:&gt;), it will also include the 0 as the first argument in the method.</p><p>negative = 0.method(:&gt;)<br>=&gt; #&lt;Method: Fixnum#&gt;&gt;</p><p>negative.call(-5)<br>=&gt; true</p><p>negative.call(3)<br>=&gt; false</p><p>The &amp; syntax turns the lambda into a block. Using our square_root variable in the example above, we can apply the lambda to an array like so:</p><p>[9, 16, 25].map(&amp;square_root)<br>=&gt; [3.0, 4.0, 5.0]</p><p><strong>Line 6</strong></p><p>return *left.quicksort, pivot, *right.quicksort</p><p>The splat operator (*) deconstructs all the arrays as they unpack back up the recursed stack, like the.flatten method. If you do not use a splat operator, your solution will look like this:</p><p>[3, 1, 2].quicksort_without_splat_return<br>=&gt; [[[[], 1, []], 2, []], 3, []]</p><p>The brackets were included in the return because when the recursed function begins to wind back up the stack, the balanced, nested array is split by the integer pivot return values.</p><p>[[[[], 1, []], 2, []], 3, []] == [1, 2, 3]<br>=&gt; false</p><p>The splat operator deconstructs the empty brackets as they are returned.</p><p>[*[*[*[], 1, *[]], 2, *[]], 3, *[]] == [1, 2, 3]<br>=&gt; true</p><p>And that is a breakdown of the coolest quicksort method I have found yet.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f904417af5ee" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Super Modulo]]></title>
            <link>https://medium.com/@adames/super-modulo-37669627108?source=rss-423a21f3d302------2</link>
            <guid isPermaLink="false">https://medium.com/p/37669627108</guid>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Adames H.]]></dc:creator>
            <pubDate>Mon, 25 Sep 2017 02:50:33 GMT</pubDate>
            <atom:updated>2017-09-25T02:50:33.543Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*1IhDKV1Ndf0SOn29y5Te2w.png" /><figcaption>Working with 12 hour time? Why not modulo?</figcaption></figure><p>The modulo (%) operator is definitely my favorite operator. New coders should become comfortable with the action. For those unaware, the modulo operator is is similar to the division operator, only it returns the remainder. <br>5 % 3 = 1<br>5 % 11 = 5<br>101 % 2 = 1</p><p>OK, Adames, so what’s the big deal?</p><p>Want to equally divvy up actions to different items in an array?<br>for i in infinity { array[i % array.length] }</p><p>Want to navigate columns in a grid? <br>column = cell number % number_of_columns</p><p>Want to check if an International Bank Account Number (IBAN) is legit? <br>IBAN % 97 == 1</p><p>OK, that last one is a <a href="https://en.wikipedia.org/wiki/International_Bank_Account_Number#Modulo_operation_on_IBAN">little more complicated</a> than I’ve described, but cool nonetheless. So get out there and use that modulo!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37669627108" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple MediaWiki API calls]]></title>
            <link>https://medium.com/@adames/simple-mediawiki-api-calls-9292b17afb0?source=rss-423a21f3d302------2</link>
            <guid isPermaLink="false">https://medium.com/p/9292b17afb0</guid>
            <category><![CDATA[wikipedia]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <dc:creator><![CDATA[Adames H.]]></dc:creator>
            <pubDate>Sun, 10 Sep 2017 23:53:32 GMT</pubDate>
            <atom:updated>2017-09-10T23:53:32.882Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Rn1jZ_64INMFDl91inJRA.png" /></figure><p>Jumping into the MediaWiki action API as a beginner is not an easy task. It is difficult to understand the shape of the data they serve to you, and difficult to understand how to ask the right questions.</p><p>Let’s start by reviewing how Wikipedia is shaped. Above all the articles is WikiData: a taxonomy of data. Here I hope to prevent you from making the first false assumption I made: the relationships are much more web-like than tree-like. The relationships were made the same way information was added to Wikipedia and follow no pre-ordained order. The Wikidata Graph builder illustrates this best, so take a second to check out <a href="https://angryloki.github.io/wikidata-graph-builder/?property=P279&amp;item=Q5">the parent classes of human</a>. This should help you when you attempt to find related items and search hierarchically (not an effective search method with this data in my opinion).</p><p>The API sends Wikipedia (the encyclopedia) information in wikitext format (their custom editing language) by default, and in HTML. You can also use one of their extensions to parse the information for you. I’ll add a few example calls here and explain the confusing parts. For beginners it’s worth mentioning that the question mark marks the beginning of the parameters you want to pass, the ampersands separate different the parameters, and the pipe character allows for multiple requests of the same parameter.</p><p>Getting Raw HTML</p><p><a href="https://en.wikipedia.org/w/api.php?action=parse&amp;page=Albert_Einstein&amp;prop=text&amp;format=json">https://en.wikipedia.org/w/api.php? action=parse &amp; page=Albert_Einstein &amp; prop=text &amp; format=json</a></p><p>Above is a useful call. Asking Wikipedia to use their parsing service to return HTML the same way it is displayed on their website. I used this call in addition to the Ruby gem Nokogiri to pull the exact HTML tags I desired, allowing me to be very selective about the information I received.</p><p>Using Extensions for Plain Text</p><p><a href="http://en.wikipedia.org/w/api.php?titles=Albert_Einstein|Ancient_Rome&amp;action=query&amp;format=json&amp;prop=pageimages|extracts&amp;pithumbsize=1000&amp;exchars=500&amp;exlimit=20&amp;explaintext&amp;exintro">http://en.wikipedia.org/w/api.php? titles=Albert_Einstein|Ancient_Rome &amp; action=query &amp; format=json &amp; prop=pageimages|extracts &amp; pithumbsize=100 &amp; exchars=500 &amp; exlimit=20 &amp; explaintext &amp; exintro</a></p><p>Using this call, your action is a query of two articles, Albert Einstein and Ancient Rome. I’ve asked for the information in JSON, and the properties are pictures and extracts (parsed plain text). Both pageimages and extracts are extensions that were not built by Wikipedia.</p><p>Searching Wikipedia</p><p><a href="https://en.wikipedia.org/w/api.php?search=Albert_Einstein&amp;action=opensearch&amp;profile=fuzzy&amp;format=json&amp;limit=10&amp;namespace=0&amp;redirect=resolve">https://en.wikipedia.org/w/api.php? search=Albert_Einstein &amp; action=opensearch &amp; profile=fuzzy &amp; format=json &amp; limit=10 &amp; namespace=0 &amp; redirect=resolve</a></p><p>This is a search call that returns items in the 0-namespace. Don’t know what namespace is? Neither did I before this search. It’s just a category of information. <a href="https://en.wikipedia.org/wiki/Wikipedia:Namespace">Wikipedia items in the zero namespace are content</a>. Another interesting parameter: fuzzy. A fuzzy search allows for typos because it searches within a degree of truth. For this API, it’s within two typos. Opensearch used to be an extension, but was eventually added to the core MediaWiki API.</p><p>Hope that helps!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9292b17afb0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A* search for solving 8 puzzles]]></title>
            <link>https://medium.com/@adames/a-search-for-solving-8-puzzles-b86136f02b30?source=rss-423a21f3d302------2</link>
            <guid isPermaLink="false">https://medium.com/p/b86136f02b30</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[puzzle]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Adames H.]]></dc:creator>
            <pubDate>Wed, 16 Aug 2017 11:01:01 GMT</pubDate>
            <atom:updated>2017-09-11T00:02:03.615Z</atom:updated>
            <content:encoded><![CDATA[<p>Building an 8-puzzle is easy. Finding its solution is tougher. An 8 puzzle is a sliding puzzle on a 3 x 3 grid of tiles with one missing. The others are scrambled by sliding tiles into the blank space.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*Lbk0W1nIr9rfY9z_piKaOQ.png" /><figcaption>8 puzzles in scrambled and solved states, respectively</figcaption></figure><p>I decided that in order to find a solution, I had to try a <a href="https://en.wikipedia.org/wiki/Breadth-first_search">breadth-first search</a>.</p><ol><li>look at next possible moves</li><li>check for a solution</li><li>no solution?</li><li>look through possible moves for solutions, starting with the move closest to the first move</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/803/1*i2QsrAc5SK6ssEB1J8qc-A.jpeg" /></figure><p>Empirically I proved that finding solutions took longer than my capacity to tolerate delay before I lost my cool. To improve the search I added a <a href="https://en.wikipedia.org/wiki/Heuristic_(computer_science)">heuristic</a>, or a smarter method of choosing which move was best.</p><p>To do this we sum all the steps away each tile is from where it belongs. In taxicab geometry (I swear that is a <a href="https://en.wikipedia.org/wiki/Taxicab_geometry">real branch of mathematics</a>), there is a concept of a manhattan distance or the distance between two points on a grid. We can use this to underestimate how many moves we are from a whole solution.</p><p>We add our heuristic to our search and we’ve got ourselves an <a href="https://en.wikipedia.org/wiki/A*_search_algorithm">A* search algorithm</a>:</p><ol><li>check to see if your leaf is the solution (I know, right?)</li><li>if it’s not the solution, collect all the connected leaves</li><li>put the leaves in a basket</li><li>pick the best leaf from the basket using our heuristic</li><li>then return our last leaf to the tree and don’t pick it again</li></ol><p>And with that change, my solutions survived my patience. Check the code below if you’re interested in the details.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8aef5d3434834b9537a42b87eab7633c/href">https://medium.com/media/8aef5d3434834b9537a42b87eab7633c/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b86136f02b30" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handling Blobs in Javascript]]></title>
            <link>https://medium.com/@adames/handling-blobs-in-javascript-e857771e776a?source=rss-423a21f3d302------2</link>
            <guid isPermaLink="false">https://medium.com/p/e857771e776a</guid>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[beginner-javascript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[developer]]></category>
            <dc:creator><![CDATA[Adames H.]]></dc:creator>
            <pubDate>Mon, 31 Jul 2017 18:44:34 GMT</pubDate>
            <atom:updated>2017-09-10T23:05:58.005Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*NGfCpAw8hT5FJ9xzUl6z3Q.png" /><figcaption>This is what a PNG blob looks like (fig. 1)</figcaption></figure><p>While working with the Google Static Maps API, I stumbled upon the obstacle of handling blobs in their API response. <a href="https://en.wikipedia.org/wiki/Binary_large_object"><strong>Binary Large OBject</strong> (<strong>BLOB</strong>)</a> is a collection of binary data stored as a chunk of bytes that represents a file. It does not have a reference to an actual file, but it does have a specific size and MIME type just like a file has (MIME type is a way of identifying files on the Internet according to their nature and format).</p><p>If you made an API call, you probably have a blob somewhere in your promise. Thats a good thing! Javascript’s fetch call has .blob method just for this. You can also use Javascript’s XMLHttpRequest call by changing thexhr.responseType = &#39;blob&#39;;. You CANNOT handle blobs this easily using jQuery’s AJAX calls.</p><p>Great, now you have a blob object that you can store easily. If displaying the object is your goal, I’ve got a few more steps for you. Javascript has great library called <a href="https://developer.mozilla.org/en-US/docs/Web/API/URL/URL">URL</a> that allows you to turn blobs into url sources on HTML &lt;img&gt;tags. We can do that by calling the URL.createObjectURL(blob) method on the responses. After, simply set an image source to the URL return of the method.</p><p>Congratulations, you’ve decoded a blob!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e857771e776a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple form_for]]></title>
            <link>https://medium.com/@adames/simple-form-for-65e3463cf21?source=rss-423a21f3d302------2</link>
            <guid isPermaLink="false">https://medium.com/p/65e3463cf21</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[pokemon]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <dc:creator><![CDATA[Adames H.]]></dc:creator>
            <pubDate>Tue, 11 Jul 2017 11:45:11 GMT</pubDate>
            <atom:updated>2017-09-10T23:03:45.389Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XaxVg02aAOws8l5hu6yTUg.png" /></figure><p>Moving from Ruby to Ruby on Rails reminds me of that scene in Transformers when Shia Labeouf first realizes his Chevrolet Camaro is actually a giant robot trying to save the world. The powerful and intelligent alien is destroying my well-kept yard. Let’s walk through the most simple uses for this method and keep your garden intact.</p><p>For the newbies: forms are input on webpages, like sign in forms. Ruby has a method that called form_for that generates HTML form tags for you. As input, it takes in a template of the model you are creating a form_for. More jargon! OK, a model is the conceptual model for an item you want to work with in computer science. For example, if you have users, you will want a user model to pass around and reference. Models have attributes, like a user might in the real world: a name, an email, or maybe an address. See the picture above for an example.</p><p>Let’s say you want to create a new Pokemon.</p><p><em>pokemons_controller#new</em></p><p>@pokemon = Pokemon.new</p><p><em>pokemon/new.html.erb</em></p><p>&lt;%= form_for @pokemon do |f| %&gt;</p><p>No need to give this @pokemon a type or any other attribute, form_for uses the empty template (Pokemon.new) to make its form. It also generates an authenticity token, html tag ids (like &lt;div id=pikachu &gt;) and html tag names. Authenticity tokens prevents forgery on your site. The body of the form requires the attributes you would like to set and the field type for each attribute.</p><p>&lt;%= f.text_field :name %&gt;</p><p>&lt;%= f.text_area :pokedex_description %&gt;</p><p>There are many types of fields form_for supports, from password_fields to url_field.</p><p>The dynamic nature of form_for also means that it can be used to edit an object (one of your pokemon) by providing an object already saved in ActiveRecord (our pokedex).</p><p><em>pokemons_controller#edit</em></p><p>@pokemon = Pokemon.find(<em>existing pokemon</em>)</p><p>If the object already exists, form_for will add default values, button names, html class tags that reflect the existing object. More importantly, it will indicate that the method of the form is a patch instead of a post.</p><p>Lastly, the parameters passed to you will require strong parameters. If you receive a ActiveModel::ForbiddenAttribute exception, it only means you must tweek your .require(<em>and</em>).permit(<em>statements</em>).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65e3463cf21" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The new developer blog]]></title>
            <link>https://medium.com/@adames/technically-emotional-3f5cab5e51f?source=rss-423a21f3d302------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f5cab5e51f</guid>
            <category><![CDATA[product-management]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[emotional-intelligence]]></category>
            <dc:creator><![CDATA[Adames H.]]></dc:creator>
            <pubDate>Wed, 14 Jun 2017 05:47:56 GMT</pubDate>
            <atom:updated>2017-09-16T21:34:02.678Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1hZhpiGDgClKdBreodkqIQ.jpeg" /></figure><p>Five years ago, I moved to New York City for work. I found a small startup to settle into, and was warmly welcomed by the team. Although I spoke a different language, most were accommodating in their communication with me. I immersed myself in the culture, but the language barrier persisted. This summer I decided enough was enough: let’s learn a language — let’s become technical.</p><p>Tech companies generally prefer to encapsulate technical knowledge in highly effective people that work like APIs — black boxes of engineering and technical know-how. I used to attend “tech talks,” but the presentations were often abstract or full of technical jargon. After a few talks, I realized my time was best spent elsewhere. If the company were a school, I would have dropped out of that class.</p><p>Only my disinterest was related to the way the information was communicated. Today, I’m knee-deep in the same concepts I felt lost listening to only last year. I fancy myself a communicator, and plan to write about technical ideas the way I wish they were explained to me while I was a product manager. Stay tuned.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3f5cab5e51f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>