<?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 Catherine O&#39;Hara on Medium]]></title>
        <description><![CDATA[Stories by Catherine O&#39;Hara on Medium]]></description>
        <link>https://medium.com/@oharacatherine?source=rss-6ec2b69ba3b0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5RlOis_MNhInXuoScn5jHQ.jpeg</url>
            <title>Stories by Catherine O&amp;#39;Hara on Medium</title>
            <link>https://medium.com/@oharacatherine?source=rss-6ec2b69ba3b0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 23:19:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@oharacatherine/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[Auth with JSON Web Tokens & BCrypt (Part I: Rails)]]></title>
            <link>https://medium.com/swlh/auth-with-json-web-tokens-bcrypt-part-i-rails-3afd71751ea?source=rss-6ec2b69ba3b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/3afd71751ea</guid>
            <category><![CDATA[bcrypt]]></category>
            <category><![CDATA[jwt-auth]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Catherine O'Hara]]></dc:creator>
            <pubDate>Mon, 07 Oct 2019 05:17:59 GMT</pubDate>
            <atom:updated>2019-10-09T22:18:24.624Z</atom:updated>
            <content:encoded><![CDATA[<h3>Auth with JSON Web Tokens (JWT) &amp; BCrypt (Part I: Rails)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NJY5bZXAQm3k9Hbw0xYVOg.jpeg" /><figcaption><a href="https://unsplash.com/@jamessutton_photography">@jamessutton_photography</a></figcaption></figure><p>In this article, we will be walking through how to set up user auth in your backend by creating JWTs for storing in the browser’s localStorage object. Please note that this might not be the best method for an app that requires high security for sensitive data. In that case, please look into using sessions/cookies. However, the benefit of localStorage is that it runs independent from your server and, therefore, is quite useful in building a Single Page App (SPA). So if you choose to use localStorage, setting a short expiry is one way to increase security. But let’s begin…</p><p>Create your Rails backend API by running the following (we will be using PostgreSQL, you may need to <a href="https://www.postgresql.org/">install it on your own system</a>).</p><pre>rails new project-name --api --database=postgresql</pre><p>Add the following to your Gemfile(via terminal):</p><pre>bundle add jwt &amp;&amp; bundle add active_model_serializers &amp;&amp; bundle add faker</pre><p>In my experience, it is best to add them via the terminal rather then type them manually into your Gemfile because the terminal will grab the correct version and specify which one it is in your Gemfile. You will also need to uncomment (in Gemfile): gem &quot;bcrypt&quot; and run bundle install.</p><p>*In this lesson I will be assuming you will set up your CORS config on your own, so we can continue with auth.</p><p>Go ahead and set up your User model, controller and (optional) serializer. Make sure to include a username or email (to login with) and a password_digest attribute on your users table. I will set mine up as such:</p><pre>rails g model User username name password_digest<br>rails g controller users</pre><p>Run your migrations and add has_secure_password to your User model. This validation is provided by BCrypt and will ensure a password is present at the creation of a new User. Adding has_secure_password will also provide us with <a href="https://api.rubyonrails.org/classes/ActiveModel/SecurePassword/ClassMethods.html#method-i-has_secure_password">methods to set and authenticate BCrypt passwords</a>. I would consider adding validations to the username/email as well (these are not provided via BCrypt).</p><p>Now we need to add a create method back in your UsersController.</p><pre>class UsersController &lt; ApplicationController</pre><pre>   def create<br>      @user = User.create(user_params)<br>      if @user.valid?<br>         render json: @user, status: :created<br>      else<br>         render json: { error: &#39;Failed to create user&#39; }, <br>            status: :not_acceptable<br>      end<br>   end<br> <br>   private</pre><pre>   def user_params<br>      params.require(:user).permit(:username, :name, :password)<br>   end</pre><pre>end</pre><p>And add to your routes.rb file:</p><pre>Rails.application.routes.draw do<br>   resources :users, only: [:create]<br>   post &#39;/login&#39;, to: &#39;auth#create&#39;<br>end</pre><p>At this point, you can now try creating a new user via a POST request! (Remember you need to have enabled CORS access.)</p><p>Great, now that we have our password encryption working, we don’t have to worry about storing our User passwords on the database as plain strings — <strong>please, never do this</strong>. [<em>We also created this encrypted password in order to make it more difficult to steal a password in the case where a token is accessed.]</em></p><p>We will essentially be doing the same now with our users and tokens, but store them on the client-side browser rather than in our database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*6VROiBoNvFWPmn1Xzme1Dw.png" /><figcaption><a href="http://ericsmasal.com/2018/06/04/authenticate-and-authorize-with-jwt-tokens-in-asp-net-core-2-web-api/">That Programming Aha-Moment</a></figcaption></figure><p>Let’s write some methods in our parent ApplicationController, so we can utilize them in both our UsersController and AuthController.</p><pre>class ApplicationController &lt; ActionController::API<br>   before_action :authorized</pre><pre>   def authorized<br>      render json: { message: &#39;Please log in&#39; }, <br>         status: :unauthorized unless logged_in?<br>   end</pre><pre>   def logged_in?<br>      !!current_user<br>   end</pre><pre>   def current_user<br>      if decoded_token()<br>         user_id = decoded_token[0][&#39;user_id&#39;]<br>         @user = User.find_by(id: user_id)<br>      end<br>   end</pre><pre>   def decoded_token<br>      if auth_header()<br>         token = auth_header.split(&#39; &#39;)[1]<br>         begin<br>            JWT.decode(token, &#39;&lt;secret_key_here&gt;&#39;, true, <br>               algorithm: &#39;HS256&#39;)<br>         rescue JWT::DecodeError<br>            nil<br>         end<br>      end<br>   end</pre><pre>   def auth_header<br>      request.headers[&#39;Authorization&#39;]<br>   end</pre><pre>   def encode_token(payload)<br>      JWT.encode(payload, &#39;&lt;secret_key_here&gt;&#39;)<br>   end</pre><pre>end</pre><p>*Note: ‘&lt;secret_key_here&gt;’ is intended to be replaced with your secret key. Don’t forget to store your key in a .env file and add the file to .gitignore!</p><p>This chain of methods will now be expecting an ‘Authorization’ header to come in with fetch requests to protected routes or resources, specifically our auth_header method.</p><p>The syntax of this header is Authorization: Bearer &lt;token&gt;, and within a front end JavaScript request it will ultimately look like:</p><pre>headers: {<br>   &#39;Authorization&#39;: `Bearer ${localStorage.getItem(&#39;token&#39;)}`<br>}</pre><p>Without this header and the provided token, your server will not be able to identify the user and will not provide authorization. The response you will receive from a request, as stated in our authorized method, would be ‘Please log in’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*pilZE1uym98TSGhQg2BzLQ.png" /><figcaption><a href="https://dzone.com/articles/jwts-with-spring-boot-and-java-9">DZone</a></figcaption></figure><p>JWTs have a syntax of their own, too. With three parts, each separated by a .(period). An example looks like the following:</p><p>eyJbhGciOiJIUzI1Ni9J.eyJ2c1VyX2klIjxfoQ.g0U5SAOLozk3dz0mNUrvBSR-0CSewJ5ePraRWg_akVb</p><p>Each of these parts translate to the token’s: header.payload.signature</p><p>This is exactly what our decoded_token method is looking for, before decoding the token. The encode_token method will do the opposite, taking in the user’s information and scrambling it with your secret key and the optional algorithm to produce a token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4W8JT5yod3lBvYSL6uN1DQ.png" /></figure><p>So, now that our Application Controller is set up, let’s complete our UsersController.</p><pre>class UsersController &lt; ApplicationController<br>   skip_before_action :authorized, only: [:create]</pre><pre>   def create<br>      @user = User.create(user_params)<br>      if @user.valid?<br>         @token <strong>=</strong> encode_token(user_id: @user.id)         <br>         render json: { user: @user, jwt: @token }, status: :created<br>      else<br>         render json: { error: &#39;Failed to create user&#39; }, <br>            status: :not_acceptable<br>      end<br>   end</pre><pre>   private  </pre><pre>   def user_params<br>      params.require(:user).permit(:username, :name, :password)<br>   end</pre><pre>end</pre><p>Above, we added in the line to create and encode the token using the user id. After this happens, Rails will now render or return both the user and the newly created token. We also added a skip_before_action since it is inherited from our ApplicationController, but we don’t need to authorize a user before they are created in our database.</p><p>At this point, you should be able to create a new user via a POST request again, but this time receive a token with your response.</p><p>All is working as expected? Awesome. Let’s carry on…</p><p>We need to complete our AuthController to authenticate a user when they return to log in (versus authorize a user when they first create an account). The Auth Controller will also issue a token, so the user can navigate your app without having to login on every page or with every following request to the server.</p><p>First, create a AuthController with:</p><pre>rails g controller Auth</pre><p>The AuthController should then contain the following:</p><pre>class AuthController &lt; ApplicationController<br>   skip_before_action :authorized, only: [:create]</pre><pre>   def create<br>      @user = User.find_by(username: user_login_params[:username])<br>      if @user &amp;&amp; @user.authenticate(user_login_params[:password]<br>         token = encode_token({ user_id: @user.id })<br>         render json: { user: @user, jwt: token }, status: :accepted<br>      else<br>         render json: { message: &#39;Invalid username or password&#39; }, <br>            status: :unauthorized<br>      end<br>   end</pre><pre>   private</pre><pre>   def user_login_params<br>      params.require(:user).permit(:username, :password)<br>   end</pre><pre>end</pre><p>The create action in the AuthController looks very similar to the one in the UsersController. However, our AuthController will call @user.authenticate (a method provided by BCrypt) on the password entered at login before providing an encoded token from our user’s id.</p><p>So there you have it, how to set up auth in your Rails backend. We created our User model, controller and ran our migration. We set up BCrypt to encrypt our user’s password (again, please never store as plain text!) We built our Application Controller to encode/decode our user’s token and authorize our user. And we built our UsersController and AuthController to issue these tokens for new or existing users.</p><p>Stay tuned to complete auth in the front end (Part II: React!) 🔒🔑</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kKEjtW0fKhb-nacipCM_Mg.png" /><figcaption><a href="https://jwt.io/">J</a>WT.io</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3afd71751ea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/auth-with-json-web-tokens-bcrypt-part-i-rails-3afd71751ea">Auth with JSON Web Tokens &amp; BCrypt (Part I: Rails)</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning to Code is like Learning to Play an Instrument]]></title>
            <link>https://medium.com/swlh/learning-to-code-is-like-learning-to-play-an-instrument-61517299fe3f?source=rss-6ec2b69ba3b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/61517299fe3f</guid>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[music]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Catherine O'Hara]]></dc:creator>
            <pubDate>Mon, 16 Sep 2019 06:48:25 GMT</pubDate>
            <atom:updated>2019-09-16T15:54:51.246Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ii6qJOSFL_eRrPWHUFEx0g.png" /><figcaption><a href="https://unsplash.com/@shotsbywolf">Geert Pieters</a></figcaption></figure><p>After having some time to dive into different programming languages and building a few programs, I’ve noticed some patterns and similarities between learning to build software and learning to play an instrument. I grew up playing piano and practicing most everyday and have been experiencing much of the same processes with coding the past three or so months.</p><p>My biggest takeaway? Learning each new technology has been like learning a new song on piano. At first it’s messy and can be a lot to just jump into, but as you pick it apart to understand the pieces then put it together one bit at a time, it all starts to make sense.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F8lPSqcjcNjymIOS4Pm%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fkpop-bts-8lPSqcjcNjymIOS4Pm&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F8lPSqcjcNjymIOS4Pm%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="247" frameborder="0" scrolling="no"><a href="https://medium.com/media/7374af3131d4d64c81be0c2b6628ced8/href">https://medium.com/media/7374af3131d4d64c81be0c2b6628ced8/href</a></iframe><p>Just like learning anything new! But to break down what I’m trying to say, I’ll try to hit a few points:</p><h3><strong>Theory</strong></h3><p>There is music theory and there is programming language theory. They are the concepts and principles of how each works. Sure, you might be able to play a song or code a program without having to delve into this arena, but the subtleties and depth of your medium come from understanding it. But of course, the practice and the theory should grow together. Which bring me to my next point.</p><h3>Do It</h3><p>You have to get your hands dirty and try it out for yourself! No matter how much you read or study your medium, there is no way to truly learn it unless you do it. Build a form, practice your chords. Whether it’s one staff or one function at a time, you need to try it out for yourself. There is no other way.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FyE3P1gj3qLMbe%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2FyE3P1gj3qLMbe&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FyE3P1gj3qLMbe%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="217" frameborder="0" scrolling="no"><a href="https://medium.com/media/c3093a72a217c236463db2410e921e4f/href">https://medium.com/media/c3093a72a217c236463db2410e921e4f/href</a></iframe><p>Again, this is just like learning anything else. You can read all you want about cooking or photography, which will definitely provide some good insight, but to truly learn either you have to just do it. You can always refer back to your resources when there’s something you want to know or don’t quite understand yet.</p><h3>Keep doing it</h3><p>So at this point, you may have tried a few things and you’re kind of getting it, maybe feeling like you can do this, wondering if you can become good at it. It’s exciting! Some things are starting to make sense, but it’s still difficult. Maybe you’re even doubting your abilities at some points. You keep getting stuck or making mistakes, but the parts you do get right feel wonderful.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FXreQmk7ETCak0%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fretro-thumbs-up-XreQmk7ETCak0&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FXreQmk7ETCak0%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/bf88fa670cb69cf97a1d5341d0606a25/href">https://medium.com/media/bf88fa670cb69cf97a1d5341d0606a25/href</a></iframe><p>This is natural. This is learning. Picking up a new skill takes practice and repetition. Every day you practice, you will learn something new, you will take another step forward and be a bit better than you were the day before. Some days will be more productive than others. Some moments you might not feel it so much and that’s alright, too. But so long as you don’t give up, you’re likely to improve.</p><p>Sometimes all you need is a break or to work on a different song/project for a bit if you’re feeling stuck. This can sometimes be a way out of a rut, to get into your flow again and remember why you love doing what you do.</p><h3>A form of expression</h3><p>In a sense, while coding, your computer is your instrument, and an instrument is a tool. As logical as computer programming can get while working through problems, it is also very much an expression of your solutions to these problems — both literally and figuratively. Not only are you depicting the end result of computer processes and data relationships, you are also deciding how you would like to share and display these results. Your computer is your instrument as you express the how and the why. And when you’re lucky, you get to call all the shots.</p><p>But if you’re in a situation where you’re not driving the development of the program or writing the sonata, there is still plenty of space to be able to express yourself. Whether it’s through refactoring and rearranging code to make it look beautiful, playing a song with a different set of dynamics or carefully curating the best variable names, you are still a creator, leaving your mark on the world.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FMdA16VIoXKKxNE8Stk%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Frock-coding-programming-MdA16VIoXKKxNE8Stk&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2FMdA16VIoXKKxNE8Stk%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="435" frameborder="0" scrolling="no"><a href="https://medium.com/media/557f19f8bf532da296bbf7a99bd98d75/href">https://medium.com/media/557f19f8bf532da296bbf7a99bd98d75/href</a></iframe><h3>Problem Solving</h3><p>As I mentioned just above, programming, like playing music, takes a bit of both creativity and logic. You may lean more one way than another, but it takes both to carry out a whole project. This one probably does apply more towards being the driver of projects or the musical composer, but the process is similar when you get stuck in a certain problem area of either domain. Can’t fix a bug? Keep getting stuck in the same verse? How are you going to approach this problem from another angle if what you’re trying hasn’t been producing the results you’re trying to achieve? Here, you get to fire up your neurons and exercise your noggin.</p><h3>You will get better</h3><p>Lastly, if you give it some time, you will get better. Even a month in to regularly applying yourself you can already look back and see your progression. Oh, the things you will know! All the struggle along the way has suddenly become worth it. Instead of trying to wrap your head around how much you still have to learn and what you don’t know, you can look back every once in a while and see how far you’ve come! There is no need to compare yourself to others in your field and what they are doing. As long as you are doing better than you used to be, you’re in a good place and can get to where you want to be.</p><p>Music and programming can each be a lifetime of learning — a lifetime of challenge, growth and reward.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FuTZ5xeWyloEVO86uBV%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Frocketmanmovie-elton-john-rocketman-eltonjohn-uTZ5xeWyloEVO86uBV&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FuTZ5xeWyloEVO86uBV%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/d55c3bb3d5ddd8e6517945d5d1937883/href">https://medium.com/media/d55c3bb3d5ddd8e6517945d5d1937883/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61517299fe3f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/learning-to-code-is-like-learning-to-play-an-instrument-61517299fe3f">Learning to Code is like Learning to Play an Instrument</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When the BASH Ain’t Got *Flash* — Beautify the CLI]]></title>
            <link>https://medium.com/@oharacatherine/when-the-bash-aint-got-flash-beautify-the-cli-5f318325a86?source=rss-6ec2b69ba3b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f318325a86</guid>
            <category><![CDATA[cli-app]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[terminal]]></category>
            <category><![CDATA[rubygems]]></category>
            <dc:creator><![CDATA[Catherine O'Hara]]></dc:creator>
            <pubDate>Mon, 19 Aug 2019 01:26:28 GMT</pubDate>
            <atom:updated>2019-08-19T02:11:24.271Z</atom:updated>
            <content:encoded><![CDATA[<h3>When the BASH Ain’t Got *Flash* — Beautify the CLI</h3><figure><img alt="terminal without styling" src="https://cdn-images-1.medium.com/max/799/1*aEpN8fbsi1qSQh3QG5lm9A.png" /><figcaption>Photo: <a href="https://forums.whonix.org/t/whonix-for-virtualbox-with-cli-command-line-interface-14-0-0-9-4-no-graphical-user-interface-no-gui-headless-testers-wanted/6313">Whonix for VirtualBox with CLI</a></figcaption></figure><p>By default, the BASH terminal is not very <em>pretty</em>. Sure, it can be functional and get the point across, but if you’re building an app for today’s users, well.. there’s a bridge to build between the CLI and a GUI. If it’s a CLI app you’re building, that is.</p><figure><img alt="terminal in different colors" src="https://cdn-images-1.medium.com/max/1024/1*9jFIMOfcHoOsRXqPOrKLng.png" /></figure><p>One way to customize the terminal is via the Shell settings on your system. You can change the background and text colors as well as the font itself. But this is still more for your own preferences. What if a user downloads your app and wants to run it on their local machine? There’s a chance their terminal may look different than yours.</p><p>This, we may not be able to influence. However, there are a few ways in which you can stylize a CLI app and create a Front End of sorts with a Back End language. For the purposes of this post, I’ll be talking about a few gems I learned about while pair-programming a Ruby CLI app (<a href="https://github.com/ChefBoyRT/TacoLandia">TacoLandia</a>) with <a href="https://medium.com/u/dbc0f9da9687">Taylor Stein</a>.</p><p>One gem I found particularly prominent and useful in our app was <a href="https://github.com/piotrmurach/tty-prompt">TTY::Prompt</a>. This gem enabled us to be able to simplify the user experience and minimize the margin of error while receiving user input. There are several interactive elements you can implement with TTY::Prompt; you can allow users to choose from options with a scrollable menu and a list of choices, prompt for a y/n answer, ask for a number input that correlates to a list of choices, or mask a response, such as a password. TTY::Prompt also allows for user input similar to a form, without or with validations, and compiling responses into a hash or nested hashes. We chose to enable the scrolling menu.</p><pre>require &quot;tty-prompt&quot;<br><br>prompt = TTY::Prompt.new<br></pre><pre>prompt.select(&quot;Choose your destiny?&quot;, %w(Scorpion Kano Jax))<br># =&gt;<br># Choose your destiny? (Use ↑/↓ arrow keys, press Enter to select)<br># ‣ Scorpion<br>#   Kano<br>#   Jax</pre><p>Or in our case…</p><p>menu_selection = prompt.select(“Please choose an option”, menu_options)</p><p>The best part? You can change the standard selection arrow with an emoji! So, naturally, we chose a taco.</p><p>prompt = TTY::Prompt.new(symbols: {marker: ‘🌮’})</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zX0fJ2tujNSbOCxoKOLCzQ.png" /></figure><p>As seen above, another way to stylize your terminal app and add some pizazz is to add some ASCII art. We went with a logo design that we generated with a <a href="http://patorjk.com/software/taag/#p=display&amp;f=Graffiti&amp;t=Type%20Something%20">Text to ASCII Art Generator</a>. One thing to keep in mind…you may need to double up each ‘ \ ’ that appears in your art so your terminal or code editor does not misread it as an ‘ignore’ or comment.</p><p>As for the border around the ASCII art, that was created by a gem relative to TTY::Prompt, called <a href="https://github.com/piotrmurach/tty-box">TTY::Box</a>. This gem allows you to create frames around text and customize the borders, text alignment, colors of box and other formatting. Once installed, the gem requires code as simple as:</p><pre>TTY::Box.frame(width: 30, height: 10)</pre><pre>print box</pre><p>(Then you can adjust and customize as needed).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Qary8zNmDwmm93VkKb2aw.png" /></figure><p>Now what about running your program? You may want to keep a clean, natural flow to the app. In order to prevent a mashup of ‘pages’, a simple line of code could be used to clear the terminal before your next screen:</p><p>system “clear”</p><p>Use this as often as you need! It can prevent some unruly presentation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bdGYSPxGiObNCFA5ILCxzQ.png" /><figcaption>Yikes!</figcaption></figure><p>On that note, another line of code that can help with the flow of your program is one that will help you adjust the timing between the presentation of screens or text:</p><p>sleep(1)</p><p>This code creates pauses before running the next line of code in increments of a second, passing in integers or floats between the parenthesis.</p><p>And guess what, combine both system “clear” and sleep() and you can create… animations!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FIziyjDyOR39MAMKTkc%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FIziyjDyOR39MAMKTkc%2Fsource.mp4&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FIziyjDyOR39MAMKTkc%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="367" frameborder="0" scrolling="no"><a href="https://medium.com/media/ddcb1dcc615ddd7778414650cd58e6f5/href">https://medium.com/media/ddcb1dcc615ddd7778414650cd58e6f5/href</a></iframe><p>And there’s one last gem I’d like to talk about, because it combines animation, tacos and another TTY::gem… <a href="https://github.com/piotrmurach/tty-progressbar">TTY::ProgressBar</a>! This gem allow you to create an animated progress bar with the ability to customize the speed, width, number of steps and such. And yes, you can include an emoji as a symbol as we did above with the selector icon.</p><pre>def self.progress_bar<br>  0.step(40, 2) do |i|<br>    printf(&quot;\rCalculating: %-1s&quot;, &quot;🌮&quot; * (i/5))<br>    sleep(0.20)<br>  end<br>end</pre><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FJTW4Vy1hRQfkxWmplt%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FJTW4Vy1hRQfkxWmplt%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FJTW4Vy1hRQfkxWmplt%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="367" frameborder="0" scrolling="no"><a href="https://medium.com/media/3568f446500ebb3b17de30f84b02394f/href">https://medium.com/media/3568f446500ebb3b17de30f84b02394f/href</a></iframe><p>Voilà. As you can see, there are many ways to create a CLI app that has its own look and feel. And there are many other gems for Ruby that can assist you in this process. A couple others we played with but decided not to use, for the sake of simplicity and a clean design, were:</p><p><a href="https://github.com/fazibear/colorize">Colorize</a> : color your text, text background and text effects<br><a href="https://github.com/sickill/rainbow">Rainbow</a> : also for color, background and effects on strings</p><p>Or visit <a href="https://rubygems.org/">RubyGems</a> and search for your next favorites!</p><pre><br>       ,.--._ .-&#39;_..--...-&#39;<br>      &#39;-&quot;&#39;. _/_ /  ..--&#39;&#39;&quot;&quot;&#39;-.<br>      _.--&quot;&quot;...:._:(_ ..:&quot;::. \<br>   .-&#39; ..::--&quot;&quot;_(##)#)&quot;&#39;:. \ \)    \ _|_ /<br>  /_:-:&#39;/  :__(##)##)    ): )   &#39;-./&#39;   &#39;\.-&#39;<br>  &quot;  / |  :&#39; :/&quot;&quot;\///)  /:.&#39;    --(       )--<br>    / :( :( :(   (#//)  &quot;       .-&#39;\.___./&#39;-.<br>   / :/|\ :\_:\   \#//\            /  |  \<br>   |:/ | &quot;&quot;--&#39;:\   (#//)              &#39;<br>   \/  \ :|  \ :\  (#//)<br>        \:\   &#39;.&#39;:. \#//\<br>         &#39;:|    &quot;--&#39;(#///)<br>                    (#///)<br>                    (#///)<br>                     \#///\<br>                     (##///)<br>                     (##///)<br>                     (##///)<br>                     (##///)<br>                      \##///\<br>                      (###///)<br>                      (sjw////)__...-----....__<br>                      (#/::&#39;&#39;&#39;                 &quot;&quot;--.._<br>                 __..-&#39;&#39;&#39;                             &quot;-._<br>         __..--&quot;&quot;                                         &#39;._<br>___..--&quot;&quot;                                                    &quot;-..____<br>  (_ &quot;&quot;---....___                                     __...--&quot;&quot; _)<br>    &quot;&quot;&quot;--...  ___&quot;&quot;&quot;&quot;&quot;-----......._______......----&quot;&quot;&quot;     --&quot;&quot;&quot;<br>                  &quot;&quot;&quot;&quot;       ---.....   ___....----</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f318325a86" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Active Record & CRUD Operations]]></title>
            <link>https://medium.com/@oharacatherine/active-record-crud-operations-e2864a07657e?source=rss-6ec2b69ba3b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2864a07657e</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[activerecord]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Catherine O'Hara]]></dc:creator>
            <pubDate>Sun, 04 Aug 2019 05:53:22 GMT</pubDate>
            <atom:updated>2019-08-05T03:21:11.975Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o5tg56GvyKYTsQdJg8TVSQ.jpeg" /><figcaption>photo from : <a href="https://www.gapintelligence.com/blog/tags/activerecord/">Gap Intelligence</a></figcaption></figure><p>In order for data to be persisted (or lasting) when you close a program, it must be stored in a database. SQL, or Structured Query Language, is a computer language that allows communication with such databases. If you’ve ever worked with database tables or SQL then you must be familiar with CRUD operations. Create, read, update, delete. These are the core functions while working with data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*pDFCUkGnYcRRG9sjuIUxTw.png" /><figcaption>credit: S<a href="https://stefanomanfredini.info/en/2017/06/saving-time-crud-generator-laravel/">tefano Manfredini</a></figcaption></figure><p>Active Record is a Ruby gem, also incorporated in the Rails framework, that greatly simplifies the process of working with said databases. Active Record provides methods for these CRUD operations that allows you to efficiently communicate with a database, quickly persisting classes as tables and class instances as rows in the tables. And vice versa — Active Record then allows you to retrieve the persisted data and operate on it as though they were classes and class objects.</p><p>After configuring your environment to include the Active Record gem, establishing your connection to and migrating your database tables, you can then call the following methods:</p><p><strong>Create</strong></p><pre>.new (will instantiate but not save)<br>.save (to create persistence, commit to database)</pre><pre>.create (same as entering .new then .save)</pre><p><strong>Read</strong></p><pre>.all (returns all objects of a class/records in a table)<br>.first (first record)<br>.last (last record)<br>.count (the number of records)<br>.order (defaults ASC, can also be DESC)</pre><pre>.find (to retrieve a record by ID)<br>.find_by (will return a single record, first match)<br>.where (will return all records that match given attribute)</pre><pre>.pluck (to select only specific value(s) of records)</pre><p><strong>Update</strong></p><pre>.update (instance method, update single record with attribute)<br>.update_all (class method, update all records with attribute)</pre><p><strong>Delete</strong></p><pre>.destroy (to destroy a record after retrieving with .find_by)<br>.destroy_by (to delete multiple records by a specific attribute(s))<br>.destroy_all (all records of a table/all instances of a class)</pre><p>As you can see, most of these methods are written to be used intuitively. They allow you to use clean and simple syntax and chaining as such:</p><pre>Friend.order(age: :ASC).last.id</pre><p>whereas in SQL syntax would look like:</p><pre>SELECT id <br>FROM friends <br>ORDER BY age ASC <br>LIMIT 1;</pre><p>or Ruby without Active Record:</p><pre><strong>Class Friend<br>   </strong>def self.find_id_oldest_friend<br>      sql <strong>=</strong> <strong>&lt;&lt;-</strong>SQL<br>        SELECT id<br>        FROM friends<br>        ORDER BY age ASC<br>        LIMIT 1<br>     SQL</pre><pre>      DB[:conn].<strong>execute</strong>(sql, age).<strong>map</strong> <strong>do</strong> <strong>|</strong>row<strong>|<br>         </strong>self.<strong>new_from_db</strong>(row)<br>      <strong>end</strong>.<strong>first<br>   end<br>end</strong></pre><p>So do not take these methods and gem for granted! Many thanks to the programmers before us and around us. And remember, your code is rarely your own, but oftentimes the result of collaboration. 😉</p><p>For a more complete list and proper syntax examples, check out this <a href="https://devhints.io/rails-models">Cheat Sheet</a> that includes persistence and query methods or the <a href="https://edgeguides.rubyonrails.org/active_record_basics.html">Active Record Basics</a> guide itself. By the way, Active Record also has aggregate methods that allow for simple <a href="https://api.rubyonrails.org/classes/ActiveRecord/Calculations.html">calculations</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2864a07657e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Diving into the Tech World Oasis]]></title>
            <link>https://medium.com/@oharacatherine/diving-into-the-tech-world-oasis-ae2ea7113fa9?source=rss-6ec2b69ba3b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae2ea7113fa9</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[codingbootcamp]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[junior-developer]]></category>
            <dc:creator><![CDATA[Catherine O'Hara]]></dc:creator>
            <pubDate>Sat, 27 Jul 2019 20:19:55 GMT</pubDate>
            <atom:updated>2019-07-27T20:19:55.366Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L3tWu92Jg8gHrt-XDaI8EA.jpeg" /><figcaption>A panorama photo from the desert I grew up in. “A friend’s backyard.” El Paso, Texas.</figcaption></figure><p>So I recently started learning programming.</p><p>Coding, software engineering, web development. Frameworks, languages, methods, databases, APIs, CLI, back-end, front-end, full stack. Many new concepts and vocabulary inside and outside of the computer languages themselves. I had a little bit of a background in HTML and CSS from a Web Design course I took in college (and back when I had/customized a MySpace profile), but learning object-oriented programming and how to build web apps has been a whole new beast of a journey. One in which I intend to devour (and enjoy! ☺).</p><p>It’s been happening quickly, too. After a detour from my Multimedia degree into the Health industry, I eventually realized I missed being enveloped in creation and project-building (despite my intrigue in the healing arts). Sure, I had my outlets on the side when I needed a creative fix. But still, a part of me kept going unnoticed, to my self, in my core. So, I’ve quit my job. I’ve enrolled in an all-immersive coding “bootcamp” for the next three months. I’m two weeks into the program now, and it’s been a fantastic experience. I’m loving what I’m learning and the rate at which I’m learning it. This coming week we’ll be building our first projects, a CLI app. So there will be some of that to come, here, along with some technical things I’m learning.</p><p>Some of what I post may be new to you readers, or of novice knowledge — depending where you are in your own programming journey. To some, it may be a nice refresher. But either way, I hope someone can learn something from my writings. Even if it is just my self.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae2ea7113fa9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>