Thursday, December 20, 2012

Social Coding, Why Did I Wait So Long?

I have been pretty active on Github for the past couple weeks.  Over the previous six months I have used Github to host my code so I could push to Heroku.  I also found myself on Github reading wikis or readme files for some of the gems I use.  As a beginner, I did not feel comfortable getting any more involved in the open source community.

A couple weeks ago I was watching my server logs and thought to myself "Wow, this favicon error that keeps popping up in my logs is really annoying."  It did not stop anything from running, but every call to a view in my app had an error that the favicon path could not be found.  I saw this error in a couple of my apps, and decided to find out what was causing it.  Come to find out the favicon path was being called in my application layout, which was generated by the twitter-bootstrap-rails gem.  It was a simple fix from what I could see.  I just needed to change favicon_link_tag 'images/favicon.ico' to favicon_link_tag 'favicon.ico'.  I changed my code in the application layout, and sure enough it worked.

When I was going through Code Academy (now The Starter League), we were encouraged to get our feet wet by helping out on some open source projects.  I always have been afraid to get involved.  To be honest I was not even sure how to get involved.  This seemed like a really easy fix to make, and I could get my feet wet by contributing to a project.  I went to Github, forked a copy of the project, and started digging through the files.  I realized the folder structure of this project was much different then I was used to with a Rails app.  There were generators, themes, and everything seemed different from what I was used to.  I was finally able to find the generator files that produce the application layout code, and revised the faulty favicon area.  I had to update erb, haml, and slim versions of the layout.  Now that I revised the code, what in the world was I supposed to do to get it back into the main project?

I searched Github and found their documentation to be very easy to follow.  All I needed to do was create a pull request.  As I created the pull request I started to get very nervous.  What if I did something wrong?  What if my code breaks the project?  I have errors in simple code all the time, so how was I to insure I did not overlook something in my little late night experiment?  I figured there was only one way to find out or learn my mistakes, and that is to submit the pull request.  Three hours later my pull request was merged into the project.

I know the change I made was really simple, but I was overjoyed that I was able to finally get my feet wet on a major project.  This also gave me some confidence to dive into the open issues and try to help out others.  Some questions were easily answered, and others were far more complex for me to handle.  One of the open issues was based off of the fact that the read me file was not clear about "fluid" meaning a responsive design.  I updated the readme file, created a new pull request, and this morning that change was merged as well.

Last week I also forked another gem to create a custom version of it for me.  The gem is called blogit.  I needed to customize some of the views and functionality for creating the Reading Glue blog.  I keep the modified version of the gem on my Github account, and can update my apps gem directly by the link back to my version on Github.  For the most part this gem resembles a normal rails app.  It was easier to know where to find files, and to understand what I am looking at.  It was also a great way to dive into more complicated code, and learn better ways to refactor my own code in the future.

One year ago I had no clue how to code outside of some very basic html and javascript.  Nine months ago I started looking at Ruby on Rails, and felt overwhelmed.  Fast forward to the present and I am feeling comfortable contributing to open source projects or forking other people's code for my own customizations.  I am not sure why I chose to wait so long to start using Github for social coding.  Maybe it was just a fear of getting involved and failing in front of the world.  I did not realize the learning benefits that come from contributing to the open source community.

Are you learning to code and only using Github as a way to store your code?  I highly recommend getting involved in a project.  Even if it is closing out open issues, updating a readme file, or something else that is simple.  You likely have the skill set to help out in some way, and I guarantee you will learn more as you continue to stay connected to the project.

Monday, December 3, 2012

Building Just To Build

8 days ago I was exhausted from a day of Christmas decorating. We went to cut down the tree, I hung lights outside, took care of decorations inside the house, etc. I ended the night on the couch with a Celebration Ale and watching Nation Lampoon's Christmas Vacation with Julie. It is a tradition in my family to watch this movie on Thanksgiving weekend. It is also a tradition that we endlessly cite lines from the movie. Over time I have noticed that we are not the only ones that do this. It seems to be a popular tradition among those that are near my same age. I thought to myself "It would be cool if someone had a web app that released a quote from the movie each day of December until Christmas. Kind of like an advent calendar for Christmas Vacation quotes." In the past I would have wished someone would take the time to build out something stupid like this. But wait, I just took a three month intensive training course to make web apps. Why not just build it myself? Well, I introduce you to Griswold Advent.

