<?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 James Thomas on Medium]]></title>
        <description><![CDATA[Stories by James Thomas on Medium]]></description>
        <link>https://medium.com/@jamesjacobthomas7?source=rss-850b5c14102c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*GJMMnYcKKV-F3QrOhFVXCQ.jpeg</url>
            <title>Stories by James Thomas on Medium</title>
            <link>https://medium.com/@jamesjacobthomas7?source=rss-850b5c14102c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 02:28:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jamesjacobthomas7/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[The Importance of Making Your Website Mobile Friendly]]></title>
            <link>https://medium.com/@jamesjacobthomas7/the-importance-of-making-your-website-mobile-friendly-bd88a2db24d1?source=rss-850b5c14102c------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd88a2db24d1</guid>
            <category><![CDATA[mobile-friendly]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[responsive-design]]></category>
            <dc:creator><![CDATA[James Thomas]]></dc:creator>
            <pubDate>Thu, 09 May 2019 03:56:06 GMT</pubDate>
            <atom:updated>2019-05-09T03:56:06.999Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*fiqeAm0jENOgu6_D3CgnMg.gif" /></figure><p>You just finished your website. The frontend has just been connected to the backend. All the data has been displayed to the client and it has been deployed and up and running. You think that you’re done and ready to move on but you’re forgetting one crucial thing. Your website doesn’t look too good on a mobile device. Why is that important? Let me tell you why.</p><p>Since the dawn of mobile devices, it has always been important to make your website mobile friendly. Since 2015, 60% of website traffic now comes from mobile devices and now experts say that 35% of website traffic comes from online shoppers. So if you’re website isn’t mobile friendly, then you maybe losing out on a large chunk of potential revenue. Also mobile devices are more accessible and easier for people to log on with.</p><p>Making your website mobile friendly, also increases the overall user experience. At the point when a website is perused from a mobile or tablet, it changes from an even design to a vertical configuration, bringing on a different display of content and pictures. Responsive website design controls the webpage to properly fit the screen of the gadget utilized, contracting the pictures and content sizes rather than keeping a constant structure. Accordingly, this programmed adjustment improves the user experience by providing a less demanding method for navigating the website.</p><p>A mobile friendly website is more cost effective. Before responsive web design, one had to create multiple versions of the same website to serve different device sizes and this ended up costing a lot of time and resources. It also made it difficult to make changes on the fly and makes your website less abstract.</p><p>Lastly, having a mobile friendly site engages your Google rating or SEO. An urgent stride in enhancing a website is to create a responsive website composition in light of the fact that, all in all, Google identifies if a website is mobile friendly and favors it when displaying search results.</p><p>One of the best ways to make your website mobile friendly, is by setting up multiple media queries. With this queries, you can have your HTML check to see what size display the client is viewing your website and adjust accordingly. You can maneuver the positioning and sizing of elements on the page in order to make browsing a more pleasant and UX friendly experience.</p><p>Hopefully this was convincing enough to consider making your next website/application more user friendly for mobile device users of different screen sizes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd88a2db24d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS Variables]]></title>
            <link>https://medium.com/@jamesjacobthomas7/css-variables-d6a81efd764b?source=rss-850b5c14102c------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6a81efd764b</guid>
            <category><![CDATA[css-variables]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[James Thomas]]></dc:creator>
            <pubDate>Thu, 25 Apr 2019 03:58:33 GMT</pubDate>
            <atom:updated>2019-04-25T03:58:33.258Z</atom:updated>
            <content:encoded><![CDATA[<p>Variables exist in most programming languages. They are keywords used to store information. They can be arbitrary values like a string , number, boolean, or something a little more complex, like a function/method or an object/hash/dictionary. Well they also exist in CSS as CSS variables too.</p><p>CSS variables, (aka Custom properties or Cascading variables) are values defined in CSS that designed for reusability throughout the stylesheet. They are set using the custom property notation and are accessed through the var function.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*t2BeY7u7BiTpIt3ZfT7F0Q.png" /><figcaption>Defining and using CSS variables</figcaption></figure><p>In the above code snippet, we have used the root pseudo class to define three css variables, base, spacing, and blur. Then throughout the code, the variable is used with var() function throughout different attributes for different elements. Large programs could have lots of CSS with a lot of repeated values and makes it difficult to find alter these values. The custom properties allow the initial place to store the value and have it referenced numerous times. It also makes it easier with the naming instead writing out long and complicated values, with the variable name instead.</p><p>In the case of a no value for a custom property on a given element, the value of the parent is inherited. Here is an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*eAJGwgmHqAI6l04nYG4LMA.png" /></figure><p>Here we have some HTML with some defined class names on each div. In the style code below, we have two css selectors for the two of the divs with two custom variables with different values. However, you can see that the other two classes do not have any css selectors for that custom value. The results end up being the following:</p><ul><li>class=”two” element: 10px</li><li>class=”three” element: 2em</li><li>class=”four” element: 10px (the parent for this element has the value of 10px so it inherits that value)</li><li>class=”one” element: undefined (this element does not have a parent to inherit from so it’s value ends up being undefined)</li></ul><p>CSS variables are not like typical variables in a programming language. The value is computed when needed and is not stored for future use in other rules. For example, you cannot set a property for an element and expect it available in a sibling descendant. The property is only set for the matching selector and its descendants, like any normal CSS.</p><p>When using the var() function, you can setup multiple fallback values in case the given variable is not defined. It is not used for browser compatibility but instead for choosing a different value if the variable isn’t defined or if it is invalid. The function accepts two parameters. The first argument is the name of the custom property to be substituted. The second argument is the fallback value in case the first argument fails. If the second argument fails then it will evaluate as invalid.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mzww8AKQkLvduyac2aJr9Q.png" /></figure><p>The above technique does has some performance issues, due to the fact that it does take time to parse those values.</p><p>The classic sense of validity in CSS, tied to each property, is not useful in regards to custom variables. When the values of the custom properties are parsed, the browser doesn’t know where they will be used, so must, therefore, consider nearly all values as <em>valid</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6a81efd764b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Call Stack]]></title>
            <link>https://medium.com/@jamesjacobthomas7/the-call-stack-707805c96c8c?source=rss-850b5c14102c------2</link>
            <guid isPermaLink="false">https://medium.com/p/707805c96c8c</guid>
            <category><![CDATA[call-stack]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[methods]]></category>
            <category><![CDATA[stack]]></category>
            <dc:creator><![CDATA[James Thomas]]></dc:creator>
            <pubDate>Thu, 28 Mar 2019 03:02:26 GMT</pubDate>
            <atom:updated>2019-03-28T03:02:26.729Z</atom:updated>
            <content:encoded><![CDATA[<p>A call stack is known as many different things. It can be called the execution stack, the program stack, control stack, run-time stack, or machine stack. It is a stack data structure that stores information about the active subroutines of a computer program. In this case let’s talk about it’s relation to function/method calls</p><p>Let’s say you have multiple methods declared like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TFVeSjHDNM3dx9uRomo_lw.png" /></figure><p>You have two methods declared first, #greet2 and #bye, which puts out two statements to your console. The third method ends up putting statements to the console and calls both of your previously declared methods. The stack however doesn’t take place until the functions are called so how does it begin? Let’s start by calling #greet since it calls our other two methods anyway. What does that look like? Your computer allocates a box of memory for every method call and within that box holds any variables declared as well as their values that method called within that same box. Here is a visual example if you got lost there:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KXZ_3MmPBPefJOIwqkxPDg.png" /><figcaption>Initial method call #greet</figcaption></figure><p>Here since the first method call is #greet, its memory is allocated first along with it’s parameter and argument value. Then it puts “hello, #{name}” and continues to the next line where #greet2 is called in which another stack is placed on top of the current call stack. This is the case because the initial #greet method has not completed running and is in a partially complete state so we add one more memory block to the stack:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tGVGXRtzfPI4af1VDeKU9A.png" /><figcaption>#greet2 is called and added to the call stack</figcaption></figure><p>Then before you go further the #greet2 finishes because it puts out the statement with no further function calls within and you return from the method call. When this happens, the method that returns gets popped off the stack:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9OL4UxSFFOkl8SHkOiDZBg.png" /><figcaption>#greet2 popping off the current call stack</figcaption></figure><p>We are still in our #greet method so that block of memory still remains and we continue to work our way down. The next line puts out a string priming us for our #bye method. Then the #bye method is called and then added to the call stack:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PrYRSWF9mRAzD4YWSzU0CA.png" /><figcaption>#bye added to the current call stack</figcaption></figure><p>Since #bye has no variables we don’t need to make any additional allocations to our #bye memory block. Then the #bye method exits out and get’s popped off of the call stack. Then since our initial #greet method has no more code to run in its body, it returns and also gets popped off and our stack has completed.</p><p>Now that was a simple implementation of a call stack but what happens when things get more complicated? What happens when we throw recursion into the mix?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=707805c96c8c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a proxy server with Node and Express]]></title>
            <link>https://medium.com/@jamesjacobthomas7/building-a-proxy-server-with-node-and-express-25af8c4551b8?source=rss-850b5c14102c------2</link>
            <guid isPermaLink="false">https://medium.com/p/25af8c4551b8</guid>
            <category><![CDATA[proxy]]></category>
            <category><![CDATA[dark-sky-api]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[expressjs]]></category>
            <category><![CDATA[servers]]></category>
            <dc:creator><![CDATA[James Thomas]]></dc:creator>
            <pubDate>Thu, 07 Mar 2019 07:00:22 GMT</pubDate>
            <atom:updated>2019-03-14T22:12:45.162Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I was working on a weather application and building it with React and I had decided to use the Dark Sky API in order to do so. Now usually I would just make a fetch request to the external Dark Sky API and display the data in the frontend. However this didn’t work as intended because Dark Sky had turned CORS off in order to protect the client from having their API key exposed. So in order to solve this problem I built a proxy server with Node and Express.</p><p>Now according to the docs Node is an asynchronous Javascript runtime that is designed to build scalable web applications. It can handle multiple requests concurrently but if there are no requests, then Node falls ‘asleep’. Express is a framework for Node that is put on top that helps build robust APIs. First you need to make sure the following dependencies are installed and available in your project:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*K-AVzxgViPAKq3xvtpe74g.png" /><figcaption>Use npm or yarn with terminal/command line to add these dependencies to your application</figcaption></figure><p>Here’s the file structure that I used after initializing npm for the server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*e_bAFOTL48DGxZRCED9uDw.png" /><figcaption>My file structure for my proxy-server</figcaption></figure><p>You have your node modules which is standard after initializing your Node application. Then there is the .env file where the environment variables. Here I stored the two API keys that were required for my weather application; Dark Sky (weather data) and MapQuest geocode (converts text into lat/lng coordinates). It also stores something called the port number but we will get to that shortly. We then add this file to the .gitignore and then our keys as well as the port number are directly injected into our application when it spins up. The Procfile is only necessary for deployment to Heroku and can be ignored for the moment. Then we have our Readme and our Javascript file housing the code for the server. Let’s take a look at server file next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UaNxiIJODT9BFq1Thk7NXg.png" /><figcaption>The meat of it all…the server</figcaption></figure><p>There’s a quite a few moving pieces but I’ll break it down to make it understandable. The first thing we have is <strong>dotenv; </strong>it’s a dependency used to handle the environment variables and their injection into your project. Then we initialize an instance of <strong>express</strong> which is the instance of a server. The server being active and online is then saved to a new variable called <strong>app</strong>. We then have the <strong>port</strong> variable which defines the port for the endpoint that will be used for the proxy server. Here for production and deployment it’s using the predefined environment variable from the .env file or defaulting to 3000. For the development and testing stage you can predefine or explicitly make it 3000 or another valid number like 9000. Then last but not least before the dive, we have the <strong>request </strong>library designed to implement simple HTTP requests. Now here are the steps of setting it up and getting it up and running.</p><p>First I enable CORS by telling my <em>app </em>server instance to use it by calling the use function on the server instance. I then have app listen at the port that i previously defined with a callback function to log the fact that my server was running thing and things were ready to take place. Then my app gets the query params from the frontend(made with React.js) and get the location property out of the query and save it to the variable. Then an api request is made to the external MaqQuest api using the location variable and the relevant key from my list of environment variables to convert the location text into a set of lat/lng coordinates. It comes in from the api and is converted to a JSON response object and they relevant keys are extracted and put into the lat/lng array defined earlier in the project.</p><p>In the final step I make another external api request to the DarkSky API using the array of lat/lng coordinates and its relevant api key from the list of environment files. As a result the body of the request is then sent the link of localhost and the port that was defined(in this case localhost, but if deployed then the url created via hosting site) where the frontend has access to fetch the relevant information and display to the client/user. Here is the live example of the server with the frontend weather widget: <a href="https://blitzweatherapp.herokuapp.com/">https://blitzweatherapp.herokuapp.com/</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25af8c4551b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Arrays vs. Linked Lists]]></title>
            <link>https://medium.com/@jamesjacobthomas7/arrays-vs-linked-lists-9b55e45b9ecc?source=rss-850b5c14102c------2</link>
            <guid isPermaLink="false">https://medium.com/p/9b55e45b9ecc</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[James Thomas]]></dc:creator>
            <pubDate>Thu, 21 Feb 2019 12:43:31 GMT</pubDate>
            <atom:updated>2019-02-21T17:56:54.895Z</atom:updated>
            <content:encoded><![CDATA[<p>When storing elements in a collection on a computer, two data structures come to mind; an <strong>Array</strong> and a <strong>Linked List</strong>. And while at first glance it may be ok to you either or, they have certain nuances that characterize them, with advantages and disadvantages all the like. Let’s explore them.</p><p>Let’s start with the more and more widely used, an <strong>Array. T</strong>he array is a collection of elements that is stored contiguously (right next to each other) in memory. So if you have a collection of 5 elements, then space is allocated for those 5 spots for your array. The problem comes when you need add more elements. If you wanted to add more elements to your array, your computer has to designate a different chunk of memory for your array and has to do that every time an element is added. This makes adding elements to an array slow and inefficient. To work around this you can try and ask your computer to reserve some memory for future additions, however if you don’t end up using the allocated memory, it becomes a waste because it can’t be used for anything else.</p><p>On the bright side, you know the address and location of every element of an array because they are right next to each other. This allows for instant look up times to find the element that you’re looking for. This makes arrays great and is known as random access (accessing any random element in the collection).</p><p>Now let’s talk about <strong>Linked Lists</strong>. Linked lists are also collections of data stored on your computer but unlike their array counterpart, can be stored anywhere in memory, in any position or order. A bunch of random memory addresses are linked together. Adding an item to a list is simple; stick it anywhere in your computer’s memory and give its address to the previous element in the list. The items never have to be shifted around as long as there is memory available, items can be added to the list.</p><p>And just like arrays, it has its disadvantages. For example, if you wanted to look up the last element in the list, you have to go through the list from top to bottom to get the address of the last item. With linked lists you don’t know all of the addresses for all the elements in the collection, only for the next immediate one. Linked Lists are good for reading one at a time but not if you want to jump around different elements in a random order. If you wanted to insert or delete elements it’s also infinite easier, all that needs to be done is change the memory of the element that comes before the element deleted/inserted. A real life example would be at restaurant.</p><p>In terms of Big O time, for Arrays:</p><ul><li>Reading: O(1)</li><li>Insertion: O(N)</li></ul><p>and for Linked Lists:</p><ul><li>Reading: O(N)</li><li>Insertion: O(1)</li></ul><p>Insertions and Deletions are O(1) time only if you can instantly access the element to be deleted. In linked lists it’s common to keep track of the first and last elements, so those two elements have instant lookup time.</p><p>Now when should you use which one? Let’s break it down into some real life examples. Suppose I need to run a binary search on a collection. First in working with an array, let’s assume that it’s sorted from the get go. That’s fine and dandy but what happens if I need to add elements to the array? Once I add it to the end of the array, binary search won’t work as well, due to the fact that I have to sort the array every time. This slows binary search down by a great deal. Inserting elements into arrays is already slow due to the fact that they have to be shifted completely to a different chunk of memory and the fact they must be sorted again doesn’t help. It might better to use a linked list in this case.</p><p>Now say that we are at restaurant where the waiter takes orders and add’s it to the current queue that has been setup. We then have the chef take off one order at a time in order and the cycle goes on. We can also shift up</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9b55e45b9ecc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What is Webpack?]]></title>
            <link>https://levelup.gitconnected.com/what-is-webpack-4fdb624597ae?source=rss-850b5c14102c------2</link>
            <guid isPermaLink="false">https://medium.com/p/4fdb624597ae</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[James Thomas]]></dc:creator>
            <pubDate>Thu, 24 Jan 2019 03:15:16 GMT</pubDate>
            <atom:updated>2019-01-25T15:07:31.026Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are building a modern JavaScript application, you have likely heard the term “webpack” mentioned before. Webpack is a static module bundler for JavaScript applications — it takes all the code from your application and makes it usable in a web browser. Modules are reusable chunks of code built from your app’s JavaScript, node_modules, images, and the CSS styles which are packaged to be easily used in your website. Webpack separates the code based on how it is used in your app, and with this modular breakdown of responsibilities, it becomes much easier to manage, debug, verify, and test your code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SVyedUtyXmpDcJaXuiZNRg.png" /><figcaption>Dependency Graph with Webpack</figcaption></figure><p>When Webpack processes your application, it builds a dependency graph which maps out the modules that your project needs and generates one or more <strong>bundles</strong>. A bundle is a distinct grouping of connected code that has been compiled and transformed for the browser.</p><p>If one file depends on another (it uses the code from a separate file), Webpack treats this as a dependency. Webpack also takes your non-code assets (images, fonts, styles, etc.) and converts them to dependencies for your application.</p><p>Webpack can be broken down into these 5 principals:</p><ul><li>Entry</li><li>Output</li><li>Loaders</li><li>Plugins</li><li>Mode</li></ul><p><strong>Entry </strong>is the entry point for the application. It is the first module (JavaScript file)that Webpack will process to build out the full dependency graph. It will look at the files that are imported into the entry, and these are added to the dependency graph. It then continues to walk through all the imported files until it has accounted for all the code needed to run the applications.</p><p>Webpack figures out which other modules depend on the entry point, both directly and indirectly. The default entry point in modern JavaScript applications is <strong>./src/index.js, </strong>but it can be set to any file of your choosing. It is also possible to have multiple entry points. Here are some examples of designating entries:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*agqHggQOS4l-0G11WBObbw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ij73y3nJZpcysJU5AUR0Jw.png" /></figure><p>Multiple entry points are specifically for multi-page applications. With the example above, you are telling Webpack to create three separate dependency graphs. It fetches a new HTML document with new assets. This allows for maximizing reusable code throughout the different pages of an application, making it more optimized.</p><p>The <strong>Output </strong>point is where the files are to be written on disk with thename of the files. The main output file is written as <strong>./dist/main.js </strong>and any other files are added to the <strong>dist </strong>directory. The output is set at the same location as the entry point. The output can also use hash or chunk names for the content, allow it to be dynamically updated when the code changes. This ensures you are able to serve the correct code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w1tgedsOBaZpAX3fXK6ppA.png" /></figure><p>By default, Webpack only knows how to process .js or .json files, which can be limiting. With <strong>Loaders</strong>,<strong> </strong>Webpack can extend functionality to process other file types by converting them into modules for your application.</p><p>The loaders are specified in the module key under rules. There are 2 configuration options required to add a loader — <strong>test </strong>which identifies file or file types should be transformed and <strong>use </strong>which tells Webpack which loader to use in order to transform these files. It looks like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZfsqRl_3RcPFOJqTl_-bNQ.png" /></figure><p>Loaders can also be used inline with import statements as well through a command line.</p><p><strong>Plugins </strong>handle the additional tasks that can’t be completed by a loader. This includes things such as bundle optimization, defining environment variables, etc. Another example would be extracting a style sheet or generating an index.html file for a single page web application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Up6rF0uyn0KD0o3pWqYag.png" /><figcaption>Serving up a new index.html page for single page web app</figcaption></figure><p><strong>Mode </strong>tells<strong> </strong>Webpack which configuration and optimizations to use for your application. This triggers some mode-specific plugins for Webpack that are built into Webpack, building it for the correct environment. The modes are <strong>development, production, or none. </strong>If mode is not specified, then Webpack automatically defaults to production.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yc0elhQmZg4nLT0crvZKLQ.png" /></figure><p>Development optimizes for faster build times and code readability for debugging. Production optimizes for the smallest build possible, requiring a longer build time to parse and shrink the code.</p><p>The last thing you should be aware of is browser compatibility. Currently, Webpack is set to support browsers that are compatible with ES5 and above.</p><p>Hopefully, with this small introduction, you can start to tinker with your Webpack configuration and create a setup that is ideal for you and your JavaScript web application workflow.</p><figure><a href="https://levelup.gitconnected.com/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E6CoI_MRyZ1JInNPsBSHtA.png" /></a></figure><p><a href="https://gitconnected.com/learn/webpack">Learn Webpack - Best Webpack Tutorials (2019) | gitconnected</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4fdb624597ae" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/what-is-webpack-4fdb624597ae">What is Webpack?</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CORS]]></title>
            <link>https://medium.com/@jamesjacobthomas7/cors-a84f3624988e?source=rss-850b5c14102c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a84f3624988e</guid>
            <category><![CDATA[api]]></category>
            <category><![CDATA[cors]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[James Thomas]]></dc:creator>
            <pubDate>Thu, 17 Jan 2019 05:09:45 GMT</pubDate>
            <atom:updated>2019-01-17T06:35:25.333Z</atom:updated>
            <content:encoded><![CDATA[<p>When you visit a website or building one, you may see lots of information populated from different resources. If these resources are not properly cleared, the site could have a potential security risk, such as loading malicious code from a suspicious resource or hijacked completely.</p><p>Most servers have one of two types of security policy, Same-Origin or CORS. Same-Origin is very restrictive and only allows for resources from the same server. It doesn’t allow for external resources to be loaded in and enforces that resources only interact with each other on the webpage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bG6QaoPsYuVvvGeSsHgJuw.jpeg" /><figcaption>Same-origin policy</figcaption></figure><p>If you ever worked with external web apis, you have probably come across this acronym before. CORS stands for Cross-Origin-Resource-Sharing. It’s a request for a resource (like an image or font, or some kind of data) from an external source like an API. Websites often seek resources from other areas to populate the current page. CORS opens up the possibility to loading in many different resources from many different resources to provide more depth for the webpage. However with these new possibilities, there needs to be a way of handling these foreign requests in a secure fashion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0AOuwLcJv_92qnisNJsIgg.jpeg" /><figcaption>Cross-Origin policy</figcaption></figure><p>One way would be through authentication. CORS would implement a protocol called an HTTP header. The header is a piece of information with that is passed along with a response or request. CORS manages requests by adding these headers to the standard list of headers. Here are some examples of CORS headers</p><ul><li>Access-Control-Allow-Origin (Indicates whether the response can be shared) This is for a request without credentials and tells the browser to allow any origin to access the assets on the server</li><li>Access-Control-Allow-Credentials (Indicates whether or not the response to the request can be exposed when the credentials flag is true.) This is for making a request that requires credentials such as Cookies, TLS Certificates, or authorization headers</li><li>Access-Control-Allow-Headers (Used in response to a preflight request, which is made before the original request and uses the Options header, determining if the request is safe, and indicates whether the HTTP headers can be used)</li><li>Access-Control-Allow-Methods (Specifies the method or methods allowed when accessing the resource in response to a preflight request)</li><li>Access-Control-Expose-Headers (Indicates which headers can be revealed as a response by listing their names) By default the six headers that are exposed are <strong>Cache-Control, Content-Language, Content-Type, Expires, Last-Modified, and Pragma. </strong>If you want to expose other headers then they must be specified using this header</li><li>Access-Control-Max-Age (Sets how long the results of a preflight request can be cached)</li><li>Access-Control-Request-Headers (Used when sending a preflight request to make the server aware of what HTTP headers will be used when the actual request will be made)</li><li>Access-Control-Request-Method (Used when sending a preflight request to make the server aware of what Request method will be used when the actual request is made)</li><li>Origin (Indicates where the fetch came from but doesn’t include the path name, only the server name) Sent with CORS requests as well as POST requests</li></ul><p>The implementation of CORS depends on the language or framework of the backend. Here’s a simple example using Express:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g8Atop76FcHENDtE3Zqwtg.png" /></figure><p>Here I am allowing this Express endpoint to be accessed from any origin in development after setting the port to 3000</p><p>With CORS the webpages you view and create allow for many different resources to load in and provide depth for the user.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a84f3624988e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Binary Search Algorithm]]></title>
            <link>https://medium.com/@jamesjacobthomas7/binary-search-algorithm-7a637325457b?source=rss-850b5c14102c------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a637325457b</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[binary-search]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[James Thomas]]></dc:creator>
            <pubDate>Thu, 10 Jan 2019 04:52:31 GMT</pubDate>
            <atom:updated>2019-01-10T05:46:23.199Z</atom:updated>
            <content:encoded><![CDATA[<p>When I started to dive in the deep and complicated world of computer science, I was very intimidated by what was in front of me and the vast depth of it all. One of the first things I learned about was the Binary Search Algorithm.</p><p>You see when we write algorithms or sets of instructions for our computer to perform, ideally we want it to run as efficiently and as quickly as possible. One example would be a search algorithm. For our purposes the algorithm will just be a query for a single element inside a sorted collection. A good example would a phone book query. You are looking for an individual inside a phone book and you are hoping that the name exists inside the phone book. If the person does exist inside the phone book, then you have their phone number or <strong>position </strong>inside the book. Now there are two ways you can go about this; a simple search or using our new tool, Binary Search.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*cAKBKo9ErpUtHBtOwsXbuQ.gif" /></figure><p>Let’s start with the simple search. If you had no time constraints and you had no clue on how to go about finding this person in this gigantic rolodex of entries. You would have go an iterate through each element of the collection, one at a time until you found the person you are looking for… . That would be terrible, the chances of you finding that person in a timely fashion are slim to none. Best case scenario, it might be the first person or the person might be on of the first few pages, but worst case would be that the it’s the last person on the <strong>LAST</strong> page. So it’s really up in the air and as the collection of elements get larger the longer it will take for the query to complete. Here’s a code snippet to kind of illustrate how it goes down</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O5b0y6HlVC33cEtfCijBHg.png" /><figcaption>Not the most ideal if the collection gets large enough</figcaption></figure><p>Now let’s try the binary search. With binary search, the key is the sorted collection. With the collection sorted binary search really shines through as the better method to find the person in the phone book. With Binary Search, you guess the middle number or element in the collection and eliminate one half of the collection whether the element was too large or too small. Then you repeat the process and continuously narrow down the collection, guessing a new middle element in the newly shortened collection and narrowing it down until you find the element and position in the collection.</p><p>Here’s the code snippet:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qyuo7fsEr_Kstkc3Tqb90Q.png" /><figcaption>Binary Search</figcaption></figure><p>It seems like a lot is going on but with this method, you’re actually making it much easier to find what your looking for and find it in record time. You assign a low and high value and change those consistently as the collection gets smaller and assign a new middle value as a result. Then you check to see if that new middle value is the same as the element you’re looking for and return the middle number. Otherwise reassign new high, low, and middle values and start it again. The sorted collection makes it simple to reassign a new middle value every time.</p><p>Now that you’ve seen both methods, I hope that if you need to write a simple search algorithm that you do it with binary search rather than going through every element one at a time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a637325457b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WebSockets and How I Used Them (A quick glance)]]></title>
            <link>https://medium.com/@jamesjacobthomas7/websockets-and-how-i-used-them-a-quick-glance-37899b697852?source=rss-850b5c14102c------2</link>
            <guid isPermaLink="false">https://medium.com/p/37899b697852</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[actioncable]]></category>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[James Thomas]]></dc:creator>
            <pubDate>Wed, 14 Nov 2018 02:22:43 GMT</pubDate>
            <atom:updated>2018-11-14T02:49:25.713Z</atom:updated>
            <content:encoded><![CDATA[<h3>WebSockets and How I Used Them</h3><p>It goes by many names; WebSockets, The WebSocket Protocol, and The WebSocket API. From your preferred messaging application to a popular online multiplayer game, WebSockets are crucial and implemented in some of today’s most used web applications.</p><p>A WebSocket, by definition, is a computer communications protocol providing a full-duplex (communication in both directions) communication channels over a single TCP connection. This WebSocket API makes two-way communication possible between the user’s browser and a server. The user can send messages to the server and receive event-driven responses without having to poll the server. It can have multiple users connect to the same live server and communicate and get responses back instantly with the API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*4xt1KHVnm2T84AmSL58N2g.gif" /></figure><p>WebSockets allow for a streaming connection between a user and a server and allow for instant information exchange. In the example of a chat application, with messages being funneled through the socket, you exchange with one or multiple users in real time, depending on who is “listening” (connected) on the server.</p><p>WebSockets are not only limited to chat/messaging applications. They are applicable to any application that needs live updating and instantaneous information exchange. Some examples include but not limited to: live sports updates, stock tickers, multiplayer games, chat applications, social media feeds, so on and so forth.</p><p>WebSockets also account for hazards such as proxies and firewalls making streaming possible on any connection. It supports the upstream and downstream communications over a single connection. It also places less burden on servers, allowing existing machines to support simultaneous connections.</p><p>Here’s an example implementation WebSockets in a modern web application. In the example below, I used WebSockets for an instant messaging application with a Rails 5 API backend and a React.js Frontend. This is by no means a guide but rather an example of how it COULD be used. I used Action Cable, a wrapper for Rails that seamlessly integrates the prime features of WebSockets in Ruby and allows for easy implementations across a full domain model. It’s built into Rails 5.2, so there’s no need for any external libraries or gems to install/execute.</p><p>It works on the principle of Pub-Sub (publishing and subscribing). It works with senders sending data (publishers) to an abstract number of recipients (subscribers) without specifying who they are.</p><p>The first step was to mount the server in your routes file so that your frontend gets an endpoint to stream from:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qkfzF_fTtAPIhTF_aRxCow.png" /><figcaption>On line 5, I setup the ActionCable server endpoint</figcaption></figure><p>The next step was to create a channel on the backend to stream the messages as they are being created in real time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*htPGaUjiy-kww4EW6J6QFg.png" /><figcaption>Here is the messages channel that manages message creation as well as broadcasting the message</figcaption></figure><p>Here we have two methods, subscribed and received. The first method, subscribed, allows the messages channel to be streamed to the connected users, or the subscribers. The second method, received, manages message creation and broadcasting the message. I implemented JWT user authentication so that the messages can be traced back to the user and only those with valid user accounts can create a message.</p><p>For the frontend of my application I used them npm package <a href="https://www.npmjs.com/package/actioncable"><strong><em>actioncable</em></strong></a><strong> </strong>to connect to the WebSocket API from client side to server side. This package is directly from the team that works on Rails. With this library, I instantiate an instance of <strong>cableApp </strong>and pass it down as props to the component that needs access to the WebSocket connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0FhQxxeX-_AmrC_C25aKOA.png" /><figcaption>Imported actionCable and created a cableApp instance, then connected the cableApp to my backend endpoint “/cable” and passed it down to the component that needed the connection</figcaption></figure><p>I then wired in the connection to the WebSocket through a React.js lifecycle method <strong>componentDidMount</strong>() and established a connection every time the component was mounted to the DOM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dtvP_4eLQOczYV1vRRvDRA.png" /><figcaption>In componentDidMount() I established the client to connect to the WebSocket protocol which is streaming from the “messagesChannel” from my Rails API.</figcaption></figure><p>Now every time a message is created and sent to the <strong>receive</strong> method, the subscribe(d) users will instantly receive and be able view the message in real time. This implementation supports multiple users subscribed to the same channel. So if multiple users are signed and subscribed to the same channel they can send messages that all the subscribers will be able to see as well as receive messages from other subscribers. Of course you could limit it two people and make it peer to peer but where’s the fun in that.</p><p>I hope that by reading this you can see the potential of WebSockets. It provides itself as a valuable resource in a day and age in which information exchange needs to be done very quickly. Hopefully you as the reader will implement them in a project of your own.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37899b697852" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>