<?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 Patrick Abejar on Medium]]></title>
        <description><![CDATA[Stories by Patrick Abejar on Medium]]></description>
        <link>https://medium.com/@wireless.patrick?source=rss-b1eb97dc7c8d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*kUFiFk43OwWoOaP_DPOKqQ.jpeg</url>
            <title>Stories by Patrick Abejar on Medium</title>
            <link>https://medium.com/@wireless.patrick?source=rss-b1eb97dc7c8d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 06:52:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wireless.patrick/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[I Ripped AWS Cognito Out of My App and Everything Got Better]]></title>
            <link>https://medium.com/@wireless.patrick/i-ripped-aws-cognito-out-of-my-app-and-everything-got-better-7d79bab4994d?source=rss-b1eb97dc7c8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7d79bab4994d</guid>
            <dc:creator><![CDATA[Patrick Abejar]]></dc:creator>
            <pubDate>Wed, 24 Jun 2026 04:42:52 GMT</pubDate>
            <atom:updated>2026-06-24T04:42:52.687Z</atom:updated>
            <content:encoded><![CDATA[<p>The auth requirement was one sentence: let me sign in with Google, read my email, check it against an allowlist. Three things. That was the whole feature.</p><p>I reached for Cognito because it’s the AWS-shaped answer and I didn’t think about it hard enough. The setup was a user pool, the hosted UI, Google wired in as a social IdP, and a Lambda that validated the Cognito-issued JWT and compared the email against a hardcoded list. And to be fair: it worked. For a while I had no complaints.</p><p>Then I wanted the Google account chooser. This is the screen that asks <em>which</em> account when you’re signed into three of them. That’s prompt=select_account on the authorize call. One parameter. Every OAuth doc on earth mentions it.</p><p>I added it to the Cognito authorize URL. Nothing changed. It kept silently auto-picking whatever account the browser was already holding.</p><p>So I went and read the actual redirects. Turns out Cognito takes your /authorize, and when it builds <em>its own</em> request to Google, it doesn&#39;t carry your prompt along. It mints a fresh authorize request upstream with the params it feels like sending, and yours aren&#39;t on the list. No error. No log line. No note in the docs saying &quot;we drop this.&quot; You find out by diffing redirect headers in the network tab like it&#39;s 2009.</p><p>That’s the part that got me. The feature isn’t missing from Google. Google’s supported it for a decade. It’s that Cognito sits in the middle, eats the parameter, and says nothing. You can’t pass it through the front, and there’s no escape hatch to inject it on the side either. Both doors closed, no sign on either one.</p><h3>Pulling it out</h3><p>I dropped in Google Identity Services. Now the browser talks to Google directly and renders Google’s own button, which has the chooser built in, because it’s Google’s button and Google knows how its own product works. The page gets back an ID token. The Lambda verifies that token against Google’s JWKS, checks iss and aud, pulls the email, checks the list. The verification code barely moved; a signed JWT is a signed JWT no matter who minted it.</p><p>No client secret in the browser. No hosted UI to theme. No second user directory pretending to manage users for an app whose entire user model is a comma-separated list. The thing I fought for an afternoon took about twenty minutes once Cognito wasn’t in the path.</p><h3>The actual gripe</h3><p>I’m sure Cognito earns its keep when you genuinely need the parts — a real directory, MFA, a branded hosted page, token lifecycle, all of it. I didn’t need any of that. I needed three verbs and a list, and for that it was a tax I was paying to make Google work <em>worse</em>. The annoying part wasn’t the missing feature. It was burning an afternoon to discover the abstraction had quietly decided what I was allowed to send Google, and hadn’t bothered to mention it.</p><p>If AWS had a reviews page I’d give it the engineer’s two stars: works fine, right up until you ask it to do the one thing you came for.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7d79bab4994d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Dumbest Dumb Dumbed Down Code Along to Start WebRTC]]></title>
            <link>https://medium.com/@wireless.patrick/the-dumbest-dumb-dumbed-down-code-along-to-start-webrtc-ec66106d414b?source=rss-b1eb97dc7c8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ec66106d414b</guid>
            <category><![CDATA[software]]></category>
            <category><![CDATA[webrtc]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Patrick Abejar]]></dc:creator>
            <pubDate>Tue, 05 Mar 2019 14:43:00 GMT</pubDate>
            <atom:updated>2019-03-05T17:46:25.625Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gBzF6MOMj0bWdVteWC8GFQ.png" /></figure><p><strong><em>Disclaimer: We’re not even building a full-fledged app, but you’ll still be using the very basics of WebRTC allowing you to further your understanding. This post is designed to remove the intimidation WebRTC brings by just jumping into implementing the technology without being too concerned about other associated technologies.</em></strong></p><p>In your quest to create some of the most interactive apps, you probably stumbled across several different technologies to improve interactivity in “real time” such as through ActionCable, WebSockets, and others. You may have even stumbled upon a powerful and impressive technology called WebRTC. It’s a fast way of communicating directly with others. It throws out the middleman in exchange for faster speed and added privacy.</p><p>However, implementing WebRTC in your app is no easy task. This post aims to get you familiar with WebRTC at a very minimal level. WebRTC can be implemented in an infinite amount of apps and this post is designed to get you to start playing with WebRTC rather than creating a full-fledged frontend application.</p><p>Let’s create a very crude WebRTC chat app in the browser console. The latest version of <strong>Google Chrome </strong>is compatible with this code-along.</p><h3>High Level Description of WebRTC Setup</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mibguG51iYRPsftLJTg0Yg.png" /><figcaption>Each RTCPeerConnection needs to be described with an offer, answer, and candidates in order to open the data channel where RTC communications may take place.</figcaption></figure><p>We are trying to <strong>decorate</strong> an RTCPeerConnection on <strong>BOTH</strong> peers with information about the data to be exchanged and the network each peer is located in. An RTCPeerConnection helps us create a data channel between any two peers and opens that data channel.</p><p>We decorate each RTCPeerConnection with offers, answers, and ice candidates. Below each of the three lists methods of RTCPeerConnection we use to add information about the offer, answer, or ice candidate to the RTCPeerConnection.</p><ul><li><strong>OFFER: </strong>describes data to be exchanged and the address of the initiator</li></ul><pre><strong>OFFER RTCPeerConnection methods<br> .addLocalDescription()</strong> if offer was produced by current browser<br> <strong>.addRemoteDescription()</strong> if offer was produced by other browser</pre><ul><li><strong>ANSWER: </strong>describes data to be exchanged and the address of the receiver</li></ul><pre><strong>ANSWER RTCPeerConnection methods<br> .addLocalDescription()</strong> if answer was produced by current browser<br> <strong>.addRemoteDescription()</strong> if answer was produced by other browser</pre><ul><li><strong>ICE CANDIDATE: </strong>indicates possible directions on how to get to the peer</li></ul><pre><strong>ICE CANDIDATE RTCPeerConnection methods<br> .addIceCandidate()</strong> regardless of where candidate was produced</pre><p>When we have added a sufficient amount of information our RTCPeerConnection opens the data channel and we may send data across it.</p><p><strong>A metaphor</strong>: Feed the RTCPeerConnection with offers, answers, and candidates so that it may grow and open up a RTCDataChannel.</p><h3><strong>BUILD IT — Code-Along</strong></h3><p><strong>1 | Open two browsers consoles on the same computer or different computers.</strong></p><p><strong>2 | Copy the following setup code into BOTH browser consoles.</strong> This code creates an RTC data channel for peer-to-peer communication. Right now it’s closed, but when we fulfill two conditions it will be ready for use! RTCPeerConnection helps this set up. Run this on both browsers!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90fa1c532a5bb439468e55d9e1083ea2/href">https://medium.com/media/90fa1c532a5bb439468e55d9e1083ea2/href</a></iframe><p><strong>3 | Choose a browser to start the connection and create that offer.</strong> Copy this code into that browser console. This creates some self-identifying data about this computer that will be added to the RTCPeerConnection in line 3 of <em>minimalOfferCreationWebRTC.js</em>. It will also be logged out into the console so that we may share it with the other peer so they can add it to their RTCPeerConnection object.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/747f465bea834b019db56552aa4900d7/href">https://medium.com/media/747f465bea834b019db56552aa4900d7/href</a></iframe><p>Some ICE candidates will also pop up in the console as well. They have been added automatically in line 6 of <em>mininalSetupWebRTC.js.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FvJ7w72tE4KWMHVShIQ1ZA.jpeg" /></figure><p><strong>4 | Share the offer with the other browser console.</strong> Put the offer logged into the console from the other computer into the arguments for the constructor of RTCSessionDescription and run it in that browser. (There should be a Javascript object in between the two inner parentheses.)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2cce71f5d943c619a5f181dfd3b9cf83/href">https://medium.com/media/2cce71f5d943c619a5f181dfd3b9cf83/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ra7XBBPlmrXXAr648UG-dA.jpeg" /></figure><p><em>How? You can: Copy and paste. Read it out loud to somebody else typing. Send it through iMessage/E-mail/carrier pigeon.</em></p><p><strong>5 | Share the candidate(s) with the other browser console.</strong> For each candidate that was logged to the console in the browser that constructed the offer, copy that Javascript object and place it as an argument of the addIceCandidate function.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1fa3fa0b89e9248e9bcd9f7a339f68d1/href">https://medium.com/media/1fa3fa0b89e9248e9bcd9f7a339f68d1/href</a></iframe><p><em>How again? You can: Copy and paste. Read it out loud to somebody else typing. Send it through iMessage/E-mail/carrier pigeon.</em></p><p><strong>6 | Create the answer in the browser you just added the offer and candidates. </strong>Copy and paste the below answer in the appropriate browser. Note that the answer was added to the RTCPeerConnection. We must do the same for the RTCPeerConnection in the other browser console.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f2959609567b4ea80781edf0dbbff2f7/href">https://medium.com/media/f2959609567b4ea80781edf0dbbff2f7/href</a></iframe><p><strong>7 | Share the answer with the other browser console.</strong> Just like before, we need to add the answer description to the other browser’s console. (This is the one that created the offer.)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2cce71f5d943c619a5f181dfd3b9cf83/href">https://medium.com/media/2cce71f5d943c619a5f181dfd3b9cf83/href</a></iframe><p><strong>8 | Share the candidate(s) with the other browser console. </strong>Just like before, we need to add the candidates to the other browser’s console. <strong>FOR EACH candidate </strong>logged from the answer producing browser, we need to run the below with the candidate Javascript object as the argument to the addIceCandidate function. (This is the one that created the offer to begin with.)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1fa3fa0b89e9248e9bcd9f7a339f68d1/href">https://medium.com/media/1fa3fa0b89e9248e9bcd9f7a339f68d1/href</a></iframe><p>Should everything go correctly, we should have “Data Channel now open” appear on the console.</p><p><strong>STEP 9 | You may now use the .send() method of dataChannel in order to send messages peer-to-peer between both browsers. </strong>This method accepts strings only.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d141a412734b62a2e1e19dda348912b/href">https://medium.com/media/3d141a412734b62a2e1e19dda348912b/href</a></iframe><p>When you run this, ‘successsssss’ will appear in the other WebRTC connected console.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/383/1*afB1izCTGMhHnMbC2rCGxg.png" /><figcaption>The string ‘successsssss’ was successfully sent peer-to-peer to the other browser.</figcaption></figure><p>Congratulations, you have just sent data peer-to-peer!</p><h3>Next to Learn</h3><h4>Learn How — Technologies Powering WebRTC</h4><p>This was a very short blog post designed to get you interested in WebRTC through demonstration. This, by far, is not a complete guide on the many technologies powering WebRTC such as:</p><ul><li>STUN/TURN servers that help produce candidates in order to overcome the complicated structure of private and public networks</li><li>NAT and IPv4 that STUN and TURN try to navigate around</li></ul><h4>Actually Building a User Interface</h4><p>It also is not a guide to constructing a complete front end facing application utilizing WebRTC as all the coding was done in a browser console. With skills in Vanilla Javascript, Angular, React, Vue, or any other web development framework you may incorporate WebRTC into those frameworks. This may be quite difficult for some more than others but your knowledge about offers, answers, and ice candidates will come in handy in this next challenge of yours.</p><h4>Automate our process using a Signaling Server</h4><p>Remember how we had to copy and paste offers, answers, and candidates? Instead, we can use a middleman server to help facilitate the copying/pasting, or dictation of these offers, answers, and candidates. Don’t worry, we won’t need the middleman server when the data channel opens. The most common signaling servers are built using WebSockets with node.</p><p>Or you can stick to this primitive method of exchanging candidates:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*8wu8mTULv6KGXs6gdH-Omw@2x.jpeg" /></figure><h4>Adding Media: Audio and Video</h4><p>WebRTC isn’t limited to strings. We can attach audio and video to it.</p><h3>Disclaimer on STUN/TURN</h3><p>WebRTC peer-to-peer technology. As mentioned in the above disclaimer there are many different technologies involved making the peer-to-peer technology possible. One of the problems that need to be solved with any successfully set up WebRTC peer connection is providing directions from one browser to another, whether they may be on the same computer, different computers but the same network, or distant from one another in different parts of the Internet. As you may have noticed during the setup in step 2, Google provides a free STUN server which helps with creating these directions in the form of candidates. STUN servers may work on the simplest of network topologies but may fail if the directions between two computers are more complex. More extensive TURN servers are needed to help overcome these more complex network traversals. Unfortunately, Google does not provide any free TURN servers.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec66106d414b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript — Where Capturing Bubbles is Mutually Exclusive]]></title>
            <link>https://medium.com/@wireless.patrick/javascript-where-capturing-bubbles-is-mutually-exclusive-b5a389c1c1b?source=rss-b1eb97dc7c8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b5a389c1c1b</guid>
            <category><![CDATA[user-experience]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[html]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Patrick Abejar]]></dc:creator>
            <pubDate>Wed, 21 Nov 2018 22:45:25 GMT</pubDate>
            <atom:updated>2018-11-21T22:45:25.962Z</atom:updated>
            <content:encoded><![CDATA[<h3>JavaScript — Where Capturing Bubbles is Mutually Exclusive</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yrL1RUhv22cQeQhdYmhxIQ.jpeg" /></figure><p>Bubbling and capturing are opposites of one another when referenced in terms of handling JavaScript events. Event bubbling occurs when event listeners of more specific children run their callbacks before larger ancestors. Event capturing occurs when ancestors of the event’s target run their callbacks before children nodes, further in the DOM.</p><h3>Example by Nested Elements</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hApFjd0yWlDf1XWDAVVLpw.png" /><figcaption>Nested divs are shown above. Color styling was done in order to better illustrate the nested hierarchy. The associated HTML and JavaScript are shown in the following GitHub gists.</figcaption></figure><p>Imagine you have the following hierarchy of &lt;div&gt;s on an HTML page. The World is a &lt;div&gt;, North America and Asia are &lt;div&gt;s, the United States, Canada, Mexico, China, Japan, and all the degrees of children are &lt;div&gt;s. Let’s place event listeners on all of these &lt;div&gt;s, which should run a callback that indicates what &lt;div&gt; triggered the event listener. The HTML and the associated JavaScript would be as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38c1f060054939403f6539ceb7130f8c/href">https://medium.com/media/38c1f060054939403f6539ceb7130f8c/href</a></iframe><p>When we click on Long Island, we get the following logs in our console:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*5-1DTzNEfT9RqL5VbrV81A.png" /></figure><p>This shows us that by default, callbacks from children are run prior to callbacks from parents. This behavior is described as event bubbling. However, we can change this behavior to have the parents run their callbacks prior to their respective children.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f5511097664eca9ad78cf16ee5ed33c/href">https://medium.com/media/4f5511097664eca9ad78cf16ee5ed33c/href</a></iframe><p>It turns out that addEventListener() takes in an optional third argument. This argument is a boolean that describes if event capturing should occur (true for event capturing, false for event bubbling). When unspecified, this argument is false. However, let’s change it to true and see what gets logged in our console when we click Long Island again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*724CZ4xEIdTatLdU5C3jmg.png" /></figure><p>Note that the order of events has been reversed when we specify that we want event capturing in our event listeners.</p><h3>stopPropagation()</h3><p>If we wanted to put an end to events bubbling or being captured down the DOM hierarchy, we can call an event’s stopPropagation() method to stop the bubbling or capturing from progressing forward.</p><p>Let’s expand our event listener to include a stop propagation if it reaches the United States &lt;div&gt;.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e356c2b53d7dc35f68e7de18ca546c1c/href">https://medium.com/media/e356c2b53d7dc35f68e7de18ca546c1c/href</a></iframe><p>Once again, let’s click on Long Island to see how far our event is captured.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HLM01tmGhAhGAOj1JxbaPA.png" /></figure><p>Events are being captured up until we get to the United States’ event listener. This is exactly what we expected. The same is logs are outputted when we click on New York City, or anywhere in the United States &lt;div&gt; as events are blocked from being captured past the United States &lt;div&gt;. This behavior also holds true for events being propagated the other way, namely event bubbling.</p><h3>Disclaimer</h3><p>It’s actually bad practice to have so many event listeners on the page due to efficiency reasons. This was done explicitly for this blog in order to illustrate event bubbling and capturing. To construct a more efficient page, we should place an event listener around the most ancestral DOM element for which we want to listen for a specific event.</p><h3>Better Practices: Event Delegation</h3><p>We can place this one event listener on The World &lt;div&gt; for the case illustrated in this blog. Inside the callback for this event listener, we can write conditional logic that runs different code depending on the children triggered.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbcf2bd56b6f33883ac43d3c26ef76bf/href">https://medium.com/media/fbcf2bd56b6f33883ac43d3c26ef76bf/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b5a389c1c1b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reusable Modular Components: The Higher-Order]]></title>
            <link>https://medium.com/@wireless.patrick/reusable-modular-components-the-higher-order-bd0d1ec9e4e8?source=rss-b1eb97dc7c8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd0d1ec9e4e8</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[higher-order-components]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Patrick Abejar]]></dc:creator>
            <pubDate>Mon, 19 Nov 2018 14:46:30 GMT</pubDate>
            <atom:updated>2018-11-19T14:46:30.756Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d6cxZfzmyD2Fit9PVCVwxw.png" /></figure><p>We use components to give a modular and reusable structure to views and their associated logic. Without such structure provided by front-end frameworks such as React, creating views (especially for single-page applications) can become quite tedious. This is due in part to the many considerations of where and when to manipulate the DOM (Document Object Model).</p><p>But what if we can further increase the re-usability of our components through a simple programming pattern supported by Javascript and ReactJS? There is a way! Reusable programming typically encompasses developing code that takes advantage of pure functions, the single responsibility principle, and some form of inheritance (whether that be prototypical in functional programming or object-oriented inheritance in object-oriented programming).</p><p>If we find that we want the same behavior or information shared across components, we can write that behavior into a function that will provide this shared behavior or information to a minimal version of this component in the form of an output. This is the style in which we will write functions that produce higher order components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*8Y4xN4fi2YMaA88cUfD65g.png" /><figcaption>Use higher-order components to increase re-usability.</figcaption></figure><h3>Common Examples: withRouter and connect</h3><p>You may have used higher order components before if you’ve used Redux or React’s client-side browser routing. Redux allows components to easily share a global state among each other. This state can be accessed or modified through the store, which is shared via higher-order components. React-redux’s higher-order component, connect, makes sharing global state possible and seamless. You don’t need to be concerned with the tedious implementations of passing state around.</p><p>React’s client-side routing also takes advantage of higher-order components to share router information such as locations and paths. Applying the function withRouter to a React router application allows components all over the component hierarchy to access the current router props of locations and paths without having to drill props down or lift state up unnecessarily.</p><p>Higher-order component functions like withRouter and connect allow us to pass information to only the components that need them. Prior to using these higher-order components, data needed to transit intermediate components in order to reach the appropriate child or parent. However, higher-order components take away the need to pass non-pertinent data through irrelevant components, allowing these components to maintain a single responsibility and therefore being more reusable.</p><h3>Create Loading Display with HOC</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*pb4xg6b8nzP9Jg3AsK1anw.gif" /></figure><p>Let’s say we have a single-page application that retrieves data from three external APIs, one that provides weather data, another that provides traffic data, and another that provides the top news headlines. Each piece of data will be displayed in their own component on the single-page application. However, we want to let the user know that the data is being retrieved (i.e. using a spinning circle or a status progress bar). Initially, without higher-order components, we can create such an application in ReactJS as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cd9383dbc0e937e5436cb8bac73ad6c4/href">https://medium.com/media/cd9383dbc0e937e5436cb8bac73ad6c4/href</a></iframe><p>Notice that in all the child components of the App component, we are repeating the process of checking if data has been retrieved and displaying that data or a spinning waiting circle if it has not been retrieved.</p><p>In the spirit of being modular, we can place this repetitive functionality in a function. This can be done as so:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f5677a5a3be526ee4dffb8ff51df5cd/href">https://medium.com/media/1f5677a5a3be526ee4dffb8ff51df5cd/href</a></iframe><p>Note that we are taking in a component, using its props and other characteristics and returning another component with those characteristics modified.</p><p>We can then remove this code from the Weather, Traffic, and News components. In the event that we want to change the loading image or message, we only have to modify it in our function that will provide it to the components, rather than modifying all of the components individually.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a004d613534043e6d20bb7ce56ecac07/href">https://medium.com/media/a004d613534043e6d20bb7ce56ecac07/href</a></iframe><p>Remember, we still need to feed our components into the function as follows to be provided with the loading image. This is done through both an import on line 2 of News.js, Traffic.js, and Weather.js along with the export line on line 14.</p><h3>Other Use Cases</h3><p>With all this, our higher-order component is finished! Not only may we share data and logic in this manner, but we can also share any type of behavior such as styling across specific components easily. We can modify props and provide or subtract props. The power of modular re-usability is endless.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd0d1ec9e4e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Trigger Students: SQL Triggers]]></title>
            <link>https://medium.com/@wireless.patrick/how-to-trigger-students-sql-triggers-c527ae9eafa5?source=rss-b1eb97dc7c8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/c527ae9eafa5</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[postgres]]></category>
            <dc:creator><![CDATA[Patrick Abejar]]></dc:creator>
            <pubDate>Sun, 04 Nov 2018 22:56:05 GMT</pubDate>
            <atom:updated>2018-11-05T03:34:38.243Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zga2_LHIhWAi75XnGUSxOg.png" /></figure><blockquote>SQL has more powers than most people know. The set of queried languages go beyond the immediate retrieval and modification of tables and their data. Similar to event listeners in Javascript, we can place lines of code on a table (DOM elements in Javascript) and have these lines of code execute upon a specific event. The frontend Javascript of a web application would be able to listen for click events, mouse events, and DOM events among others. In a database, we can listen to certain modifications that may occur on the tables themselves. These are called triggers.</blockquote><h3>Topics Covered</h3><ul><li>Stored Procedures / Functions</li><li>Triggers</li><li>OLD and NEW references</li><li>Incorporating Triggers into ORMs (ActiveRecord)</li></ul><h3><strong>Compatibility</strong></h3><p>Not all types of databases support triggers. One notable example is SQLite, which sacrificed many of the features other SQL databases come with.</p><p>MySQL and PostgreSQL are two examples of database languages that feature triggers. We will work explicitly with PostgreSQL in this blog, but will make a few references to MySQL triggers.</p><h3><strong>Stored Procedures</strong></h3><p>Analogous to how we have functions and methods in procedural and object-oriented languages, we have the ability to store reusable code within a database. These pieces of reusable code are called stored procedures and are stored within the metadata repository of a database. We can store any SQL code inside a stored procedure for easy reuse.</p><p>For PostgreSQL, a stored procedure would generally be written as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c532bb9cdd8f5c23403677b813ffbd18/href">https://medium.com/media/c532bb9cdd8f5c23403677b813ffbd18/href</a></iframe><p>With MySQL, we can write the procedure of the trigger directly in the SQL code that creates the trigger.</p><h3><strong>Example through logging Feelings</strong></h3><p>For this blog, let’s create a database that logs the emotions that Flatiron School students feel after the end of each week of their bootcamp program. There should be two tables, one for students and their information and another for feelings and the information associated with each feeling. Each feeling belongs to a student, and a student can have many feelings. The table below illustrates this database schema.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gug6cP-8sNOvMgk6W5QKgw.png" /><figcaption>A student can have many feelings, and a feeling belongs to a student. We want to implement a trigger so that an initial feeling is created when a student is created.</figcaption></figure><p>However, since all students are stressed on the first week of bootcamp, it makes sense to include this initial log of feelings automatically as students are added. We can accomplish this goal by creating a trigger.</p><p>Let’s first start by creating a stored procedure in PostgreSQL to model the insertion of initial feelings for all the students. This is how it would be written:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03a097c3a46ad195e142db0da1322914/href">https://medium.com/media/03a097c3a46ad195e142db0da1322914/href</a></iframe><p>Even though we can just start the first line as <strong>CREATE FUNCTION</strong> rather than <strong>CREATE OR REPLACE FUNCTION</strong>, it is good practice to include the <strong>REPLACE</strong> part should the need arise to include this trigger as part of the code that an Object-Relational Mapping (ORM) will process. We will dive into this later.</p><p>We have inserted a single line of</p><blockquote><em>(‘Stressed’, ‘1000 labs per second’, NEW.id, NOW(), NOW())</em></blockquote><p>into the feelings table. The NOW() function retrieves the current day and time, as there are columns in the table that require this information, namely the <em>created_at</em> and <em>updated_at</em> columns. NEW.id will be described in detail later as we intend to model this function for use by a trigger. Briefly, NEW refers to one of the two temporary tables that are created when a trigger action is called.</p><h3><strong>Let’s Trigger</strong></h3><p>For PostgreSQL, we can now use the stored procedure to create a trigger on the table we want there to be a trigger on. The syntax for a trigger in PostgreSQL would be as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5693c8ee60a2051f2bfd3f365d22fa2d/href">https://medium.com/media/5693c8ee60a2051f2bfd3f365d22fa2d/href</a></iframe><p>For our specific example, this would be implemented as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c03973ccd1f1d48b03c9c608009cf5dc/href">https://medium.com/media/c03973ccd1f1d48b03c9c608009cf5dc/href</a></iframe><p>We will call the trigger by name on the first line in order to reference it later for deletion.</p><p>The second line describes when we want the trigger to occur, and what we want the trigger to occur on. We can specify that it takes place <strong>BEFORE</strong>, <strong>AFTER</strong>, or <strong>INSTEAD OF</strong> a certain action. This action may be an <strong>INSERT</strong>, <strong>UPDATE</strong>, <strong>TRUNCATE</strong>, or <strong>DELETE</strong>. Following the specification of when we want the trigger to occur, we should specify what table the trigger will be placed on.</p><blockquote>Note: This is the table that will be listening for the specified action, not necessarily the table that we want to modify as a result of the trigger.</blockquote><p>The third line describes which rows of the table the trigger to take effect on.</p><p>The last line will indicate the name of the stored procedure we defined that should execute <strong>BEFORE</strong>/ <strong>INSTEAD OF</strong>/ <strong>AFTER</strong> a trigger action has been found.</p><p>For MySQL we may define a trigger in the following way:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0d80f3193c7d28f96cb42e9be4ac95a8/href">https://medium.com/media/0d80f3193c7d28f96cb42e9be4ac95a8/href</a></iframe><p>When we try to add a new student to the student table, either through a frontend interface or through SQL statements directly, we will find that a row has also been added to the feelings table with an association made back to the student that was just added. This is because we specified that the trigger takes place after an insert has been made on students, specifically for all rows.</p><h3><strong>Trigger’s NEW and OLD Tables</strong></h3><p>Looking back to the stored procedure we defined, there was a reference made to NEW.id when we made the association between students and feelings. When a trigger event takes place, the database will create two temporary tables, an OLD table, and a NEW table. The OLD table refers to the record (row) being tracked on the table with the trigger.</p><h4>INSERT Actions</h4><p>Since we are tracking an <strong>INSERT</strong> action, the OLD table will refer to a null record (since there were no records there prior to <strong>INSERT</strong>) while the NEW table will have the record that was inserted, namely the student that was added most recently (the one that triggered the event). NEW.id will refer to the newly added student’s id, while NEW.name, NEW.age, and NEW.location refer to the newly added student’s name, age, and location respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VCJrm_XtfAHfQNrO7yDCsA.png" /><figcaption>The above figure provides a visual representation for our OLD and NEW tables in an INSERT action. Note that since the record was just inserted, the OLD record refers to null as there was no record to begin with in the first place.</figcaption></figure><h4>UPDATE Actions</h4><p>The OLD and the NEW become more interesting when we consider other actions, such as an <strong>UPDATE</strong> action. The OLD table will contain the values right before the <strong>UPDATE</strong> triggering action is executed, while the NEW table will contain the updated values, after the <strong>UPDATE</strong> trigger action. For example, if we perform the following:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/87274dd53862be8031482bd178539578/href">https://medium.com/media/87274dd53862be8031482bd178539578/href</a></iframe><p>Then NEW.location will be ‘Long Island’ and OLD.location will be the value that existed there prior to the <strong>UPDATE</strong> action, ‘Brooklyn.’</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ox7Vi2Siqs8jzMCHRBdbuw.png" /><figcaption>The above figure provides a visual representation for our OLD and NEW tables in an UPDATE action.</figcaption></figure><h4>DELETE Actions</h4><p>The OLD and the NEW tables for a <strong>DELETE</strong> action follow the same pattern as a triggering <strong>INSERT</strong> action, except in reverse.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f20fdee58ac45ed870655258768f798c/href">https://medium.com/media/f20fdee58ac45ed870655258768f798c/href</a></iframe><p>Performing the <strong>DELETE</strong> action above would yield the following OLD and NEW tables when executed by a <strong>DELETE</strong> trigger. OLD would refer to the previous record that existed prior to <strong>DELETE</strong>, and NEW would be null as the record had already been deleted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oKJB5nbeBFQJNU4SJRMcLQ.png" /><figcaption>The above figure provides a visual representation for our OLD and NEW tables in a DELETE action. Note that since the record was deleted, the NEW record refers to null as no record exists anymore.</figcaption></figure><h3><strong>Usage in ORMs: ActiveRecord</strong></h3><p>If we want Ruby’s ActiveRecord ORM to incorporate a trigger into the database tables, we must define the SQL manually. We must also define the SQL in ActiveRecord’s up and down method rather than ActiveRecord’s change method. This is because there are no built-in functions for creating triggers as there are for creating, inserting, deleting, and other common SQL actions.</p><p>We must implement both the up and down actions so that we can migrate and rollback without a problem. Define the creation of the stored procedure and trigger in the up method and the destruction of the trigger and the stored procedure in the down function as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7df56e1ebedb54a27b0e514b570c211f/href">https://medium.com/media/7df56e1ebedb54a27b0e514b570c211f/href</a></iframe><p>With all that in mind, enjoy your new found skill of triggering!</p><h3><strong>References</strong></h3><ul><li><a href="https://www.postgresql.org/docs/9.1/static/sql-createtrigger.html">https://www.postgresql.org/docs/9.1/static/sql-createtrigger.html</a></li><li><a href="https://dev.mysql.com/doc/refman/8.0/en/trigger-syntax.html">https://dev.mysql.com/doc/refman/8.0/en/trigger-syntax.html</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c527ae9eafa5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implementing Simultaneous Key Presses]]></title>
            <link>https://medium.com/@wireless.patrick/implementing-simultaneous-key-presses-8c592c74a450?source=rss-b1eb97dc7c8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c592c74a450</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[browsers]]></category>
            <category><![CDATA[games]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[events]]></category>
            <dc:creator><![CDATA[Patrick Abejar]]></dc:creator>
            <pubDate>Mon, 29 Oct 2018 03:26:39 GMT</pubDate>
            <atom:updated>2018-10-29T03:26:39.151Z</atom:updated>
            <content:encoded><![CDATA[<p>You’re creating a game (or an app where you want to hide some easter eggs) and you decide that you want simultaneous key presses implemented into it. Unfortunately for you, keydown events do not come simultaneously or even alternate between the keys you press down on.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aef2405ddac6b564a0ecae6555b152ff/href">https://medium.com/media/aef2405ddac6b564a0ecae6555b152ff/href</a></iframe><p>For example, if I run the code above in my browser’s console and simultaneously press more than one key, it will only fire the last key that the browser detected. This isn’t exactly what we wanted. This was the dilemma I encountered when I was trying to make my character move diagonally in my game.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2fTqFPr9SW5T3t0v4xjoow.png" /><figcaption>When I try to press the up and left keys at the same time, only the later of the keys is registered in firing the keydown event. We have to implement this behavior explicitly.</figcaption></figure><h3><strong>Record Key Events in an Array</strong></h3><p>Luckily, there we can work around this behavior. Depending on how many keys you need simultaneously pressed down, you can store keydown events in an array as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/813e11ecde9e1586d487dc21866fcd43/href">https://medium.com/media/813e11ecde9e1586d487dc21866fcd43/href</a></iframe><p>Run the above code in your browser’s console and press a bunch of keys. If you check keysRecord, you will see that the array has been populated with respect to the keys that were pressed. Any key that was pressed will not be undefined in the array with respect to the key’s keyCode and it will have an entry in the keysRecord array marked as the boolean true since one of the events did meet that conditional test of e.type === “keydown”.</p><p>For example, try pressing down the left key. When you check the keysRecord array, you will see that keysRecord[37] has a value of true. 37 is the respective keyCode of the left key.</p><h3><strong>Ensure Simultaneous Key Presses Only</strong></h3><p>However, when we release this key, it is still marked as true. Let’s apply the updateKeysRecord function also to a keyup event listener so that the conditional test in updateKeysRecord will change the array entry to false for the respective key that was released.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c8f56f34ea70770920dced6a3c70200/href">https://medium.com/media/9c8f56f34ea70770920dced6a3c70200/href</a></iframe><p>So that we may have a more visible response, let’s run the following in our browser’s console.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f295a9035c02925345cbedef102f64f5/href">https://medium.com/media/f295a9035c02925345cbedef102f64f5/href</a></iframe><p>If we press ‘a’ and ‘b’ keys simultaneously, the console.log message “a and b!” should pop up in the browser’s console. Pressing just one or pressing anything else would not yield that result. This is due to the array we used to store keys that are actively being pressed. In fact, you can add as many keys as you want to the if statement.</p><p>You can find the keyCodes quickly at <a href="https://keycode.info/">https://keycode.info/</a> or by running the KeysTogether1.js in the browser’s console manually.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c592c74a450" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy Websites and React Production Builds on Amazon Web Services]]></title>
            <link>https://medium.com/@wireless.patrick/deploy-websites-and-react-production-builds-on-amazon-web-services-865e7ec67d1c?source=rss-b1eb97dc7c8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/865e7ec67d1c</guid>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Patrick Abejar]]></dc:creator>
            <pubDate>Mon, 22 Oct 2018 03:03:49 GMT</pubDate>
            <atom:updated>2018-10-23T15:35:42.669Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TvX3txt6WiP5--yi1tTQYA.png" /></figure><p>Do you have a static website or an app that can be served by a node static server? You can definitely deploy your website/app on Amazon Web Services (AWS) in few and very simple steps in order to let others use your website/app. We’re going to use Amazon S3 (Simple Storage Service) in order to accomplish this task as it comes with free tiered access. You are limited to the amount of storage and also the amount of calls on your resources that users make each month. To find out about the most up to date limits, visit <a href="https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/free-tier-limits.html">https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/free-tier-limits.html</a>.</p><p><em>Prerequisite: Sign up for a free account (depending upon your requirements) at </em><a href="https://aws.amazon.com/"><em>https://aws.amazon.com/</em></a></p><p>Once you have signed up for an AWS account, you will be shown the list of all the web services Amazon has to offer on your console. Look for the Storage section, and then click S3. This will be the best way for us to host static files and static websites on Amazon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5ikx4QA4do7YLMvF6S36yQ.png" /></figure><h3>What is a Bucket?</h3><p>A bucket is similar to a folder/directory on your computer. However, files are stored as objects when stored in the S3 cloud. The user can control read and write privacy for each of the user’s buckets. Buckets can be placed in a physical region chosen by the owner of the bucket.</p><p>Click “Create bucket” and the following screen should show up:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SnrHq5DNtnprM1JhH4U5GQ.png" /></figure><p>Fill in the bucket name with a DNS compliant name. If you have a website, you will want to use that exact URL. For example, I would place <a href="http://patrickabejar.net/">patrickabejar.net</a> in that field. Below that, choose the physical region closest to the majority of your expected audience. You may go ahead and click next.</p><p>The next screen asks for information on Properties and Management. As of now, we don’t need to tweak with any of these options for the basic goal we want to accomplish so we can go ahead and click next again.</p><h3>Option 1</h3><p>One way that we can let our website be publicly in view is to change the option of manage public permissions to “Grant public read access to this bucket.” You don’t have to chose this method, and there will be a second method to allow public read access to the bucket later in the article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r3cOPleVy44LL4P8OT6s_A.png" /></figure><h3>For Both Option 1 &amp; 2</h3><p>Go ahead and click next, and then create bucket.</p><p>Your bucket should now appear on the list of buckets. Click it’s name and you should be shown this screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xw3WIfU7uKCp9It0AU_3vA.png" /></figure><h3><strong>Option 2</strong></h3><p>If you didn’t go along and make your bucket readable in option 1, you should follow this method of making your bucket readable. Click the Permissions tab on top and then click Bucket Policy. Copy and paste the below policy into your Bucket policy editor. You must change the resource line to contain your actual bucket name. Click save and you should be told that the bucket was successfully made public. Click Overview to head back to complete your website deployment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SuIQ1ku5ccj7MAguV37OWw.png" /></figure><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c19d03bc8f019950dbbb5f0c3745b6b8/href">https://medium.com/media/c19d03bc8f019950dbbb5f0c3745b6b8/href</a></iframe><p>Click upload and then either find the files of your website/app on your computer after pressing Add Files or drag them and drop them onto the drop area.</p><h3><strong>Tip on Deploying React Apps on AWS</strong></h3><p>You should clear all the errors and warnings from your console before you deploy your React app. Once that is accomplished, your terminal will display instructions on how to get a production build of your React app ready. You will need to run the following command in order to start on your production build.</p><blockquote>npm run build</blockquote><p>Navigate to the build folder that was just created. Upload all the contents of the build folder into your S3 bucket. These files may also be run locally served through a node static server in order for you to run your production build locally.</p><h3>Finalize Deploying</h3><p>You don’t need to wait until upload is finished to configure your static website/app as a static one. Click on the Properties tab and find the card that says static website hosting. Click that and then click “Use this bucket to host a website” to active the static server. Type in the document you want shown (usually index.html) when a user accesses your bucket in the index document field. You may also type in an error document for error handling. Take note of the endpoint on the top portion of the card. Click save.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kz7ix-F5VxkbsY2jAT06CQ.png" /></figure><p>Once the uploading is complete, go to your endpoint in your browser. You will see your website/app successfully deployed to AWS!</p><h3><strong>Tip on Using An External Domain Name</strong></h3><p>You should use your endpoint (minus the bucket name part) as a CNAME record in your DNS records to link to your AWS bucket. For example, <a href="http://patrick.net.s3-website.us-east-2.amazonaws.com/">http://patrick.net.s3-website.us-east-2.amazonaws.com</a> should become <a href="http://us-east-2.amazonaws.com./">http://us-east-2.amazonaws.com.</a> This may take a while to be reflected on the DNS.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=865e7ec67d1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beyond 1024×768 Design: CSS Units of Measurement]]></title>
            <link>https://medium.com/@wireless.patrick/beyond-1024-768-design-css-units-of-measurement-17c00f3de801?source=rss-b1eb97dc7c8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/17c00f3de801</guid>
            <category><![CDATA[responsive-design]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[ui]]></category>
            <category><![CDATA[html]]></category>
            <dc:creator><![CDATA[Patrick Abejar]]></dc:creator>
            <pubDate>Fri, 12 Oct 2018 16:06:13 GMT</pubDate>
            <atom:updated>2018-10-12T16:06:13.795Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*27B9O5qW9y_uEm0rswDMLQ.png" /></figure><p>Styling is very important to consider when creating user-friendly interfaces for web apps and static websites. Users want their experiences to be easy and intuitive. Small details such as the wrong positioning, the wrong sizing, or something too complex can turn off users. In this blog post, we will take a look at the different ways we can specify sizes of elements.</p><p>There are many different ways to specify size due to the multitude of physical display dimensions that exist among all devices with web browsers. You don’t want to create a website that displays beautifully on your 13” MacBook but looks like a cluttered mess when displayed on an iPad or your 11.6” Chromebook. Likewise, you don’t want to end up with large amounts of whitespace when you display your website/app on a large display screen. When websites/ web app layouts and styling are user-friendly for all dimensions, the websites/web apps are said to be responsive.</p><h3>Units by Pixels</h3><p><strong>Units: px</strong></p><ul><li><em>Disadvantage: Not responsive</em></li></ul><p>The obvious disadvantage to indicating sizes of elements in pixels is that resizing a window will not automatically scale the element/layout in proportion to the new size of the window. Desktops and especially mobile devices of all dimensions will display the elements in different proportion to each other.</p><ul><li><em>Advantage: When you don’t need responsiveness for something static such as border-radius or border thickness</em></li></ul><p>When creating rounded borders around a &lt;div&gt;, &lt;section&gt;, or &lt;button&gt; element, you usually don’t want the element to appear more round when the proportion goes up or down. Typically proportional measurement units are needed for the entire size of the element, not just one aspect of it. Keeping this in mind, it makes sense also to specify border thickness in terms of pixels and not as a function of the viewport or parent element dimensions.</p><h3>Percentage of viewport</h3><p><strong>Units: vh, vw, vmin, vmax</strong></p><p>You can specify the size of an element proportional to the viewport dimensions. The viewport is defined as the user’s visible area of a web page in the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i25xqFoNO6lo0x115UacqQ.png" /><figcaption>The area inside the red rectangle is known as the viewport. vh refers to the height of this rectangle, while vw refers to the width of this rectangle.</figcaption></figure><p>100 vh refers to the dimension of the entire viewport height, while 100 vw refers to the dimension of the entire viewport width. Think of the numerical value as being a percentage of the viewport. vmax can also be used, which gives the greater value between vh and vw. Likewise, vmin gives the lesser value between vh and vw.</p><ul><li><em>Best Use Case: Specifying sizes of top-level elements</em></li></ul><p>It is best to use proportional viewport measurements when specifying the outer most elements of the webpage/ web app. The proportional measurements provide element responsiveness to changes in window/viewport size. Viewport size measurements give our website/web app portability so that it may be viewed on platforms of different displays.</p><p>Often one may want to use min-height, max-height, min-width, and max-width with viewport measurements. These css attributes are useful when you have a known size range (proportion or pixels) for an element rather than a specific number for the size. Use this when you want to avoid whitespace.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/1*1SGGzoIdMls1MXfCL_bC6A.gif" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*92mib7PvXo5mKw8e6NIF1w.gif" /><figcaption>The GIF on the left shows a website that lacks responsiveness. When dimensions are changed, the website will not scale to a user-friendly size. The elements unintentionally collide amongst each other.</figcaption></figure><h3>Percentage of parent element/root element</h3><p><strong>Units: %, em, rem</strong></p><p>Percentage and em units of measurement also follow proportional behavior, however, they are both with respect to the parent element and not the viewport. Specifying 100% in an element will make it the same size (either width or height) as its direct parent. Likewise, specifying 1.0 em will also make an element the same size (either width or height) as its direct parent. The measurement size em refers to what multiplicative factor the child is in relation to the parent.</p><p>Sometimes, you don’t want to specify the size of an element in proportion to the viewport. This is especially true if you want to keep your element responsive to its surrounding environment, especially to a non-responsive parent. Imagine if you made a child div with a pixel specified parent — depending on the size of the viewport, the child could become larger than its direct parent.</p><ul><li><em>Best Use Case: Specifying the size of an element that has a non-responsive parent</em></li></ul><p>Note: You can also use rem to represent size in proportion to the root element.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17c00f3de801" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Virtualization: Sharing Is Caring — The Technology behind Cloud Computing]]></title>
            <link>https://medium.com/@wireless.patrick/virtualization-sharing-is-caring-the-technology-behind-cloud-computing-818dbcd35998?source=rss-b1eb97dc7c8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/818dbcd35998</guid>
            <category><![CDATA[hypervisors]]></category>
            <category><![CDATA[google]]></category>
            <category><![CDATA[computers]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[virtualization]]></category>
            <dc:creator><![CDATA[Patrick Abejar]]></dc:creator>
            <pubDate>Fri, 14 Sep 2018 18:20:43 GMT</pubDate>
            <atom:updated>2018-09-14T18:20:43.634Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-YJiTB80ZTIZd1BXeyc6Gg.png" /></figure><p>Over the years, technology has supplemented and powered business functions by taking advantage of automation in order to increase efficiency and profitability. However, this initially did not come without a decrease in human effort as people were required to create new and maintain existing information technology infrastructure. Different methods of software and infrastructure delivery were tried and eventually molded itself into the ever so efficient cloud computing model powered by virtualization. The push for virtualization originated out of the realization that large amounts of infrastructure remained idle and could be put to better use and full utilization if some form of resource pooling was available. Resources such as CPUs, storage devices, applications, and etc. were divided up so that they may be available to people outside the physical context of a machine. This introduce the concept of virtual machines and virtual applications which were not bounded to a physical definition but could span many physical machines. Not only could physical machines span multiple machines, but one machine was able to contain multiple virtualized machines. Technologies pushing this idea were developed throughout the years, including many proprietary and some open source. Different considerations of security, proprietary ownership, required functions, and others were motivations behind some of these different technologies. Although each technology developed differently, resource allocation technologies of virtualization enabled cloud computing.</p><p>Traditionally, software has been dependent upon hardware and its limitations. Virtualization takes a new approach to software, allowing it to take higher degrees of managing software not done previously. Multiple machines could exist on one machine with the aid of a supervisory software that would manage each virtual machine. This supervisor software, better known as the hypervisor, would need to mimic the administrative characteristics of physical CPUs, storage, I/O devices, and other hardware. A hypervisor would need to manage software in in that the virtual environment provided is identical to the physical environment, that the program is able to run efficiently without significant decreases in speed, and that the virtual machine monitor is in complete control of the virtual machine. Along with these three requirements, a virtual machine shall not interfere with the operations of another virtual machine under that same hypervisor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nI4z1z2FhosmemiD8TH3yg.png" /></figure><p>This leads to technologists working diligently to prevent interference despite all machines being supervised under the same hypervisor and utilizing the same CPU. Modern day CPUs have virtualization in mind upon construction. Previously, CPU instructions and other concepts specific to certain CPUs have made the virtualization process difficult. In this case, certain manipulation techniques and abstractions are required by software in order to successfully fulfill the above requirements of hypervisors. Specifically, there are three instructions make virtualization challenging. For the Intel x86 processor these are instructions that make the status register aware to the virtual machine, instructions that utilize one of a kind local/global registers, and instructions that may violate different privilege levels. The Motorola M68000 processor only had the trouble of dealing with the first set of problematic instructions. In order to solve this problem, already existing traps were used to divert processing these problematic instructions into the hypervisor for the hypervisor to deal with accordingly. This required a slight modification in the written instruction set. Whether this modification in instruction set would be performed at real-time or the modification in instruction set would be performed completely before any instruction set would be processed would depend on the needed advantages of each method; the former approach is termed binary rewriting, and the latter approach is termed paravirtualization. When instruction sets are trapped in the hypervisor, the hypervisor itself can manage individual operating systems of each virtual machine and may process the new instructions without interfering with other machine privileged operations.</p><p>Hypervisors are a necessary middleman that expand the abilities of software to manipulate hardware; however, like with any middlemen, they add overhead cost to the speed and processing power overall. This is due in part to virtual machines being created at the user level rather than at the kernel level. To address this weak point, operating system virtualization has been developed in order to lower overhead, which creates virtual servers at the kernel level. However, other characteristics of virtual machines make them an excellent choice of technology when dealing with other technological considerations such as application portability, platform independence, and offerings of rich programming languages. Although not a requirement, these characteristics help make cloud computing more available to others, especially in the case of proprietary boundaries. A famous example of this is the Java Virtual Machine, whose slogan is “compile once, run anywhere.”</p><p>One instance does exist where virtualization does increase speed and performance of computations, and that is in the case of parallel cluster computing applications. Virtualization of resources among many different physical machines can, in effect, create a virtual machine more powerful than any physical machine supporting it. This pooling of many virtualized physical machines is the basis for cloud computing and allows us to offer many of the services that cloud computing has to offer. This is not just limited to a single virtual machine but applications of this can be extended to concepts of network virtualization and its applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yWdMBXnOntE9JRYDhPTzWg.jpeg" /></figure><p>The varying levels of virtualization compatibility possessed by processors led to different designs of hypervisors. Hypervisors may exist on the bare metal of CPUs for fully virtualized machines such as Oracle VM, Sun xVM, and VMWare ESX. For CPUs that do not support these machines running on bare metal, hypervisors may run on the operating system and manipulate hardware characteristics from there. Oracle’s VirtualBox is creative in its technology as it takes advantage of the unused privilege levels between the kernel and the user level in order to take control of the virtual machine when it stumbles upon any of the previously mentioned three classes of troublesome instructions.</p><p>Using already existing technology of sharing I/O devices across networks, hypervisors have been able to share I/O devices among their virtual machines. The Xen hypervisor takes advantage of this concept by sending TCP network messages to a designated host at dom0 (symbol for host’s domain) where all the I/O devices are connected. Drivers are required on all these virtual machines in order for the virtual machine to accurately understand the I/O devices it wishes to communicate with. A modified version of direct memory access (DMA) called IOMMU allows virtual machines to connect to any I/O device that the physical machine is connected to while maintaining security and separation from other virtual machines. The DMAs that exist in the physical machine require a MMU that effectively separates virtual machines through a translation of memory addresses in a record keeping table.</p><p>Because I/O device tasks are engineered efficiently in paravirtualization, there are some times that I/O intensive tasks really benefit from being paravirtualized over fully virtualized in terms of speed. The ability of the MMU to separate I/O devices among different virtualized machines is what make paravirtualization more desired for I/O devices. This technique to creating a faster hypervisor is better known as hybrid virtualization.</p><p>From many machines, makers of hypervisors were able to collectively pool the CPUs, I/O devices, and storage devices from these machines and abstract them into one virtual machine that people were able to use. The responsibility of distributing computation tasks and resources is given to the load balancer. Load balancers typically distribute request for resources in a round robin fashion on the condition of the health, workload, priority, traffic, and security of the resources. However, this depends on the implementation of the load balancer. The most advance types of load balancers ensure efficiency of virtualization through a greater number of these quality assurance criteria and even perform compression and caching techniques. Load balancers are very necessary in server farms where requests are mapped to an enormous amount of resources at the direction of the load balancer. It is interesting to note that load balancers take the opposite approach of mapping abstracted/imaginary addresses to physical resources, compared their foundations of virtual machines that map physical resources to abstracted virtual addresses.</p><p>The standards of virtualization and its applications have been well discussed and created that many organizations and industries look to virtualization to create powerful efficient technologies with the highest integrity. The Java Virtual Machine was previously mentioned as a virtualized technology that not only creates a virtualized environment but also promotes portability. Google Search is a more prominent example of virtualization with more than 3.5 billion searches daily worldwide. Google Search takes advantage of the parallel cluster computing technology that virtualization offers in order to handle the massive workload it incurs every minute. Although simple by appearance, Google employs a large amount of physical machines distributed throughout various worldwide locations that run the same Google search application. Load balancers distribute search queries to various Google servers, some of them containing caches to speed up processing. Distributed virtualized systems such as Google’s not only allow for speedy applications, but reliable applications redundantly reinforced among many resources.</p><p>Virtualization has broken the long held thought that machines are confined to their physical boundaries. Software can manipulate hardware in order to provide this breakthrough. A single physical machine may contain many virtual machines and these virtual machines may be abstracted and pooled together so that they are viewed to the end user as a powerful machine that can be used on demand. The portable nature of virtual environments also aids in this goal by increasing compatibility. The most prominent examples of virtualization in modern day are software, platforms, and infrastructure being provided as a service in the cloud. The flexible nature of virtualization allows under utilized resources to be brought together to make these applications possible and thus radically change business processes by more powerful systems on demand to power these businesses.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=818dbcd35998" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Rails to Create Meaningful Relations]]></title>
            <link>https://medium.com/@wireless.patrick/using-rails-to-create-meaningful-relations-a39efafe9187?source=rss-b1eb97dc7c8d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a39efafe9187</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[forms]]></category>
            <category><![CDATA[object-oriented]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Patrick Abejar]]></dc:creator>
            <pubDate>Sat, 01 Sep 2018 03:59:46 GMT</pubDate>
            <atom:updated>2019-02-17T01:11:41.764Z</atom:updated>
            <content:encoded><![CDATA[<p>Objects associate similarly related information about natural phenomena or other real-life nouns into an incredibly useful package. It is much more useful to have a customized artist object set as the attribute of a song rather than setting that same attribute to a string containing the artist’s name. It is much easier to set descriptive identifiable attributes such as hometown, genres, year started, and others to an artist object rather than a string representing an artist’s name. Recursively, we can provide attributes for hometown, genres, and years started, as long as we write our own classes for those attributes. One of the most interesting features of object-oriented programming lays in establishing relationships between any of these classes. This gives our data richer meaning beyond the scope of boring String or Fixnum attributes. We can build complex and powerful webs of relationships that will allow our genre object to provide us with all the song objects that belong to it, or all the song objects that an artist object has.</p><h3>The Problem</h3><p>Ideally, we want to be able to set an artist object equal to the artist attribute of a song object as shown below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/df9c763c4e324e3faf33e776523ecae0/href">https://medium.com/media/df9c763c4e324e3faf33e776523ecae0/href</a></iframe><p>But almost none of our data is provided for us in the object format we desire. The Internet is filled with data flowing through forms as strings rather than a nice object. A user can’t simply type an object into an HTML form. You can only type in strings. We have to transform that user inputed string into an object. Only then can we take advantage of the previously mentioned powerful features objects offer us. In this example, it is the ability to create relationships among objects.</p><h3>The Actual Case</h3><p>A user types in the following information into a form that creates a song.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/59c8386612bdcc2357230736c952373d/href">https://medium.com/media/59c8386612bdcc2357230736c952373d/href</a></iframe><p>All this information is posted to a rails route that will now have control over all three of these user inputted strings. We can easily create objects using Rails.</p><p><strong>But wait… Why do you want to create a differently named setter to store your user input text over the ActiveRecord produced method?</strong></p><p>We like setting custom made objects as attributes, rather than strings and fixnums as these custom made objects can have different methods implemented for them.</p><p>Essentially, both methods work by setting an object as an attribute to another object. This is a shared goal. The difference lays in our input. One method takes in user text and another takes in an object. We have to that user text and transform it into an object.</p><p>When users type in information in a form, they often will not be typing an ID of an object, rather they will enter a descriptive name. This text should be used to either find or create an object. Once that object is instantiated and simultaneously persisted onto the database then we may form relations between it as follows:</p><ul><li>If the object the form was intended for HAS_MANY of these newly created/found objects, then we must push the instance of this object onto the array.</li><li>If the object the form was intended for BELONGS_TO this newly created/found object, then we can set this instance of this object to an array.</li></ul><h3>Implementation</h3><p>You will need to define custom getters and setters for the user text input you want to use to create or find an object. The setters will either push the object into an array (representing has_many relationship) or set the object equal to the attribute directly (representing a belongs_to relationship).</p><p><strong>REMINDER: If this user field is left blank, we must not pass this into the create class method. We can either delete these empty strings or we can ignore them as we iterate through the params hash. This is performed in the model’s method.</strong></p><h3><strong>Naming Conventions</strong></h3><p>The name of the getters and setters are dependent on the names provided in the HTML form. You will want to use a different name than the ActiveRecord defined setter to avoid self-referencing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a39efafe9187" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>