<?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 Timothy Fell on Medium]]></title>
        <description><![CDATA[Stories by Timothy Fell on Medium]]></description>
        <link>https://medium.com/@Timothy_Fell?source=rss-37806a67c20f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*vuUf8aLAInOywwNxmDgeZQ.jpeg</url>
            <title>Stories by Timothy Fell on Medium</title>
            <link>https://medium.com/@Timothy_Fell?source=rss-37806a67c20f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 13:19:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Timothy_Fell/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[Relationships and Growing Pains]]></title>
            <link>https://medium.com/@Timothy_Fell/relationships-and-growing-pains-44561f874e89?source=rss-37806a67c20f------2</link>
            <guid isPermaLink="false">https://medium.com/p/44561f874e89</guid>
            <category><![CDATA[json-api]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[json]]></category>
            <dc:creator><![CDATA[Timothy Fell]]></dc:creator>
            <pubDate>Mon, 03 Dec 2018 10:52:51 GMT</pubDate>
            <atom:updated>2018-12-03T10:52:51.922Z</atom:updated>
            <content:encoded><![CDATA[<h4>Learning How to Build a Rails API</h4><h4>To start with, what is an API?</h4><p>In simple terms, an API is an interface that gives other machines, systems, and people access to the data held within the database of an app or website. There are many ways to build an API but for this project, I tried my hand at building an API that responds with JSON data to each request. JSON is pretty spectacular because a JSON response is just a string, a sequence of text. This makes it fast to transmit over the internet, can be sent and used in a variety of systems and if needed can still be read by the human eye.</p><h4>The Project: Rails Engine</h4><p>The project I have been working on is called Rails Engine and the API I created for it returns data regarding the e-commerce information, relationships and business analytics held within the database. There were six tables within the database, including Merchants, Customers, Items, Invoices, Invoice Items, and Transactions. All six of these tables interacted and relied on each other to build a simple dataset of a theoretical e-commerce app or website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0CfEdl8u4BRdTQKuAoA0BQ.png" /><figcaption>My CSV import code.</figcaption></figure><p>The data used was pulled from Etsy, I imported it from six CSV (Comma-separated-value) files and contained a reasonably small amount of data. When I say “small”, I mean no file contained more than 50,000 entries in it as opposed to millions of entries. As I was building this, I also learned about the JSON API 1.0 Spec which is a web standard for the data returned by my API. This helps other people more easily learn and use the system I have built.</p><h4>Planning</h4><p>As with all new one-week projects planning is key and plays a large roll in completing the project. I originally planned to start my project by building the models that would represent each table in the database then move onto the most difficult analytical problems to finish them first then fill in my time with the other more simple queries. I also planned to write serializers along the way that would allow me to structure my JSON to follow the spec mentioned above.</p><h4>Challenges</h4><p>Of course, as with any plan, as soon as I started to put fingertips to keyboard the plan dissolved. There were a few key gems (code add-ons) that I forgot to add to my project right at the beginning. This resulted in my relationships and database tables not interacting the way I needed them to. My solution to this was to take a step back and determine what and how I could work on my project without actually having my relationships set up. Luckily I had worked with this data set on a previous project so I was familiar enough with it to start working on the business analytics problems, at least on paper.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1cC5g4JQ43JjMbYTcHqAvQ.png" /><figcaption>My missing Gems.</figcaption></figure><p>By the time I had sorted out my missing gems and gotten my tables talking to each other correctly I had roughed out and had potential solutions for 4 of the 10 complex problems. Instead of wallowing in my frustration I was able to continue being productive despite my database not being completely set up to work with. Since figuring out what I was missing, I have created a checklist of gems to use and processes to perform when starting a project of this variety. Building myself a process for creating APIs.</p><h4>The Experience</h4><p>This project has been a lot of fun to work on despite being frustrating at the beginning. Since everything was just returning JSON data, there was no extra work to do on for human comfort. No views, HTML or CSS to display my data, no forms to intake new data, and lastly, the only part of <a href="https://stackify.com/what-are-crud-operations/">CRUD</a> I had needed to build was the R (read). I didn’t want the public creating, updating or deleting my data with a public API. I paired up with some of my teammates to work on the more complex problems, whiteboarding them out as a way to explore them and along the way, learned some new techniques for solving big, multi-joined ActiveRecord/SQL queries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hb3f5Ywu_pkqjkvkn3UFYQ.png" /><figcaption>A JSON sample from a relationship query.</figcaption></figure><h4>What Went Well</h4><p>Amongst the chaos at the beginning of this project, I did despair a little at not being able to get my database tables to work correctly. However, I am proud that I continued to press forward and work through the challenging business analytics problems using ActiveRecord. In the past, I also would have shut down and stopped working on a project that was giving me so much trouble but since my college years, I have learned to be patient with myself and reach out to coworkers/classmates for help. I ended up trading my help for a classmate’s in figuring out why my table relationships weren’t working.</p><h4>What Would I Change</h4><p>If I had to do the project again I would be more careful in the beginning and make sure my setup is rock solid using the processes I am currently building. This would help me create my database tables without a hitch, plan out what my Git branches will be beforehand and what I need finished before I start each one, and set up regular check-in times with my teammates or seniors to get feedback as I go along.</p><h4>What’s Next?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*czFwd56Bnq8_IaQ_6V3x5g.jpeg" /></figure><p>Well, hopefully, some quality time outside away from a computer! But jokes aside, I want to bring the experience I gained from this project to bear on ones in the future. I have learned that even when a framework isn’t fully set-up progress can still be made as long as the framework does get finished (you can’t use complex queries on an empty database). As I build more apps and APIs I will expand on my project-startup-processes allowing me to cut down initial setup time and provide reliable results with practice.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=44561f874e89" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Set Password Requirements in Rails]]></title>
            <link>https://medium.com/@Timothy_Fell/how-to-set-password-requirements-in-rails-d9081926923b?source=rss-37806a67c20f------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9081926923b</guid>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[passwords]]></category>
            <category><![CDATA[validation]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[regular-expressions]]></category>
            <dc:creator><![CDATA[Timothy Fell]]></dc:creator>
            <pubDate>Wed, 07 Nov 2018 14:29:10 GMT</pubDate>
            <atom:updated>2018-11-07T14:29:10.699Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l0Q5AHdg-UrvscmGgk4arQ.jpeg" /></figure><h4>A peek into more complex validations and basic password security for those new to Rails</h4><p>So hopefully you’ve been working in Rails for at least a few weeks and have been validating your models up till now. The presence of a username, the presence of an email, maybe even some numericality for item inventories, and who knows what else! Now you’re looking to create all those pesky rules for passwords when someone signs up for your Rails app? Good! Users are lazy and the easier they can make their passwords to remember (hack) they will.</p><h3>Password Hashing</h3><p>Before we even get to password requirements, make sure you are never storing user passwords as plaintext. Heaven forbid someone gets a look at your database they will be able to screenshot all of the users passwords including any admins that might be present on the system. Blasphemy and chaos!</p><p>To deal with this many developers hash the plain text password input and store the hash value in their database instead. Hashing is a coding process similar to a chemical reaction, irreversible. Making it very hard to reverse engineer the hash value back to the original password. This helps protect you and your users even if someone you don’t trust gets a peek at your database.</p><p>To implement this technique I suggest using <a href="https://rubygems.org/gems/bcrypt/versions/3.1.12">bcrypt</a>. It’s a rails gem that allows you to hash a value using SHA256 which takes in any string input and spits out a new 32 byte string for you to store in your database. Example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z6GkF2dUkKHwI39Jm9zaSQ.png" /></figure><p>First lets add or uncomment out (in Rails it’s usually there unless you deleted it) …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*9izCS-cBdC_qHJArFyU7Vw.png" /></figure><p>… in your Gemfile within the main section (not development or test) and run your bundler to install this handy tool. This will install it within your app for use and will be included in your packaged app if/when you’re ready for production.</p><p>Now all you need to do is add a line to your model file and change your password column in your CreateUser migration file to be password_digest. Only do this if your project isn’t in production, if it is create a new migration to change the column name in your User table instead.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*BT8XqORGjCydYhBRdLg4ew.png" /><figcaption>Add this line before the laster end of your User model file.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*R06MhN5ovEauhlTtYJeuNg.png" /><figcaption>From this…</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*hfPkyDsuTcGLmUJxSDbSUg.png" /><figcaption>To this!</figcaption></figure><p>Drop, create and migrate your database to put these new changes in effect (again if in production DO NOT DROP database). The hashed password value will be stored instead of your plain text passwords. This way you never store the plain text passwords for anyone to find.</p><p>Cool! Now hackers will have a very hard time trying to figure out our users’ passwords even if they find them. Now how about brute force attacks? Trying all the combinations of characters, numbers, and symbols that a password might be? Well there are some techniques out there to increase the time between attempts and eventually lock the account after a certain number of attempts. Both great ideas that I suggest you look into. However, that is a fair bit more complicated than what I want to get into today.</p><h3>Regular Expression Constant</h3><p>Instead, today, let’s force our lazy users to create more complicated passwords that will be harder to brute force hack. To get started you need nothing more than Rails, easy! Presumably you have a User model that houses validations, relationships and relevant methods for your user table. Let’s get started!</p><p>Generally, a good base would make sure all passwords are at least a certain length (let’s say 8), contain at least one uppercase and one lowercase letter, a number and a symbol. With these restrictions the number of possible passwords is in the trillions if not quadrillions (I tried to find the exact number but all I found were mathematicians bickering).</p><p>Awesome, but how do we check if the password a user passes in fits all those criteria? Validations and Ruby regular expressions(regexp), yay! Rails has an awesome built in validation, format, that takes in a regexp as a value and compares what we’re validating to it. Let’s make the regexp a constant to pass into the format validation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*KaquISPeubycuasl3ILMRw.png" /></figure><p>“What does that even mean?!” you say? Well /\A denotes the start of the string we are examining and the /x denotes the end of it. The /x also allows us to put whitespace between our different regexp tokens we will be adding in between the /\A and /x. Now that we’ve got the setup done, let’s start adding the regexp tokens we need for our password requirements. I’m going to start with the minimum length of 8 characters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*TgYfwilJYaThZAu5IyRNgQ.png" /></figure><p>Awesome, more gobbly gook! Let’s break down this new line we’ve added.</p><ul><li>‘?=’ tells our program to look from the start of the string at what it contains.</li><li>The ‘.’ tells our regexp token that there should be no characters before what we pass the regexp token next.</li><li>Finally the ‘{8,}’ tells us that we are expecting the string to have a minimum length of 8 but no maximum length.</li></ul><p>That’s right super long passwords are in! All together we are expecting our string to start with nothing before having at least 8 characters in length with no maximum. And this token doesn’t capture or change our original string in any way so we can keep checking other things and store the password as input, perfect!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*0ijsB9BVbb3uuw5atID-7A.png" /></figure><p>Same as before with some new bits!</p><ul><li>The .* combination denotes that the number could be the first character in the string (.) or have some other characters come before it (*).</li><li>The \d denotes we are looking for a number or digit.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/942/1*9hD3qBZtZr8NY6GENqZOcw.png" /></figure><p>This is the same as the digit line but instead we are making sure there is at least one lowercase letter from the range a-z.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/952/1*wsCybVUE-_GrE2VtyTg_7w.png" /></figure><p>This new line makes sure there is one uppercase letter from the range A-Z in the string.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*VDEC7QhFEG-krlkbZigqsg.png" /></figure><p>This last line we are adding, simply put, checks to make sure there is one symbol in the string from the list of keyboard symbols.</p><h3>Password Validation</h3><p>Great! We’ve got an awesome regexp Constant to validate our password with. Now let’s implement it in our validations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*WVPjD7hcO0mDGCL1kkL4Mw.png" /></figure><p>Now our validation will use our regexp constant to check our password for our requirements. Mission complete!</p><h3>PS</h3><p>Make sure to run your tests because if there was any user creation or updating they most likely have been broken. To fix, change any passwords you use in your tests to pass all your password requirements. Also make sure to sad path test what happens when someone doesn’t fulfill all the password requirements!</p><h3>Resources:</h3><ul><li><a href="https://guides.rubyonrails.org/active_record_validations.html">https://guides.rubyonrails.org/active_record_validations.html</a></li><li><a href="http://www.gnu.org/software/grep/manual/html_node/Regular-Expressions.html">http://www.gnu.org/software/grep/manual/html_node/Regular-Expressions.html</a></li><li><a href="https://github.com/codahale/bcrypt-ruby">https://github.com/codahale/bcrypt-ruby</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9081926923b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>