<?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 Scott Bewick on Medium]]></title>
        <description><![CDATA[Stories by Scott Bewick on Medium]]></description>
        <link>https://medium.com/@Scottibe?source=rss-29bdddca3721------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dmbNkD5D-u45r44go_cf0g.png</url>
            <title>Stories by Scott Bewick on Medium</title>
            <link>https://medium.com/@Scottibe?source=rss-29bdddca3721------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 20:39:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Scottibe/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[Custom Queries in Rails’ Bi-directional Associations]]></title>
            <link>https://medium.com/@Scottibe/custom-queries-in-rails-bi-directional-associations-4b69f856f6b?source=rss-29bdddca3721------2</link>
            <guid isPermaLink="false">https://medium.com/p/4b69f856f6b</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <dc:creator><![CDATA[Scott Bewick]]></dc:creator>
            <pubDate>Tue, 08 Aug 2017 21:20:56 GMT</pubDate>
            <atom:updated>2017-08-08T21:20:56.967Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently while working on a Rails project it became necessary to customize the the bi-directional associations in my user and event classes. It was slightly more complicated than the typical parent/child relationship in a <em>has_many/belongs_to</em> association.</p><p>The increased complexity arose from the need for an individual event to not only <em>belong to</em> a user when a user creates an event, but also for an individual event to<em> have many</em> users for users who will attend the event. Additionally, a user needs to <em>have many</em> events they have created and <em>have many</em> events they are attending</p><p>So how does an event both belong to a user and have many users? And how does an event have two separate types of users? One way to deal with the event belonging to a user and having many users would be to create a whole new class called Creator but this being Rails, there is a better way.</p><pre>class Event &lt; ActiveRecord::Base</pre><pre>  belongs_to :creator, class_name: &#39;User&#39;</pre><p>In the Event class, simply write the belongs_to macro as if creator was its own class but specify that this is, in fact, an instance of the user class only with a different name with: class_name: &#39;User&#39;</p><p>Next make sure to add creator to the database.</p><pre>class CreateEvents &lt; ActiveRecord::Migration<br>  def change<br>    create_table :events do |t|<br>      t.integer :creator_id</pre><p>Now I can call event.creator and it will distinguished from a ‘normal’ instance of the User class.</p><p>in the User class we add the has_many macro:</p><pre>class User &lt; ApplicationRecord</pre><pre>has_many :created_events, class_name: &#39;Event&#39;, foreign_key: :creator_id</pre><p>As with attendee and user, I gave created_events a separate name from events to be more specific so it was necessary to add class_name &#39;Event&#39; and since a creator has many created events, not a , it is necessary to specify a foreign key of creator_id. Otherwise we could have just used user_id in the database.</p><p>For the Event having many users as attendees, this can be accomplished through a join table.</p><pre>class Event &lt; ActiveRecord::Base</pre><pre>  belongs_to :creator, class_name: &#39;User&#39;<br>  has_many :event_attendees<br>  has_many :attendees, through: :event_attendees</pre><p>Again the user in this case is attendees so now an event belongs_to a creator and has_many attendees. This sounds much better. The join table is a combination of the event and user class, event_attendees and we have many attendees through event_attendees.</p><p>In the EventAttendee model there will two belongs_to statements.</p><pre>class EventAttendee &lt; ActiveRecord::Base</pre><pre>belongs_to :event <br>belongs_to :attendee, class_name: &#39;User&#39;, foreign_key: :attendee_id</pre><pre>end</pre><p>As you can see, with attendee you must designate that it is an instance of the User class just like with the creator name earlier. This time however, it is also necessary to add the foreign key for attendee attendee_id. The event_attendee migration should contain both event_id and attendee_id</p><pre>class CreateEventAttendees &lt; ActiveRecord::Migration<br>  def change<br>    create_table :event_attendees do |t|<br>      t.belongs_to :event<br>      t.belongs_to :attendee<br>      t.timestamps null: false<br>    end<br>  end<br>end</pre><p>Back in the User class we can finish the other end of that join table.</p><pre>class User &lt; ApplicationRecord</pre><pre>  has_many :event_attendees, foreign_key: &#39;attendee_id&#39;<br>  has_many :attending_events, through: :event_attendees, source:   :event</pre><p>here I added a has_many to the join table, event_attendees but in the User class as opposed to the Event class, we need to specify that this is for an attendee rather than a ‘normal’ instance of the User class. This join table is specifically for an attendee.</p><p>Finally, an instance of the User class will have many events they are attending, done by has_many :attending_events, through: event_attendees, source: event. Since I am using attending_events instead of just events I added the source keyword to specify where the association is coming from. You only need to use this option if the name of the source association cannot be automatically inferred from the association name.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4b69f856f6b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working With Watson’s API in Ruby — Part 2]]></title>
            <link>https://medium.com/@Scottibe/working-with-watsons-api-in-ruby-part-2-cf846b840c13?source=rss-29bdddca3721------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf846b840c13</guid>
            <category><![CDATA[ruby-on-rails]]></category>
            <category><![CDATA[rails]]></category>
            <dc:creator><![CDATA[Scott Bewick]]></dc:creator>
            <pubDate>Fri, 03 Mar 2017 03:43:31 GMT</pubDate>
            <atom:updated>2017-03-03T03:43:31.020Z</atom:updated>
            <content:encoded><![CDATA[<p>With my Ruby Wrapper for the API done I started to feel like there was something missing. In order to get a meaningful personality analysis from Watson, you needed at least 3000 words. but ideally you would have 8000+ words to analyze. While some people might have that lying around from things they had written, a lot of people might not. And even if they did, you could only analyze yourself. So I added some functionality to my app.</p><p>There weren’t a whole lot of options, basically my choices were Twitter or Twitter. It was the only place I you can just grab 3000 words of text written by other people.</p><p>Fortunately, this was a pretty simple process. Unlike Watson, There are several Ruby gems that make it easy to interact with the API. All you have to do is create a client object:</p><pre>@@client = Twitter::REST::Client.new do |config|<br>  config.consumer_key = ENV[&#39;USERNAME&#39;] <br>  config.consumer_secret = ENV[&#39;PASSWORD&#39;]<br>end</pre><p>Then call the user_timeline method provided by the gem.</p><pre>twit = @@client.user_timeline(twitter_handle, options = {:count =&gt; 200})</pre><p>This allows a user of my app to input a user name and get a personality analysis of that Twitter user from their 200 most recent tweets.</p><p>Now it was onto Sinatra with some ActiveRecord working it’s magic. As this was the first full app I had endeavored to build, I wasn’t entirely sure how to start. So the first thing I did was was use Apple’s Keynote software to mock up how I wanted the app to flow and a very basic visual structure.</p><p>I was using the MVC framework so fortunately there is a logical progression to follow. I had to set up my models and database. While part of me really wanted to make things more complicated here by having a many-to-many relationship that required a join table, along with a has_many, belongs_to, I decided to cut myself some slack since this was my first time. I went with a has_many belongs_to relationship only.</p><pre>class PersonAnalysis &lt; ActiveRecord::Base<br>belongs_to :user<br>end</pre><pre>class User &lt; ActiveRecord::Base</pre><pre>has_many :person_analyses<br>  has_many :tone_analyses<br>  has_many :person_analyses<br>  has_secure_password<br>end</pre><p>With the models finished I went to work on the controllers. I already knew what routes I needed and what they had to do. The biggest challenge I faced building them was connecting the API wrapper I had written to the correct forms and figuring out a way to let the user edit their input and resubmit it for a brand new analysis. This was the whole point of the Tone Analyzer after all.</p><p>My routes ended up being a bit longer than ones I had written previously for other assignments and could probably (definitely) use some refactoring. But in the end, by adding a text column to the database and saving what was being analyzed, I was able to show the user their input, allow them to edit and submit the new version back to the API for another analysis.</p><p>Tip #3 This may be common knowledge but I’ll say it anyway. Don’t be afraid to rollback your database, edit it, scrap it, start new again if that’s what it’s going to take. As a new developer I know I’m going to make mistakes and decisions I make at the start are just a rough draft. But there were times during this process when I knew I should head in a whole other direction, but I kept trying to fit a square peg in a round hole, trying to make things work the way I had them instead rather admitting it was wrong. It’s a total waste of time.</p><p>mistake #4 Read the bootstrap docs before you start on the front end. My CSS code is a victim of me failing to do this and thinking I could just figure it out as I went. Yes, you can probably do that but the code will be atrocious and the site probably won’t look great. It had been some time since I had done design work and while it came back to me eventually, slowing down and reading more than likely would have actually made the whole thing go faster.</p><p>Building this app was a great learning learning experience. I’ve written it before and I’ll write it again: There i no better way to learn how to code than coding. Yes, there are other things you must do, including reading other people’s code, but noting beats staring at an empty code editor and building something from scratch.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf846b840c13" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working with IBM’s Watson API in Ruby — Part 1]]></title>
            <link>https://medium.com/@Scottibe/working-with-ibms-watson-api-in-ruby-part-1-ae848952386e?source=rss-29bdddca3721------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae848952386e</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[sinatra]]></category>
            <category><![CDATA[api]]></category>
            <dc:creator><![CDATA[Scott Bewick]]></dc:creator>
            <pubDate>Fri, 03 Mar 2017 02:21:47 GMT</pubDate>
            <atom:updated>2017-03-03T02:21:47.322Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently completed my first full web app in Ruby using the Sinatra framework. But before I could, I also had to tackle my first time working with an API. These are some of the things I learned and mistakes I made. If you are an experienced Rubyist, probably no need to read further because I doubt I’ll say anything you don’t already know. But if you are a coding student, maybe I can help you avoid some mistakes I made.</p><p>My assignment was to write a Sinatra app using ActiveRecord with a couple models and at least one has_many belongs_to relationship. It had to follow CRUD conventions. It had to include user accounts and ensure that users could only modify their own content. It had to include input validations and display error messages when that input is not validated.</p><p>Not too complicated as apps go and all things I’d been studying at Flatiron, so I figured I’d up the skill level a bit and see if I can incorporate IBM’s Watson API I had just read about in a blog post.</p><p>IBM only offered SDKs for Android, ios, Java, Node.js, Python and the Unity game engine for some reason. It seemed weird to me they would have Unity but not Ruby, however, there were a few Ruby wrappers for the API in github. I guessed it might add a day, maybe two to my project while I got up to speed on the details on how APIs work and also find a Ruby wrapper that would work for project.</p><p>IBM’s Watson API offers many different services with many different endpoints and each one is slightly different. I had decided my app was going to use the Personality Insights service and the Tone Analyzer service. <a href="https://www.ibm.com/watson/developercloud/doc/getting_started/index.shtml">Here’s the link if</a> you want to learn more about everything they offer, I’d recommend looking, you can make some really cool apps with them.</p><p>But I was going to make a fairly basic app. It would take a user’s text input, send it to the Personality Insights API which would analyze the text and return an analysis of the personality of the author of the text. The Tone Analyzer also took in a user’s text input but this one analyzes the tone of a letter or email. So my app had to be able to give user the ability to edit the letter and resubmit until they achieved the desired tone. The first thing I did was search for one of those Ruby Wrappers to help me along.</p><p>Mistake #1 Just because you find a repo on Github, don’t assume it works or that it will work for your needs. I learned this the hard way. I thought the API portion would take a day or two but it took almost two days just realize the Ruby gems that I needed were either deprecated or just didn’t work. The ones I found I didn’t try because they weren’t for Personality Insights or the Tone Analyzer.</p><p>Mistake #2 If you have never done something before in coding, never just assume it will be easy and you can do it in a couple hours. In other words, don’t get over-confident. After striking out on Github, I was left with only one way forward: write my own wrapper for the API. A day or two had already passed and I was essentially taking on a pre-project before starting my project.</p><p>Tip #1 If you’re a student and you’re building an app, include technology you’ve never been exposed to. Writing my own API wrapper added extra time to my project and was frustrating at times, but the next time I have to do a similar task, it will take me a fraction of the time. At this stage in my development, everything is a learning process, so I might as well make sure I’m learning something new, always. And there is no better way to learn coding than to code. Not finding a wrapper I could work with turned out to be a blessing in disguise.</p><p>For an http client I chose to use the excon gem, although in retrospect, since my needs were pretty simple, it probably would have been better to use Net::HTTP as it’s part of the standard Ruby library and would have eliminated a dependency. I built two classes, PersonalityApi and ToneApi, which are essentially the same, save some minor differences in formatting the JSON object. The users input is taken in as an argument when a new object is instantiated.</p><p>Tip #2 Use the dotenv gem to hide your API Access keys and other sensitive information in environment variables so they aren’t pushed to Github. Obviously you don’t want to expose your secret passwords to the world in your repo so be careful when pushing to Github. Another lesson I learned the hard way, but on the bright side I did learn how to undo a commit that had already been pushed.</p><p>My get_data method is where the action takes place. When calling an API the argument is typically a hash and in this case includes the url, headers to tell the API what you’re sending and the format of it, username, password and the body, in this case the body was the users input. For the Watson API you include queries, where the keys represent the options of different data you can receive and the values are boolean values.</p><pre>def get_data<br>    response = Excon.post(<a href="http://twitter.com/url">@url</a> + &quot;/v3/profile&quot;,<br>    :body     =&gt; <a href="http://twitter.com/input">@input</a>,<br>    :headers  =&gt; {<br>      &quot;Content-Type&quot;            =&gt; &quot;text/plain&quot;,<br>      &quot;Content-Language&quot;        =&gt; &quot;en&quot;,<br>      &quot;Accept-Language&quot;         =&gt; &quot;en&quot;<br>    },<br>    :query    =&gt; {<br>      &quot;raw_scores&quot;              =&gt; true,<br>      &quot;consumption_preferences&quot; =&gt; true, <br>      &quot;version&quot;                 =&gt; &quot;10-20-2016&quot; <br>    },<br>    :user                       =&gt; <a href="http://twitter.com/username">@username</a>,<br>    :password                   =&gt; <a href="http://twitter.com/password">@password</a>)</pre><pre>    response.body<br>  end</pre><p>My next task was to take the JSON object this returned and format it into a hash with just the information I needed so I could use it to instantiate an object from another class using mass assignment. To do this I used the OpenStruct gem which made it easier to iterate through the data and pull out only what I needed. Plus, I had worked with hashes before but I had never used Ostruct, so it was another learning opportunity.</p><p>Once I had the data in hash format, with 13 personality characteristics as keys and a score for each one as the values, I created the class where I used the hash for a mass assignment which turned that data into ruby objects, so every analysis was nicely encapsulated and easy to work with. Below you can see the initialize method that takes the hash as an argument to instantiate an object with 13 attributes.</p><pre>  def initialize(analysis)<br>    analysis.each do |k, v|<br>      self.send(&quot;#{k}=&quot;, v)<br>    end <br>  end</pre><p>With my wrapper pretty much done it was time to move on to the second phase of the project. Sinatra. Part two of this post will pick up there as well.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae848952386e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[For Posterity’s Sake, Regarding the Events of Jan. 20, 2017]]></title>
            <link>https://medium.com/@Scottibe/for-posteritys-sake-regarding-the-events-of-jan-20-2017-4977bf38eb29?source=rss-29bdddca3721------2</link>
            <guid isPermaLink="false">https://medium.com/p/4977bf38eb29</guid>
            <category><![CDATA[2016-election]]></category>
            <category><![CDATA[donald-trump]]></category>
            <category><![CDATA[politics]]></category>
            <category><![CDATA[national-tragedy]]></category>
            <category><![CDATA[inauguration]]></category>
            <dc:creator><![CDATA[Scott Bewick]]></dc:creator>
            <pubDate>Fri, 20 Jan 2017 22:07:59 GMT</pubDate>
            <atom:updated>2017-01-20T22:07:59.020Z</atom:updated>
            <content:encoded><![CDATA[<p>For posterity’s sake, in case some digital archeologist 500 or 1000 years from now is reading this, I’d like to go on record as saying the following: I do not agree with anything taking place today in Washington D.C. I believe Trump will only work for the interests of Americans when those interests align with his own, which will be a rare circumstance indeed. Those with the power to stop this national tragedy and embarrassment have made a grave mistake by circumventing the will of the people.</p><p>Installing a president whose mental health has been so clearly ravaged by time and what must have been unspeakable abuse as a child, will cause irreparable harm to this country and its citizens that we may not recover from. Never before has a president been so intellectually and morally bankrupt, yet so certain of his never-ending brilliance. It would be a task of almost inconceivable difficulty finding a man who would be as poor of a choice to be president as Donald Trump.</p><p>By refusing at every opportunity to prove they care more about the country than their party and allowing trump to verbally desecrate the Constitution that has made the U.S. the most powerful country the world has ever seen, republicans have shoved the citizenry grudgingly down the trump path today. Republicans have acquiesced to trump’s authoritarian instincts in exchange for a promise to support a legislative agenda designed to do the exact opposite of the promises trump made during his campaign.</p><p>Trump now has the power to indulge every paranoid fantasy and perceived slight against him with what will most certainly be a disproportionate response. At his disposal are the most sophisticated and powerful intelligence gathering tools known to man. With the CIA, FBI and every other acronym now in his dirty little hands, Trump’s only recourse when he feels he has been wronged is no longer just a frivolous lawsuit designed to lighten the wallet of those who disagree with him. He now has the power to destroy the life of anyone he deems “an enemy” by directing the acronyms to dig up dirt. If they don’t find dirt, no problem, make dirt. A columnist writes about a trump policy in a negative way? Bug his phone. Intimidate her. Plant a fake story in the media. A man with that much power, no integrity and even fewer morals is limited in his ability to do others harm only by his imagination.</p><p>About 40 percent of the populace, who live in sparsely populated areas away from the coasts, have decided Trump is their savior despite every piece of evidence to the contrary. They are white. They are poor. They freely admit they live in a constant state of being unaware and uninformed. They have contempt for education. They will describe knowledge and the pursuit of it as feminine and weak by calling you a fag. They cry foul when their manual labor jobs go elsewhere and are replaced with intellectual labor. They have no interest in self-betterment and are scared of progress. This is a stereotype and yet true in most instances. These are the people responsible for Trump. Instead of telling them the truth, that their jobs are gone for good and they need to adapt or stay stuck where they are, Trump and republicans lie to them. They tell them they will bring back jobs that are no longer needed. They tell them it is the fault of foreigners that they feel oppressed, not the fault of a legislative agenda designed to keep them where they are while the gap between rich and poor widens into a canyon. It’s not our fault and it’s not your fault and remember, we both love god, right? and we both love guns, right? You know who doesn’t love those things? Hillary Clinton and democrats, they tell them.</p><p>We’ve let them turn stupid-white into a protected class, as if it’s just another race or lifestyle. Except this one believes it deserves more than everyone else. Their sense of entitlement and need to be coddled is only matched by their screams to stop helping minorities and the “welfare queen.” Tell them the truth, that stupid-white actually benefits a disproportionate amount from government funds to the tune of $2 for every $1 spent in taxes, you’ll probably be called a fag.</p><p>This is the country that let Donald Trump hold the most powerful position on the planet. These are the circumstances in which it occurred. The future of the United States hasn’t been this dim since the Civil War but when you consider how this happened, the willful disregard of facts, science and knowledge, perhaps this is the future we deserve.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4977bf38eb29" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[On Writing My First Ruby CLI App]]></title>
            <link>https://medium.com/@Scottibe/on-writing-my-first-ruby-cli-app-be3ca10fff0e?source=rss-29bdddca3721------2</link>
            <guid isPermaLink="false">https://medium.com/p/be3ca10fff0e</guid>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Scott Bewick]]></dc:creator>
            <pubDate>Tue, 08 Nov 2016 16:31:43 GMT</pubDate>
            <atom:updated>2016-11-08T16:31:43.128Z</atom:updated>
            <content:encoded><![CDATA[<p>My first major assignment as a student at the Flatiron School, where I am learning the skills to be a web developer, was to build a command line interface application. I chose to build an app that would track the 25 most recent Presidential election polls publicly available and give the user the opportunity to view detailed information for each poll.</p><p>As this was the first full app I had developed from scratch, it was not without its challenges. The first one being the object-oriented design. How many classes should it have? what should those classes be? The first lesson learned was keep it as simple as possible. At the beginning I went class crazy and at one point had five different classes for a project that you could conceivably get done with two. But in the end I felt the best approach and what would give me the best design was three classes. One for the CLI interface, one for scraping the data from the website and a third Poll class.</p><p>With three classes, each class had only one responsibility. The CLI class was responsible for controlling the flow of the program, making sure that the user experience was as simple as possible and the information easily accessible. The Scraper class obviously just grabbed the data from the website and made it available to my Poll class and my Poll class was responsible for instantiating new poll objects with the proper attributes so the CLI class would be able to call that data when the user asked for it.</p><p>I began working on the CLI class first and stubbed much of that out with fake data. It was time to start scraping the polls website for the data website. This is where I hit my first wall. The data I needed was in a table format with a CSS selector of td and a class of ‘choice’ so it was td.choice. This is how three of four columns, each containing the results of the polls, were labeled. The fourth column was for Hillary Clinton’s results and for some reason was different from Trump, other, and undecided categories. Clinton’s CSS selector was td.choice.best-value. It was quite easy to single out Clinton’s data due to this difference but I could not seem to separate the trump data from the ‘other’ and ‘undecided’ categories. The only way I could get the data was to get it for all four of them those categories at once. So I did.</p><p>I started gathering the data for every category and was writing the methods so that only the top 25 results showed up in an array. I ended up with arrays with 25 elements for all the attributes a single poll object would have. except for the candidate categories. I had an array of 100 elements because there was no way to separate the the ‘other’ and ‘undecided’ categories from the two main candidates, even though I had no intention of using those categories. Mostly because, who cares, right? People are only interested in Clinton and Trump.</p><p>So I got 100 elements and all my arrays matched up nicely. However, what I would eventually notice is that some of the ‘other’ and ‘undecided’ categories didn’t have a result, they were 0. Instead of putting a zero, the website put in a dash, ‘-‘, which Nokogiri was just ignoring. This threw my perfectly matching arrays out of alignment and as soon as I hit the first dash my program attributed the wrong data to the wrong candidates.</p><p>In between looking for other websites and trying different ways to scrape the site, i discovered a solution. Nokogiri wasn’t ignoring the dash after all. If I iterated over the Nokogiri-returned object with the #each method, called the text method in the block and and pushed the result of that into a new array I had previously created, it help an empty spot for the dash (“”) which would allow me to line up the data with correct candidates. At the end of the the all_results method where this is performed, I iterated over the new array and deleted any number below 20. This has the effect of deleting the data for the ‘other’ and ‘undecided’ categories because they would always be below 20 while keeping the data for Trump and Clinton as they would always be above 20. Why that is true for Trump, I do not know.</p><p>Now that I had an array with 50 elements, 25 results each for both candidates, I needed to separate those into two arrays, one for each candidate. I called on each_with_index on the 50-element array and found an interesting enumerable to chain onto that. It’s called Partition and I’d never even seen it before. It takes a block and groups items together, items for which the block returns true and items for which the block returns false are grouped together. So by chaining even? method onto the the block variable[1] for the index in each_with_index, it would evaluate 0 and all even numbers to true, grouping one candidate and the false group would be the other candidate. And that’s how to split up an array by every other element.</p><p>All in all I suppose the way in which I scraped and gathered the data into corresponding arrays may be a little hackey, but I’m not sure there is a better way to do it. The data will always be accurate and is able to deal with a situation in which there is no data for a certain category.</p><p>The Poll class instantiates a new poll object and each attribute has its own method but those attributes are not assigned until the user chooses a poll.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be3ca10fff0e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Only Way to Learn to Code is to Code]]></title>
            <link>https://medium.com/@Scottibe/the-only-way-to-learn-to-code-is-to-code-6b16961903b?source=rss-29bdddca3721------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b16961903b</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Scott Bewick]]></dc:creator>
            <pubDate>Tue, 08 Nov 2016 16:30:33 GMT</pubDate>
            <atom:updated>2016-11-08T16:30:33.362Z</atom:updated>
            <content:encoded><![CDATA[<p>Many months ago I made a very large, life-changing decision. I decided I was finally going to learn how to how to code and become a web developer. This is something I’ve thought about about for a very long time but for some reason I never pursued. Today I finished writing my first application from scratch.</p><p>I am currently enrolled at Flatiron School’s online program to become a full stack web developer. This application was the first time in the curriculum where they basically said “here’s what you need to build, now go out and build it.” The project required us to build a command line interface application using data we scraped from a website and it had to be completed in such a way that shows an understanding of object-oriented design principles in Ruby.</p><p>The project is relatively simple for an experienced programmer but when it’s your first time staring at your editor with three empty classes and a description of what the app is supposed to do in english, it can seem pretty daunting. I chose to scrape a website that listed all the publicly available Presidential polls for the 2016 election and gave all the details including results for each poll. I turned this data into my CLI app and a Ruby gem called poll_tracker.</p><p>Of all the things I learned during this process there is one item that stands out amongst the rest. It’s something I wish I had know when I was just starting and an easy piece of advice to give to those just starting to learn. Do. Just do. That’s it. Do. What I mean by that is write your own programs. Write programs starting with a blank editor within the first week. I don’t mean the “Hello World!” program that ever programmer in the world has learned forever, but you should do that too of course. Rather, use whatever you learn each day, incorporate it into a simple program and write something from beginning to end. At the start your programs will be boring as hell and they they won’t even look like programs. But they are and keep doing it as you learn new syntax and new concepts and new loops, new anything. The reason I say this is, I think the absolute best way to learn something is to do it. You can read all the books you want but until you are writing code onto a blank screen, it’s not going to crystallize in your mind and you won’t see the full picture.</p><p>Of course there are exceptions to this. Some people can learn from reading and will pick certain skills up faster than others, but most humans make and really re-enforce those neural connections when they do something, and so it was for me with this project. I now realize why the instructors at Flatiron were making such a big deal about writing these apps when we learn a new skill. Yes, they want to make sure we understand it before we move on and yes, it is a good start to a healthy portfolio of projects. Most importantly however, is that it solidifies everything we were supposed to have just learned and easily expose any area where we might have knowledge gaps. In short, I think it’s the most important exercise you can do when learning to code.</p><p>Until now I had been learning a lot through reading and practicing by doing coding exercises in which I would come as close as you can come to writing a whole program without actually writing one. I would write all the methods the program needed and I would follow along the error messages the instructors set up in the testing environment until I has, essentially, a whole program. But it wasn’t mine. someone else came up with the idea, the design, the flow. That’s a big deal I found out. When I finally wrote my first program, all those lessons I read and all the methods I had written suddenly clicked into place. I was able to see it from a 30,000 foot perspective and I was, for the first time, able to see how all of those tests I was doing added up to be one functioning program.</p><p>I’ll admit, while some of my fellow students seemed to be able to put those pieces together right away, I was not and I don’t think I am alone. I think there are a lot of people out there who need to do something to learn it. So when I say start writing programs as soon as possible, it’s because for a lot of people, it’s the only way to make all those disparate pieces of information you are inundated with when learning to code fit together and truly understand what each one’s function is in the larger whole.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b16961903b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>