<?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 Joshua Holmes on Medium]]></title>
        <description><![CDATA[Stories by Joshua Holmes on Medium]]></description>
        <link>https://medium.com/@joshua.phillip.holmes?source=rss-43e2daea35c7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*AeTz8WpcWMs3p2J_-66M1Q.jpeg</url>
            <title>Stories by Joshua Holmes on Medium</title>
            <link>https://medium.com/@joshua.phillip.holmes?source=rss-43e2daea35c7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 11:45:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@joshua.phillip.holmes/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[Fixing “Error parsing triggers: Cannot find module ‘./logger’” in Firebase CLI]]></title>
            <link>https://medium.com/@joshua.phillip.holmes/fixing-error-parsing-triggers-cannot-find-module-logger-in-firebase-cli-1f4ad8e497d4?source=rss-43e2daea35c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f4ad8e497d4</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[npm-package]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[firebase-cloud-functions]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[Joshua Holmes]]></dc:creator>
            <pubDate>Mon, 04 Apr 2022 17:17:56 GMT</pubDate>
            <atom:updated>2022-04-04T17:17:56.610Z</atom:updated>
            <content:encoded><![CDATA[<p>When deploying a function to Firebase using $ firebase deploy --only functions:myNewFunction, I came accross the following error:</p><pre><strong>Error:</strong> Error parsing triggers: Cannot find module &#39;./logger&#39; <br>Require stack: <br>- /home/josh/Development/MyProject/Firebase/functions/node_modules/firebase-functions/lib/cloud-functions.js <br>- /home/josh/Development/MyProject/Firebase/functions/node_modules/firebase-functions/lib/providers/analytics.js <br>- /home/josh/Development/MyProject/Firebase/functions/node_modules/firebase-functions/lib/index.js <br>- /home/josh/Development/MyProject/Firebase/functions/index.js <br>- /usr/lib/node_modules/firebase-tools/lib/deploy/functions/runtimes/node/triggerParser.js <br> <br>Try running &quot;npm install&quot; in your functions directory before deploying. <br> <br>Having trouble? Try <strong>firebase [command] --help</strong></pre><p>The error clearly gives a solution, which is to run $ npm install in my /home/josh/Development/MyProject/Firebase/functions directory. However, after performing this task and returning to my original Firebase deployment function, I get the same message.</p><h3>The Solution</h3><p>I returned to the output of my $ npm install command and found this message, which I am all too familiar with:</p><pre>npm WARN EBADENGINE Unsupported engine {<br>npm WARN EBADENGINE   package: undefined,<br>npm WARN EBADENGINE   required: { node: &#39;14&#39; },<br>npm WARN EBADENGINE   current: { node: &#39;v17.8.0&#39;, npm: &#39;8.5.5&#39; }<br>npm WARN EBADENGINE }</pre><pre>up to date, audited 299 packages in 2s</pre><pre>43 packages are looking for funding<br>  run `npm fund` for details</pre><pre>20 vulnerabilities (9 moderate, 11 high)</pre><pre>To address issues that do not require attention, run:<br>  npm audit fix</pre><pre>To address all issues (including breaking changes), run:<br>  npm audit fix --force</pre><pre>Run `npm audit` for details.</pre><p>I followed the instructions of this output by <strong>running</strong> <strong>$ npm audit fix --force</strong> <strong>in my functions directory</strong> (same directory I ran $ npm install in earlier). After this was done, rerunning my Firebase deployment command worked!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f4ad8e497d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker Template: Ruby on Rails with PostgreSQL]]></title>
            <link>https://blog.devgenius.io/docker-template-ruby-on-rails-with-postgresql-db2cc2d31a3f?source=rss-43e2daea35c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/db2cc2d31a3f</guid>
            <category><![CDATA[containerization]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Joshua Holmes]]></dc:creator>
            <pubDate>Mon, 31 Jan 2022 21:20:46 GMT</pubDate>
            <atom:updated>2022-02-08T18:52:22.675Z</atom:updated>
            <content:encoded><![CDATA[<h3>What Is This?</h3><p>This is a project that serves as a template to allow you to toss your Ruby on Rails (can optionally include React frontend) application into a folder, configure a few settings, then quickly have a containerized app with its own contained environment using Docker! From there, the app can be deployed on a VPS (Virtual Private Server) with almost no environment configuration. Using Docker also makes it easier to manage multiple apps running on the same VPS, which makes it very cost-effective when you have more than a few apps deployed. This template aims to make Docker as easy to setup as it is to use!</p><h3>How Do I Use It?</h3><p>To use this template, go to this project’s <a href="https://github.com/joshua-holmes/docker-template-ruby-on-rails">GitHub page</a>, clone it to your local machine, then follow along with the instructions, either here on this blog, or on GitHub! Both sets of instructions are identical.</p><h3>Instructions: Speedy Version!</h3><p><em>Note: If you are using React Router Dom with your app, please visit that section below, as there are a few extra steps for deployment. The steps are not Docker specific. It would be the same steps, regardless of the deployment method.</em></p><ol><li>Copy and paste your Ruby on Rails application (or make a new one) inside ror/ so that ror/ is the root directory of your RoR app. React frontend is optional.</li><li>Run bin/dockerize -p &lt;PORT_NUMBER&gt; in your project’s local root directory where &lt;PORT_NUMBER&gt; is a port number you want your Docker Container to run on. Type y or press enter when prompted to overwrite. This step will preserve database names and will not overwrite them, but will overwrite other settings. If you have custom settings in ror/config/database.yml, other than database names, press n instead and follow the instructions in yellow. Here is an example: bin/dockerize -p 3001</li><li>Upload your project to GitHub and then pull it down onto your server. Now in your project’s server repo, run bin/server-setup -p &#39;&lt;DB_PASSWORD&gt;&#39; -m &lt;MASTERKEY&gt;. The masterkey is found in your local project repo: ror/config/master.key. The password is your database password and you are creating a new one here. <strong>Notice</strong> the password is wrapped in single quotes. That is to prevent bash from trying to interpret special characters, such as &#39;$&#39;. <em>Optionally</em>, you can also add a username for your database with the -u flag. Here is an example of the entire command:</li></ol><pre>bin/server-setup -u username -p &#39;YourNewSecureP@$$w0rD&#39; -m fakeMasterKey1234abcd5678efgh</pre><h3>Instructions: Manual Version (good for learning)</h3><ol><li>Copy and paste your React on Rails application (or make a new one) inside ror/ so that ror/ is the root directory of your RoR app.</li><li>In .docker/ copy the example.env file into the same directory and rename it .env. You do not need to change any variables here in your local repository, but you will need to configure this file on your server repo.</li><li>Copy and paste the contents of .docker/example.database.yml into ror/config/database.yml and replace the contents inside, being careful of any database configurations you have already set for your project (if any). Preserve the database names from your original file if one of the databases has data that needs to be preserved on your local machine for development.</li><li>Open docker-compose.yml file in this project&#39;s root directory and change the first port number only, to specify which port you want your app to run on. For example change it to &quot;4000:3000&quot; if you want to run the app on port 4000. Do not change the second number.</li><li><em>Skip this step if you do not have a React frontend!</em> If you want to test your dockerization locally, open your terminal in the root directory of your project and enter bin/build-frontend. Then run sudo docker compose up --build. Keep in mind that, when it is done loading, the port displayed in your terminal is the internal port number, not the external one. That means that if you set your port to 4000 in the previous step, the terminal will still display port 3000. In this case, you would ignore the terminal and visit port 4000 by going to <a href="http://0.0.0.0:4000/">http://0.0.0.0:4000</a> and your app should be up.</li><li><strong>Your app is now Dockerized!!</strong> Visit the ‘Operation Instructions’ section below to read about how to get the app on your server and run Docker Compose, if you have never used it before.</li><li>You can now upload your app to GitHub and then pull it down onto your server. Once on your server, go to .docker/ directory in your server project repo and repeat step 2 above. This time, choose a secure password and set the correct variable to your chosen password. Be sure the password is wrapped in single quotes, as shown in the example file.</li><li>Now copy the master key from your local repo in ror/config/master.key and paste that key either into ror/config/master.key on your server repo, <em>or</em> uncomment the RAILS_MASTER_KEY variable in the .docker/.env and paste the key in that line in on your server repo.</li></ol><h3>Operating</h3><p><strong>You can run your app now!!</strong> Make sure Docker and Docker Compose are installed on your server, then <strong>run </strong><strong>sudo docker compose up --build -d</strong> from your project&#39;s root directory to build the image on your server and run your app. To see your app, <strong>visit </strong><strong>http://&lt;YOUR_SERVERS_PUBLIC_IP&gt;:&lt;PORT&gt;</strong>. To take down your app, run sudo docker compose down. If your app is running and you&#39;ve made changes to it and want to update the app on the server, I&#39;ve included a useful script that will automatically run git pull, bring your app offline, rebuild the Docker image, and bring it back online, all in one command! <strong>Simply run </strong><strong>bin/update-app</strong> from the root directory of your project.</p><p>When you update your app, make sure you run bin/build-frontend on your local repo <em>before</em> pushing it up to GitHub and updating your server. RoR&#39;s static frontend files go with the rest of your project via git, and the reason for that is because it is not likely that your server has the npm package manager, which is required to build the frontend.</p><p><strong><em>Warning:</em></strong> <em>When you run your app, the command line will tell you it is running on port 3000, even if this is not true. Just don’t fall for it’s tricks and visit the port you specified earlier. It is referring to the internal Docker port, not the external one which is the one you use when you visit your app.</em></p><p><strong><em>Another warning:</em></strong> <em>You may need to enable the port on your server firewall before being able to view the app by directly typing in the IP address and port in your browser. If you use Nginx or Apache, changing firewall settings will not be necessary because all traffic typically comes in through port 80 or 443, then is redirected to your app’s port internally.</em></p><h3>Where To Go Next</h3><p>If you are new to VPS server deployment and are wondering how you get your domain name connected, and more, here are some next steps to look into:</p><ol><li>Buy a domain from Name Cheap or Google Domains. Usually this is around $10-$12 per year.</li><li>Go into the DNS settings and create an A record that points to your server’s public IP address (the IP should be provided by your server platform provider. Usually it’s in your web portal after you login.).</li><li>Install a routing software like Nginx to forward requests to the appropriate port that your app is running on.</li><li>Install Let’s Encrypt on your server to install an SSL Certificate so your server can accept HTTPS and so your browser sees your site as safe.</li></ol><h3>Explanation</h3><p>This is an explanation of the steps taken above and is more for your education than it is necessary to read.</p><h4>Going over the steps in the Manual Version</h4><ol><li>The ror/ directory stands for Ruby on Rails or React on Rails. Your React app should then be inside the client/ folder inside of your ruby app directory.</li><li>The .docker/.env file contains environment variables that get set in your Docker Container. These variables are loaded into both the database’s container and the app’s container. By sharing the same environment variables, they can share useful information, like the database’s password, active user and the Rails environment. The master key is also stored here. This master key is used for encrypting data and should not be public, which is why git ignores it and also why you must manually load the master key onto the server’s repo, even though your local repo already has it. Rails is able to view the master key when it is stored in either the .docker/.env file as an environment variable, or in it&#39;s own master.key file in the ror/config/ directory. Either option works for Rails, so how you store the key is entirely up to you. If you need to generate a new one, delete ror/config/master.key and ror/config/credentials.yml.enc, then run rails credentials:edit command in your Rails directory. That will generate a new master.key file, but will also recreate the credentials file. Since the credentials file is uploaded via git (which is a good thing), be sure that you update all other repos after issuing that command. The master.key file is ignored by git (which is also a good thing), so don&#39;t expose that file publicly.</li><li>The ror/config/database.yml file is a configuration file for you database. In order for it to work with Docker, there are a few modifications that need to be made: A host needs to be specified and a username and password needs to be required and passed in, for security. Anything enclosed in &lt;%= %&gt; is actually ruby code. The username and password use ENV[&quot;VAR&quot;] instead of ENV.fetch(&quot;VAR&quot;) to fetch environment variables because the first option returns nil if the variable is not found, while the second one throws an error. By using the first option for username and password, it allows the username and password to be optional, since those environment variables will be established in the Docker Container (via the .docker/.env file), and are not likely established on your computer. Essentially, a password is not required when you are running it locally, but is required when it is running on your server through Docker. Similar story with the host key. If the POSTGRES_PASSWORD environment variable is not found, the program assumes that you are on your local machine and does not need to specify a host. But when the database and app are running through separate containers, a host name is needed.</li><li>The docker-compose.yml file is where docker compose gets it&#39;s instructions to build and run your app. Probably the most important part of this file is the port number. To adjust the port number that the app is running on, you must change the first of the two numbers. So entering &quot;4000:3000&quot; would run the app on port 4000. The reason the second number can&#39;t be changed is because that number is specifying the internal port number. This is the port number that Rails is technically running on inside the Docker Container, but then Docker forwards this internal port to an external port, which can be accessed outside the container. This external port number is the first number (port 4000 in my example case above). Inside this file, you can also see things like the env_file key, which is where the .env file is referenced, which contains the environment variables for the container. Additionally, the dockerfile key-value pair points to the Dockerfile, which contains instructions on how to build the app. Feel free to open that up and take a look if you are curious.</li><li>There are more custom scripts located in the bin/ folder. Feel free to open them up with a text editor to see what&#39;s inside! Keep in mind, these are bash scripts, not ruby scripts.</li><li>Once the app is dockerized, it can be taken to the server to be deployed.</li></ol><h3>FREE Knowledge! (A.K.A. tips and FAQs)</h3><h4>Using React Router Dom?</h4><p>This forwards all unknown GET requests to fallback#index, which returns your React app. Without these steps, refreshing the page while on any page except the home page will result in a 404 error. This error is not Docker-specific, but instead is React on Rails-specific when using React Router Dom.</p><ol><li>Create a controller called fallback_controller.rb in ror/app/controllers/ and paste this code in:</li></ol><pre>class FallbackController &lt; ActionController::Base<br>  def index<br>    render file: &#39;public/index.html&#39;<br>  end<br>end</pre><p>2. Open the routes file, found in ror/config/routes.rb, and add this line - get &quot;*path&quot;, to: &quot;fallback#index&quot;, constraints: -&gt;(req) { !req.xhr? &amp;&amp; req.format.html? } - to the bottom of the main code block so it looks something like this:</p><pre>Rails.application.routes.draw do<br>  ...<br>  get &quot;*path&quot;, to: &quot;fallback#index&quot;, constraints: -&gt;(req) { !req.xhr? &amp;&amp; req.format.html? }<br>end</pre><h4>Docker tips &amp; commands</h4><p><em>TIPS</em></p><ol><li>Docker commands should always be run with sudo because the Docker daemon is being run with admin priviledges. There is a way to get around it, but to me it just seems easier to use sudo. Feel free to Google around if that&#39;s the direction you want to go.</li><li>Some installations of Docker Compose come with an alias, allowing you to use the docker-compose command instead of docker compose. Others do not, so I use docker compose in this instructional set, as well as in my custom bash scripts.</li><li>A Docker Image is like a screenshot of your app with it’s environment included. The image even includes it’s own Linux distro and file system. However, since it is a screenshot, the original cannot be modified. If you make a change, you must take a new screenshot.</li><li>A Docker Container runs a Docker Image. It allows code to be stored in memory so your app can be dynamic. It is similar to a virtual machine, but instead of the environment being stored in the VM, it is stored in the image. Containers are much more performant than VMs.</li><li>A Docker Volume is a way of syncing data between a specified folder on your container with a folder on your local machine. The reason these are necessary is because, remember, data cannot be persisted to Docker Images, since images cannot be modified. Since this is the case, the Docker Container stores the data in memory and syncs it with a folder on the local machine, so when the docker is shut off, the data can be accessed next time a connected container is run. The best use for these volumes is to persist data in a database. In this project, the database in the Docker Container is syncing with our project folder .docker/volumes/database/. If this data is ever needed to be accessed in the future, that is where you can find it.</li><li>A Docker Network ties two or more Docker Containers together and allows them to interact with each other. In the example app included with this project, the PostgreSQL database is running in a container, and the RoR app is running in a seperate container. They are able to communicate with each other through the Docker Network.</li><li>Docker Compose is a solution for allowing you to configure Docker settings in a YAML file, instead of typing those settings in the command every time you run a container. For example, after specifying the port, environment variables, network, and more, the command to run my container might look like this: sudo docker -p 3000:3000 -e POSTGRES_USER=rails -e POSTGRES_PASSWORD=1234 -e RAILS_ENVIRONMENT=production --network host ... etc, etc. By placing my settings in a YAML file, Docker Compose can read the file and apply those settings automatically.</li></ol><p><em>COMMANDS</em></p><p><em>Note: When using </em><em>docker compose commands, be sure you are in the root directory of the project you want to manipulate. Docker Compose uses the </em><em>docker-compose.yml file in the root directory to know which containers to apply your commands to.</em></p><ol><li>sudo docker compose build will build a docker image with your app in it and save it to a mysterious directory on your computer. Images <em>do not ever change</em>, so anytime you update your app, you must build a new image to replace the old. This command can be used for that. Everytime you build an image, it replaces the old automatically.</li><li>sudo docker compose up will take the image built from the directory you are in and run it on the port specified in the docker-compose.yml file! If you add the --build flag, it will build a new image first, then run that image. It essentailly functions like sudo docker compose build immediately followed by sudo docker compose up. If you add the -d flag, it runs your app in the background, so you don&#39;t need to stare at a terminal the whole time your app is up. My favorite command to use when updating my app on my server is sudo docker compose up --build -d because it builds my app, then runs it in the background.</li><li>sudo docker compose down will take your app offline.</li><li>sudo docker ps will show you all containers that are online and listening on one of your ports. sudo docker ps -a will show you all containers that are online <em>or</em> offline.</li><li>sudo docker images will show all images saved on your system.</li><li>sudo docker stop &lt;CONTAINER_ID&gt; takes a container offline, using the container&#39;s ID.</li><li>sudo docker rm &lt;CONTAINER_ID&gt; deletes a container from your local storage. If you login to root using su and then typing your password, you can use docker rm $(docker ps -aq) to delete all containers on your system. Notice sudo is not used. That is because as root, you don&#39;t need sudo to elevate your privileges, since root already has highest privileges.</li><li>sudo docker rmi &lt;IMAGE_ID&gt; deletes an image from your local storage. <em>Before deleting images, make sure a container is not reliant on that image.</em> If you login to root using su and then typing your password, you can use docker rmi $(docker images -aq) to delete all images on your system. Notice sudo is not used here either.</li></ol><h4>General Tips</h4><ul><li>If you change the database username or password in the .docker/.env, the containerized app will fail to connect to the database in .docker/volumes/database. If this occurs during development and the database contents are disposable, simply delete the database folder using sudo rm -fr .docker/volumes/database from the project’s root directory. This will delete the databases and the data stored in them, allowing Docker to rebuild the databases with your new username and password.</li><li>If ror/config/master.key cannot be found, run rails credentials:edit inside ror/ to generate a new one.</li><li>If you need a new master key, delete ror/config/master.key and ror/config/credentials.yml.enc, then run rails credentials:edit inside ror/ to generate a new ones.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db2cc2d31a3f" width="1" height="1" alt=""><hr><p><a href="https://blog.devgenius.io/docker-template-ruby-on-rails-with-postgresql-db2cc2d31a3f">Docker Template: Ruby on Rails with PostgreSQL</a> was originally published in <a href="https://blog.devgenius.io/">Dev Genius</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Big O(n) to Big O(1)]]></title>
            <link>https://medium.com/@joshua.phillip.holmes/from-big-o-n-to-big-o-1-977dab1eda4a?source=rss-43e2daea35c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/977dab1eda4a</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[big-o-notation]]></category>
            <dc:creator><![CDATA[Joshua Holmes]]></dc:creator>
            <pubDate>Sun, 16 Jan 2022 19:19:02 GMT</pubDate>
            <atom:updated>2022-01-31T18:15:55.191Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a story about how I improved my project algorithm’s speed by 22%. I recently made a project that creates fake words. It inputs a collection of words, evaluates patterns in the set, and uses those patterns to generate a new word that does not exist in the original set. I cover my journey in making the app in another blog. In this blog, I explain how Version 1 of the algorithm worked and it’s problems. I also explain how I worked around those problems.</p><h3>How It Works</h3><p>My Version 1 Algorithm started by reading a set of words. Let’s use a set like this as an example:</p><pre>apple<br>banana<br>bagel<br>carrot<br>degrees<br>egg</pre><p>Using this set of words, the program is going to find a starting letter for the fake word we requested. It begins by counting how many times &quot;a&quot; starts a word, how many times &quot;b&quot; starts a word, etc. This function outputs an array like this with the results:</p><pre>[<br>    {&quot;letter&quot;: &quot;a&quot;, &quot;ratio&quot;: 0.17},<br>    {&quot;letter&quot;: &quot;b&quot;, &quot;ratio&quot;: 0.33},<br>    {&quot;letter&quot;: &quot;c&quot;, &quot;ratio&quot;: 0.17},<br>    {&quot;letter&quot;: &quot;d&quot;, &quot;ratio&quot;: 0.17},<br>    {&quot;letter&quot;: &quot;e&quot;, &quot;ratio&quot;: 0.17}<br>]</pre><p>According to the stats generated, &quot;a&quot; started a word 17% of the time in the given set of words, &quot;b&quot; started a word 33% of the time, etc. The program then selects one of the above letters at random, with a 17% chance of selecting &quot;a&quot;, a 33% chance of selecting &quot;b&quot;, etc. Let’s say, for this example, the letter &quot;e&quot; was selected by the computer. &quot;e&quot; is now the beginning of our computer generated fake word!</p><p>It now needs to pick a second letter. To do this, it now looks through the entirety of each word, instead of just the first letter. It also looks at combinations of letters that begin with our fake word, which so far is just &quot;e&quot;. So the program will now find every 2-letter combination that begins with &quot;e&quot;. The first appears in the word &quot;bagel&quot;, with an &quot;el&quot;. The second, third, and forth appear in the word &quot;degrees&quot;, with &quot;eg&quot;, &quot;ee&quot;, and &quot;es&quot;. Finally, the fifth occurrence appears in the word &quot;egg&quot;, with an &quot;eg&quot; again. The results of this evaluation are then shown in an array, just like above:</p><pre>[<br>    {&quot;letter&quot;: &quot;el&quot;, &quot;ratio&quot;: 0.20},<br>    {&quot;letter&quot;: &quot;eg&quot;, &quot;ratio&quot;: 0.40},<br>    {&quot;letter&quot;: &quot;ee&quot;, &quot;ratio&quot;: 0.20},<br>    {&quot;letter&quot;: &quot;es&quot;, &quot;ratio&quot;: 0.20}<br>]</pre><p>From the evaluation, &quot;el&quot; makes up 20% of the 2-letters combinations that start with &quot;e&quot; in the set of words, &quot;eg&quot; makes up 40%, and so on. From that, the computer will choose a random letter, as before, with a 20% chance of choosing &quot;l&quot;, a 40% chance of choosing &quot;g&quot;, and a 20% chance of choosing &quot;e&quot; and &quot;s&quot;. &quot;g&quot; has a pretty high chance of being selected, so let’s say the computer chose that letter. Our fake word is getting bigger and now looks like this! — &gt;&quot;eg&quot;</p><p>For the third letter, the program will follow the same process, but instead of looking for 2-letter combinations, it will look for 3-letter combinations that once again begin with our current fake word, which is &quot;eg&quot;. So it will find &quot;egr&quot; and &quot;egg&quot; in our set of words. Notice how the algorithm is dynamically adjusting it’s search and evaluation to match the length of the fake word. With a 50% chance of choosing either &quot;r&quot; or &quot;g&quot; (since &quot;egr&quot; and &quot;egg&quot; occur only once each in our original set of words), let’s say the computer selected &quot;g&quot;, making our fake word &quot;egg&quot; so far.</p><p>Now the computer has a problem. Since our fake word is currently &quot;egg&quot;, it needs to find a fourth letter, which means it needs to find the frequency of 4-letter combinations that begin with &quot;egg&quot;. However, if you review the original set of words above, that never occurs. To solve this problem, the computer must find a letter using our current fake word with the first letter chopped off. So now it will find all 3-letter combos beginning with &quot;gg&quot;. Since this does not occur either, the program will chop one more letter off of the evaluation segment. It will evaluate 2-letter combos beginning with &quot;g&quot;. Note that our fake word doesn’t change, just the evaluation process does. The results look like this for finding our 4th letter:</p><pre>[<br>    {&quot;letter&quot;: &quot;ge&quot;, &quot;ratio&quot;: 0.33},<br>    {&quot;letter&quot;: &quot;gr&quot;, &quot;ratio&quot;: 0.33},<br>    {&quot;letter&quot;: &quot;gg&quot;, &quot;ratio&quot;: 0.33}<br>]</pre><p>The process is the same as before now and we can use our imagination and pretend the imaginary computer in this example selected &quot;e&quot;, making our fake word &quot;egge&quot; so far. Now the computer must find a 5th letter and searches through the set of words for occurrences of 5-letter combos starting with &quot;egge&quot; and here is where the real problem begins…</p><h3>The Problem</h3><p>As the program continues through the word, it decides to evaluate &quot;egge_&quot;, where the underscore represents any letter succeeding the former. How can the program find &quot;egge_&quot; if it could not find &quot;egg_&quot;, as previously mentioned? <em>Hint: It’s impossible, but the computer is trying anyway.</em> As the word expands to 10, or 20 letters, it rechecks all the failed and impossible combinations each time a letter is added. In addition to that, each time a letter is added, the number of impossible combinations only increases. The evaluation process as the fake word increases in length looks something like this:</p><pre># <strong>Bold</strong> represents combinations of letters that were analyzed by the<br># computer and cannot be used to find a new letter<br>xxx<br><strong>xxx</strong>xxx<br><strong>xxxxxxxxxxx</strong>xxx<br><strong>xxxxxxxxxxxxxxxxxxxxxxxxx</strong>xxx<br><strong>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</strong>xxx</pre><p>For every letter added, an evaluation is also added. This represents a Big O(n) time complexity, where the number of calculations increases linearly as the data set grows. This gets expensive and can be demonstrated by a benchmark.</p><p>In the benchmark, I found the current time, ran my ruby method for getting a word 20 letters long 100 times, then found the ending time and calculated the average time each word took to generate.</p><pre>before = Time.now<br>100.times do<br>    get_word(20)<br>end<br>after = Time.now</pre><pre>(after - before)/100<br>#=&gt; 2.901</pre><p>The results of the benchmark showed that a 20-letter word took, on average, 2.90 seconds to complete on my local machine. Compare that to a 3-letter word:</p><pre>before = Time.now<br>100.times do<br>    get_word(3)<br>end<br>after = Time.now</pre><pre>(after - before)/100<br>#=&gt; 0.465</pre><h3>The Solution</h3><p>To solve this problem, take a look at what the simplified version of the method looks like in Ruby (the full version of the method just has more features/settings):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*3aWloNtXnhe9XT_BIzeDGQ.png" /></figure><p>The logic for chopping letters off of the beginning of a given segment is currently being handled by the get_letter method. This means that when it’s time to get a new letter, the information of what was chopped off previously is lost, because the get_letter method finishes after each letter. To solve this problem, the logic of chopping off letters must be handled by the get_word method, so that the chopped segment can remain in memory and be reused.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/1*cExMxiq7sk1QOjjiseLFGA.png" /></figure><p>Take a moment to read the comments in the code (marked with a “#”). First we initialize the segment, which remains identical to our fake word until the while loop. Then it checks for the stat length, given our segment. Remember, the “stats”, as the code calls them, are exactly the same as shown above (with the letters and ratios) and is calculated by counting the frequency of each occurrence of a given combo (a.k.a. segment) in a set of words. If no stats are given, it is because there was nothing to count. So segment.slice!(0) cuts off the first letter, but since we are slicing segment and not returned_word, it does not affect our fake word directly. Finally, notice after the loop that the get_letter method is invoked with segment as the argument, instead of returned_word, which is the fake word.</p><p>Let’s run the benchmark again.</p><pre>before = Time.now<br>100.times do<br>    get_word(20)<br>end<br>after = Time.now</pre><pre>(after - before) / 100<br>#=&gt; 2.274</pre><p>With these changes, the average time to find a 20-letter word drops from 2.901 seconds to 2.274 seconds, which is around a 22% improvement in speed!</p><h3>Conclusion</h3><p>Now that each combination of letters that fails to provide options for a next letter is never evaluated more than once, the evaluation process looks something like this:</p><pre># <strong>Bold</strong> represents combinations of letters that were analyzed by the<br># computer and cannot be used to find a new letter<br>xxx<br><strong>xxx</strong>xxx<br>xxxxxxxx<strong>xxx</strong>xxx<br>xxxxxxxxxxxxxxxxxxxxxx<strong>xxx</strong>xxx<br>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<strong>xxx</strong>xxx</pre><p>Therefor, the time complexity of the evaluation process now does not increase as the length of the word grows, since theoretically the evaluated segment remains the same length throughout the process. And that’s how it achieves a 22% improvement in speed without sacrificing functionality!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=977dab1eda4a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Store Objects and Arrays Using localStorage in JavaScript]]></title>
            <link>https://medium.com/@joshua.phillip.holmes/how-to-store-objects-and-arrays-using-localstorage-in-javascript-3b52af1ac212?source=rss-43e2daea35c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b52af1ac212</guid>
            <category><![CDATA[localstorage]]></category>
            <category><![CDATA[json]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[parse]]></category>
            <category><![CDATA[js]]></category>
            <dc:creator><![CDATA[Joshua Holmes]]></dc:creator>
            <pubDate>Tue, 14 Dec 2021 15:10:24 GMT</pubDate>
            <atom:updated>2021-12-14T15:10:24.994Z</atom:updated>
            <content:encoded><![CDATA[<p>Using localStorage is useful for storing information through a page refresh, but it can cause some errors without understanding how it stores data. localStorage only stores data as strings, so when you save a piece of data, such as a number localStorage.setItem(&quot;price&quot;, 1.20), the number is parsed as a string before the value gets saved. To show this, I will try entering this into a browser console:</p><pre>localStorage.setItem(&quot;price&quot;, 1.20)<br>// =&gt; undefined</pre><pre>const price = localStorage.getItem(&quot;price&quot;)<br>// =&gt; &#39;1.2&#39;</pre><pre>typeof price<br>// =&gt; &#39;string&#39;</pre><p>When attempting to save an object (or array), the same problem occurs.</p><pre>localStorage.setItem(&quot;object&quot;, {one: 1, two: 2, three: 3})<br>// =&gt; undefined</pre><pre>localStorage.getItem(&quot;object&quot;)<br>// =&gt; &#39;[object Object]&#39;</pre><p>To solve this, we need to convert the object to JSON when storing it in localStorage, since JSON is data saved as a string. We also need to convert it from JSON when retrieving it from localStorage.</p><p>To store the data, we will do it using JSON.stringify, which will convert the object (or array) into JSON:</p><pre>const myObject = {one: 1, two: 2, three: 3}<br>// =&gt; {one: 1, two: 2, three: 3}</pre><pre>localStorage.setItem(&quot;object&quot;, JSON.stringify(myObject))<br>// =&gt; undefined</pre><p>To retrieve the data, we will now parse it after retrieving it, which will convert it from JSON into a normal JavaScript object or array using JSON.parse:</p><pre>const myNewObject = JSON.parse(localStorage.getItem(&quot;object&quot;))<br>// =&gt; undefined</pre><pre>myNewObject<br>// =&gt; {one: 1, two: 2, three: 3}</pre><pre>typeof myNewObject<br>// =&gt; &#39;object&#39;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b52af1ac212" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solving “Press any key to boot from CD or DVD…..” Problem When Installing Windows 10 or 11]]></title>
            <link>https://medium.com/@joshua.phillip.holmes/solving-press-any-key-to-boot-from-cd-or-dvd-problem-when-installing-windows-10-or-11-6b245aac961f?source=rss-43e2daea35c7------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b245aac961f</guid>
            <category><![CDATA[booting-up-pc-with-new-os]]></category>
            <category><![CDATA[installing-windows]]></category>
            <category><![CDATA[windows-10]]></category>
            <category><![CDATA[windows-11]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Joshua Holmes]]></dc:creator>
            <pubDate>Fri, 19 Nov 2021 23:21:57 GMT</pubDate>
            <atom:updated>2022-01-16T18:19:25.369Z</atom:updated>
            <content:encoded><![CDATA[<p>Since you are on this page, you are probably having the same issue I had more times than I would like to admit — booting from a bootable Windows USB device (Windows 10 or 11) is failing. Maybe you are even receiving the same mystifying message that I did, asking you to press any key to boot from a CD or DVD, <em>with no mention of a USB</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bI2TQn2u5_fpljAIv0Es5Q.jpeg" /></figure><p>Upon pressing the key, a Windows installer pops up, which verifies that the ISO on the USB is being read, but installation comes to a halt when it says it can’t find the bootable device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-tK7a7swfziSypT1aeAwnQ.jpeg" /></figure><p>If you are coming across this perplexing problem, it is likely because you, like me, did not<strong> use a USB imager that is specifically designed for Windows ISOs.</strong> It is also likely that you are unable to use the Microsoft-provided <a href="https://www.microsoft.com/software-download/windows11">Create Windows Installation Media</a> tool. Creating a bootable USB for Windows will not work with a normal USB imager. You must use a tool that includes the capability of creating a bootable USB from a Windows ISO.</p><h3>Solutions</h3><p>Thankfully, I have a solution to this problem. <strong>The solution is to use a tool specifically designed to create Windows USB boot devices!</strong></p><h4>Windows</h4><p>If you are using Windows or Mac, there are solutions available. If you are using Windows, I would highly recommend using Microsoft’s <a href="https://www.microsoft.com/software-download/windows11">Create Windows 11 Installation Media</a> tool for Windows 11 or <a href="https://www.microsoft.com/en-us/software-download/windows10%20">Create Windows 10 Installation Media</a> tool for Windows 10. If you want a third party program, try using a program called <a href="https://rufus.ie/en/">Rufus</a>.</p><h4>Linux/Mac</h4><p>For Linux, I would recommend a program called <a href="https://github.com/WoeUSB/WoeUSB">WoeUSB</a>.</p><p>If you are running an Arch-based system and have an AUR installed, search for WoeUSB in the AUR. For example, type yay woeusb into the CLI if you use yay as an AUR. That’s it for installation!</p><p>If you don’t have an AUR or are using a distribution other than Arch (such as a Debian-based distro), feel free to go to the <a href="https://github.com/WoeUSB/WoeUSB#Run-from-source">WoeUSB GitHub</a> and follow the instructions in the “Run from source” section. Be sure to install any necessary dependencies.</p><p>To use WoeUSB, I would recommend typing woeusb into the terminal and reading the instructions shown there. If you’d rather read on, I will also explain it in the rest of this blog.</p><p>First, we need to type a command with 4 elements in it so it looks like this: woeusb -d /path/of/iso/file.iso /dev/drive/. The -d flag is for “device” and is used for completely wiping the USB drive and building a bootable USB device from scratch. Next is the file path of the ISO you are using. Last, is the path of the USB drive, which will vary from computer to computer.</p><p>To find the USB drive path, simply type in lsblk. Here is what mine looks like, as an example:</p><pre>NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS <br>sda           8:0    0   1.8T  0 disk  <br>├─sda1        8:1    0   1.7T  0 part /mnt/HDD-2TB <br>└─sda2        8:2    0 100.6G  0 part /run/timeshift/backup <br>sdb           8:16   1  29.8G  0 disk  <br>├─sdb1        8:17   1   2.9G  0 part  <br>├─sdb2        8:18   1     4M  0 part  <br>└─sdb3        8:19   1  26.9G  0 part  <br>nvme0n1     259:0    0 953.9G  0 disk  <br>├─nvme0n1p1 259:1    0   512M  0 part /boot <br>├─nvme0n1p2 259:2    0 697.9G  0 part / <br>└─nvme0n1p3 259:4    0 255.5G  0 part</pre><p>In my case, I am trying to find my 32GB USB drive. As you can see, sda is my 2TB drive, so that’s not it. sdb is looking like it’s about 32GB! nvme0n1 is about 1TB, so that’s not it either. To reference the drive’s location, precede the name with /dev/, so the location of my USB drive is /dev/sdb. <em>Do not select the wrong drive or you will be sad because it will delete all the data on the drive.</em></p><p>To put this all together, in my case, I would type sudo woeusb -d /home/josh/Downloads/Win10_21H1_English_x64.iso /dev/sdb. Keep in mind you must use sudo at the beginning, as I did, in order to have the correct permissions. Good luck!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b245aac961f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>