After getting done with work around 10PM on Monday I opened up iTerm, TextMate, and started coding away. After about 3 hours of work I had a functional app that spit out a quote, and limited when quotes would be shown and on what day. In other words, the system would not start showing the first quote until Dec 1, and you could not see future quotes until the day it was supposed to be shown.

On Tuesday I threw in some Twitter Bootstrap to help give me some quick styling to work with as well as a responsive design for anyone looking at the site from a mobile phone. By this time I was probably about 6 hours into things. I pretty much had everything done. Just needed to clean up some things, buy the domain name, and launch. That is until I spoke with my Uncle. He said it was cool and all, but he would never remember to come to the site daily. He doesn't use Twitter. What he needed was a daily SMS.

I took that as a challenge, and Wednesday night I dove into the Twilio API documents. I started playing around with the Twilio ruby gem, and in about 15 mins was able to send a test SMS out. I started coding and had a fully functional SMS system that could: receive a phone number from a user, store it in a database, send a verification text, receive the verification reply, mark the database entry as verified, and also remove an entry if they texted STOP back to our number. The API was pretty easy to use. Twilio performed a workshop at Code Academy (now The Starter League) when I was going there, but I had not attended. I had something else going on that evening, but kind of wish I had now. It would have made this integration go that much quicker. Even though I had it working in a couple hours, I still had some bugs and problems to work through. Most of the bugs were actually stupid mistakes you make from coding on no sleep. I ended up messing around with things from around 10PM until 4AM to get it all working right and bug free. That also included jumping back and forth between other work I am involved in, but I would say at least 4 of the 6 hours was playing around with Twilio.

Twilio isn't free, and I knew if for some reason my stupid app caught on it could end up costing me some money. I didn't mind it, but it would be cool if my time and money went to a good cause. I decided to promote a charity: water campaign as a way people could give back for the daily laughs they receive. I set that up on the main page as well as learned how to create a rake task that can be run by Heroku to send out the daily texts automatically. I set up a scheduled task to send out the daily SMS messages to those that had signed up. I also had to clean up a few issues that were seen in IE 7 and 8. I am not a fan of IE, so I really didn't want to spend a whole lot of time making sure the site looked good in them. I did what I could in a minimal amount of time and got it looking somewhat presentable. I am sure those users are pretty used to seeing sites that look like crap, so I am not too worried.

I sent out a few emails, posted it on Reddit, and set up a Twitter account. I decided that sending daily tweets out myself was too much work. I needed something automated like the rest of the site. I grabbed the twitter gem and created a scheduled task to send out the daily quote through Twitter at the same time the system sent out the daily SMS messages. Everything was done, and seemed to be working on my development setup. Now it was just time to wait and see what happened at 12AM Dec 1 when the site would stop redirecting to a coming soon page and go live automatically with the day 1 quote. Everything worked like a charm. The next test was at 10AM on Dec 1 to see if the SMS and tweet tasks worked OK. Boom, the SMS was received, but the tweet did not go through. I later found out that there was a problem with how I was truncating the quote, and it exceeded the 140 character limit. By day 2 the tweets were going out automatically as well.

So in about 12 hours of actual working time I designed and built a simple web app that few people will ever care about. I know the amount of time I put into this is way too much for what this app does. That is obvious. The thing is that I really do not care. I had an idea of something I wanted to see built, and I did it. There is a sense of pride in this process that outweighs the time I could have been doing more valuable work. I also exposed myself to the Twilio and Twitter API's for the first time. Most of all, I learned from the experience. These little mini personal hackathons have always been valuable for me learning and being able to take that knowledge and apply it to something more important like Reading Glue. Once you learn how to build things, you find that you seek out little projects to create just because you can. It can become addictive, but it also becomes a great way to continue learning. That is why I recommend to anyone that they should build just to build.