Erik Bryn: Intro To Ember @ LinkedIn

April 10, 2014

I haven't had a chance to listen to the whole thing yet but Erik gives a great intro and talks about what is coming to to ember in 2014.

Building an App with Ember App Kit

March 26, 2014

Searching the internet for tutorials that involve both Rails and Ember has proved quite difficult for me. I have found lots of tutorials that have been out date or that just were hard to follow, but I finally found the one I have been searching for so I thought I would share it with you.

It's a 4 part series by Jason Kriss that walks you through using the Rails-API gem for the backend and how to use Ember App Kit on the front end. So, if you are interested in how to build Rails backed Ember apps check out parts one, two, three, and four.

Ember and the future of the web

March 24, 2014

While I don't have much experience with Ember yet, just working with clients who want a richer more responsive experience on the web I can tell that knowing Ember is going to make your job way easier. I found this post today from The Frontside which talks about the future of the web:

I can’t actually predict the future, but I can bet on it. And Charles and I are betting The Frontside’s future on the fact that Ember provides a foundation for creating amazing, next-generation user experiences for the web.

And they talk about the downside to using Server-side MVC frameworks:

What server-side MVC frameworks are not particularly well-suited to are user-driven, stateful UIs like you’d see in desktop apps like Word, Excel, or iTunes.

It's a great read and if you want to be a relevant web developer in a few years I suggest you checkout this article and start learning a front-end framework.

My First Backbone App

March 07, 2014

If you haven't caught on from my previos blog posts:

  1. Learning Backbone.js
  2. Building Large-Scale Backbone Applications

I'm teaching myself Backbone.

Today I finished my first Backbone application with a Rails backend. It's based off of the initial Rails Tutorial Blog and I had some help from this tutorial.

Feel free to checkout the source and that actual app.

Now it's time to work on my next app that's going to use Marionette.

Building Large-Scale Backbone Applications

March 06, 2014

Brian Mann gave a great talk at the 2013 Backbone conference titled "The tools and patterns for building large-scale Backbone applications". Brian really sums up what is necessary to get over that hurdle from building small Backbone applications (like to do apps) to actually building full featured desktop like applications in Javascript using Backbone. It's definitely worth a watch. Also, can't wait for the 2014 Backbone conference!

Playing with the Help Scout API

March 05, 2014

Help Scout offers a great service for teams to share a single inbox and they also provide an API if you need to further integrate with their service.

To get started all you need is an API Key which you can get after signing up from your profile page under the API Keys section.

Help Scout provides some API Wrappers in PHP and Java, but there is also an unofficial API Wrapper in Ruby that I've been using.

Currently I'm working (as in I just started 1 hour ago) on a small little utility that will track how long it takes for emails to get processed by Help Scout's email servers and show up inside of the app. There are of course lots of other things you can use the API for, such as metrics on what your response time is to emails.

Learning Backbone.js

March 04, 2014

Yesterday I spent all morning learning Backbone.js and I thought I would share a few links might be useful for those just starting out with Backbone.js and I also thought they would be good to refer back to at a quick glance if I needed to figure something out.

Backbone really is not that complicated to pick up and I like that fact that it is just a javascript library and not a full framework. This means that I can easily add it to an existing code base and start using it right away with new features and slowly update the rest of my legacy code as time permits.

exercism.io

Febuary 28, 2014

I signed up for exercism.io a couple of days ago and I've completed two of the ruby exercises. Usually I just come up with my own stupid mini applications to work on as I'm trying something new, but it's nice to have challenging assignments given to me. I've been studying something programming related pretty much every single morning for months now and it's nice that I can add exercism to my regular routine.

I like that once I complete a problem set I can log in and see what other people have done. Which usually points out everything I did wrong. I also like that it is focused on test driven development. Each problem comes with a test file that I run over and over again as I make each little change. It's also nice to have that test file so that as I go in and refactor my code I know I didn't break anything in the process.

So if you haven't signed up for exercism.io I think you should. I don't think it is only for beginners either. Experts can continue to increase their skills and also provide input to others.

Update Column

Febuary 11, 2014

Tonight I worked on updating a single attribute for an existing User. While I think there is still probably room for some improvement, I do have the basic functionality down. There are several rails methods that you can use to update a User in your database, update_attributes, update_attribute, update_column, plus some others.

I ended up going with update_column because it doesn't talk to my Model and perform a validation. Right now this is the only way I could get it to work since I don't want it to update all the other User attributes.

Subdomain Constraints

Febuary 10, 2014

I've been reading through the Multi-Tenancy Rails book and today I studied the section on adding a subdomain constraint and just thought I would expand upon it today because I'm sure I'll need to use them again soon.

Basically a subdomain constraint will limit some routes to use a subdomain and other routes to use the normal domain routes. These constrained routes will be using separate controllerswhich is why we need thes special constraints.

Here is an example of what a constraint looks liks inside of your config/routes.rb file:

constraints(:ip => /192.168.\d+.\d+/) do
   resources: posts
end

If your subdomain is more complex than the above example then you can create your own class for it which is what this book walks you through doing.

Decorators

Febuary 04, 2014

Tonight at #bruby @4lpine talked about using Decorateors on Rails.

Besides just hearing about the decorator pattern in a couple of things that I had read I didn't know much about using decorators. John gave a great introduction to the subject and I can't wait to start cleaning up some of my models and views.

Building Systems That Last

January 31, 2014

Chad Fowler gave a great Keynote address at Garden City Ruby 2014 that I just watched tonight. It's about building decoupled systems that contain many small parts that you can change quickly and frequently. This way the system can last a long time even though its ever changing. This will hopefully save you from large rewrites every 5 years. Funny thing is that I'm currently in the middle of one of those large rewrites, so hopefully I can apply some of these things I learned in this video so that I can build a system that lasts.

Lib Directory

January 25, 2014

Yesterday I wrote about creating my rake task for the longest streak app, but I made a big mistake in putting the class files that will be fetching all the user and contribution info from GitHub from github into the helpers directory.

Esspecially since these files don't contain methods that the models or the controller will be accessing I decided to move them into the lib directory. I think another common place to put files like this would be inside of the models directory, but since these methods, as far as I know, won't be used in the web portion of this project helping to serve data to web pages so I think they belong in the lib directory. Hopefully I'm correct in this, and if I'm not please let me know!

Including the lib directory

Now that I moved my files into the lib directory I need to be able to access them from inside of my rake task. To do this you need to inlclude the lib directory into Rails Load path which you can do by adding the line config.autoload_paths += %W(#{config.root}/lib) inside of config/application.rb:

.
.
.
module LongestStreak1
  class Application < Rails::Application
    .
    .
    .
    config.autoload_paths += %W(#{config.root}/lib)
  end
end

Here is a link to my commit on GitHub addressing this issue.

Rake Tasks and Helper Methods

January 24, 2014

UPDATE: I made a big mistake in this post, read why here.

As I mentioned two weeks ago I started to rewrite my longest streak app so that it could be a Rails app and not just a command line ruby application. I'm not really rewriting it per say, more just putting my existing ruby code into the rails structure. Yesterday I worked on setting up my models. I have two right now, a user model and a contributions model. And this morning I worked on setting up a rake task for connecting to the GitHub API and getting user data. I was able to get my Rake Task to talk to my User model and to also talk to two helper methods that I created.

One of my Helpers is used for setting up my connection to GitHub called connection_helper.rb:

module ConnectionHelper
  class Connection
    .
    .
    .
  end
end

And to access it inside of my Rake task I simply call it like this:

connection = ConnectionHelper::Connection.new

Problems with threads

In my original command line project I was using threads when I collect user data, but It appears I can't use threads inside of a Rake Task so I'm going to have to figure out another way because I'm pretty sure if I ever want my tasks to complete in a reasonable amount of time I'm going to have to use threading.

Accepts Nested Attributes For

January 22, 2014

Today I worked on adding a company name to my signup form. In order for me to get the form to work correctly I discovered that I needed the rails method accepts_nested_attributes_for in my company model:

class Company < ActiveRecord::Base
  has_many :users, dependent: :destroy
  validates :name, presence: true, length: { maximum: 75 }
  validates :plan, presence: true
  accepts_nested_attributes_for :users
end

And then inside your 'new action' inside of your companies controller you need to make sure a new user gets created as part of a company:

def new
  @company = Company.new
  @user = @company.users.build
end

Now finally we can work on our form. The first part of the form you do regularly and pass in @company into the form_for method. And then you notice that we have a fields_for section for the part of the form that has to deal with users.

<%= form_for(@company) do |f| %>
  <%= render 'shared/error_messages', object: f.object %>
  <%= f.label :company %>
  <%= f.text_field :name %>

  <%= f.fields_for :users do |user| %>

    <%= user.label :name %>
    <%= user.text_field :name %>

    <%= user.label :email %>
    <%= user.text_field :email %>

    <%= user.label :password %>
    <%= user.password_field :password %>

    <%= user.label :password_confirmation, "Confirmation" %>
    <%= user.password_field :password_confirmation %>

  <% end %>

  <%= f.submit "Create my account", class: "btn btn-large btn-primary" %>

And that's pretty much all you have to do in order to get a nested form to work.

Active Record Scopes

January 20, 2014

This morning I continued to work on my Daily Weight App so that I could add some more functionality to it. Currently I'm only storing weight entries for each day, but I'm not doing any calculations on the data, like total weight loss and weight loss percentage.

My current model only had a default_scope which will be applied to all other scopes you create. So the first matter of business was to replace this default scope with a non default scope and create another scope that sorted things in ascending order so that I can properly get the first and last values.

Here is an example of a couple of scopes inside of your model:

scope :desc, -> { order('weighed_on DESC') }
scope :asc,  -> { order('weigned_on ASC') }

And then inside of your controller they can be called with:

@weight_entries = @user.weight_entries.desc.paginate(page: params[:page])
@first = @user.weight_entries.asc.first
@last  = @user.weight_entries.asc.last

Here are some links to resources if you want to learn more about scopes:

Rails 4 and Stripe

January 17, 2014

Today I worked on integration stripe into a Rails 4 Application that I'm making for work. Here is a list of links that I used for reference:

Write Command

January 16, 2014

I've been using my blogging engine hotchocolate for over a year now and one of the things I've been meaning to do is create a command to create a new post for me. This is part of the reason I've been learning how Mercenary works this past week.

I'm still planning on keeping hotchocolate around as a learning playground, but I'm pretty sure I'm going to be switching this very blog over to a jekyll powered site so that I can host it on GitHub Pages and get access to a lot more features that hotchocolate currently doesn't have.

One of the features that I've been thinking about adding to Jekyll is the ability to create a new post from the command line. There have been lots of people already who have made their own scripts to do this, but nobody has used Mercenary yet and added this to Jekyll core, or so I thought. First, here are some links of poeple who have created their own scripts to create posts from the command line:

I almost opened my terminal this morning and created a new Jekyll branch so that I could start working on this new feature myself. Luckily I kept searching and found that somebody had already started working this very feature months ago!

So, now what is left to do? Honestly, I'm not really sure, but it looks like some tests might be missing so that is probably something I could work on adding in. The frirst step is to checkout a local copy of the branch and start using this feature for myself and see what issues come up, and go from there.

Adding a CLI to your app with Mercenary

January 15, 2014

As I mentioned yesterday I created a new gem following this tutorial and in it we created a CLI using Thor, but since Jekyll uses Mercenary for it's command line interface I thought I would try and swap out Thor with Mercenary this morning and see if I could still ge things to work.

It was actually really easy and you can see my commit history to see what all I had to do.

This morning I also added some missing tests to the Mercenary gem. Hopefully they will get merged in.

Modules and Gems

January 14, 2014

One of the things what I wanted to learn more about was how Ruby Gems work, mostly because I want to be able to contribute to some open source projects.

One of the first things you should learn about are Modules. I found this tutorial on Modules from JumpStart lab to be super helpful. Basically what I didn't know about modules is that they are used for created a namespace and that you can have a module span many different source files. Knowing those two things pretty much cleared up my confusion.

I found this tutorial about gem development to be super helpful. It walks you through creating your own gem, testing it, and even building out a command line interface for it.

It's Okay to Start Over

January 10, 2014

This morning I started working on another version of my Longest Streak app. My first version was just a simple command line utility that didn't have any tests because I didn't know how to set up different environments for rspec to use. So, this next version is going to use Rails so that I can practice TDD. I'm pretty sure the majority of this app is going to be a Rake task since that is where all the heavy lifting will be. I'll probably only have 1 view for displaying the results. The database is going to be too big for Heroku, so I'll probably end up getting a $5 VPS on Digital Ocean. This will also give me an opportunity to learn how to deploy my own rails app with ngynx.

I'm pretty sure this will by my third version of the Longest Streak app, but that is how you learn. I also probably made like 10 different versions of my Daily Weight app before I finally shipped it yesterday. But keep in mind, these are very small apps with zero user base, so starting over on a much larger application with users should be taken under different circumstances.

Shipping

January 9, 2014

I shipped my very first Ruby on Rails app today! It's called Daily Weight and it is a simple tool for keeping track of how much you weigh so that you can track your progress.

My goal for my first app was that I wanted to make something that I count actually use and something my mom could even use. My whole programming career has been developing applications for businesses that do complex things that would be impossible for my mom or anybody not in the industry to understand. Not only that it is nice to work on an application that I actually want to use in Production mode.

Daily Weight is far from a polished product, but that's okay, I shipped it and I can continue to iterate on it on a regular basis.

Developing with Confidence

January 7, 2014

Like I've mentioned several times before I have started many different project, but still don't have a specific project that I could call complete and actually have other people besides myself using. I've been working the past week on actually finishing my Daily Weight Rails app. It still is not finished, but I image by the end of the week I should have it deployed to heroku and ready to use. Since I've been focusing 100% on Daily Weight I've had to put all my other projects on hold, including writing on my blog apparently and adding to my GitHub streak. But I think my lack of focus before was hurting my progress on mastering Rails so I'm glad I was able to put these other projects aside and actually accomplish something.

In developing Daily Weight I wanted to make sure I practiced Test Driven Development which has slowed me down significantly in innitial development time, but I must say it is really satisfying running bundle exec rspec spec/ and seeing 80 tests pass. I think the time spent writing tests is priceless because now I'll know exactly what breaks as I start adding new features and refactor my existing code.

Working Through Your Frustration

December 16, 2013

I was struggling yesterday trying to figure out how I could delete a word from my word app, but this morning I finally figured out what my issue was. When you use Rails scaffolding it created a before action inside of the words controller that called the method set_word and I didn't notice this method call inside of the before action.

So to get my destroy action to work this morning I simply added this line:

@word = Word.find(params[:id])

I now see why there is a before action because this exact same line is also in the show method and so the extracted it out to keep things DRY. It's amazing how such a simple little problem can slow you down, but when you take the time to work through your frustration the light at the end of the tunnel is well worth it.

Polished

December 15, 2013

I can't believe it is already half way through December and I still don't have a rails app of my own yet that I can use on a regularly basis. I think it is important to work on a project that you will actually use and that solves a problem that you personally have. Client work is hard because it often is for a problem that you don't have and won't use on a regular basis. I think solving my own problems with software, but the problem I currently have is that I usually just write simple scripts that get the job for me and then my code doesn't evolve very much if at all beyond that. Anyways, I've started several projects and I don't have a set due date or anything, but I would like to continue to work on them and make them much more polished.

Something Simple

December 14, 2013

Today I started to build a very simple Rails application with a form for adding words. That's it. But I was able to use TDD, set up validations, and practice proper MVC development.

I know this word app is pretty elementary, but it's good practice to get a way from the bad techniques of building strait up PHP apps.

Understanding Rails

December 13, 2013

I built a couple tiny Rails applications today so that I could continue to learn and master web application development with Rails. I used scaffolding for the apps that I made and I didn't do any testing, so what I want to do is rebuild the apps that I made with using scaffolding and to add some tests to them. It just seems like there is a lot going on and I need to break things down into smaller individual chunks and make sure I understand what is going on.

I feel like past few days I took a break from programming anything in Rails or maybe I was actually avoiding it without realizing it, but doing TDD in Rails is foreign to me and the only way I'm going to get over this hump is to just write a lot of Rails applications.

Jekyll: Multiple Post Directories

December 12, 2013

This morning I started migrating my LDS archive app over to Jekyll. Since it's not really a blog it doesn't make since to just store every article I'm transcribing in the _post directory but from what I learned today I should be able to use categories for each of the separate conference sessions.

I'm switching over to Jekyll because it offers more features that I don't have built into hotchocolate yet, but mainly because I can host it for free on GitHub.

Article Sorting

If you have more than 1 post on the same day you will have to add the time stamp to the YAML front matter.

GitHub Pages Base URL

December 11, 2013

Today I figured out how to add Twitter Bootstrap to my test Jekyll site. And then I spent the rest of the time that I had in the morning figuring out how to set the base URL since I'm using a project page and not a personal page on GitHub Pages.

Fascinated with Jekyll

December 10, 2013

I installed Jekyll for the first time today. It was a lot easier than I thought it would be to get my first post to display. I guess the next thing I should do is host it on GitHub Pages.

[5 min later]

Okay, my new test site is now hosted on GitHub Pages.

My Fascination with Jekyll

I built my own blogging engine almost a year ago because I wanted my own blog, I wanted to use markdown, and I was inspired by Second Crack. It took me probably 4 hours to do and it's been running strong all year and I'm not even sure if I'll replace it with Jekyll yet. I do have another project that I'm working on that I will use Jekyll for though.

Anyways, I think we are going to be seeing a lot more of static file blogging engines and hosting on GitHub pages makes things super simple. I learned a lot building my first blogging engine and I think I still have a billion things more I could learn from Jekyll which is why I want to tear Jekyll apart and figure out it works. Hopefully I can make a few contributions along the way.


Note: In order to get my posts to display I needed to set up my baseurl. See this commit. Ignore the github-pages gem I added, it isn't needed.

Start By Dog Fooding

December 09, 2013

I'm slowly working on my Daily Weight application. I've been tracking my weight almost daily for a while now. While I haven't lost a lot of weight because of it I know it has kept me from crossing the 200 lb line which I never want to be at again. I'm mostly just making this app to learn Rails, but I am hoping I can get some practical use out of it. Today I was able to add date and weight validations, but I still need to make my form to enter in those values. I already have all of the user athentication working and users can sign up and login/logout, but since I'm really just building this for myself right now I kind of wish I had just started with my form for entering in my weight, so that I could start dog fooding it right away and then added multi user support later.

Slow and Steady

December 08, 2013

My importer for Longest Streak is still running pretty strong, just slow (about 20 seconds per 100 users), but I think it should be done importing all 4 millions users by the end of the week. I started working on Daily Weight again and was able to create my model for storing the weight. Hopefully I can finish this part up this week so that I can actually start using my app.

GitHub 50 Years From Now

December 07, 2013

How To Calculated Streaks Longer Than 366 Days?

First of all I think there are only a handful of users who have streaks longer than 366 days. Which means whatever expensive way I come up with to calculate their longest streak I will only have to do it for them and only once.

Storing Daily Streak Count

If I only want to calculate streak counts longer than 366 days once, I'm going to need to start storing the count of commits for every single day of the year for every user. This data can then be used to create contribution graphs longer than 1 year. If I do something like this I probably would try and find a way to make the contribution graphs vertical.

GitHub 50 Years From Now

GitHub is still a baby, but imagine we are in the future 30 to 50 years from now, okay even 7 years from now. GitHub is still going to be around and I think there is a lot of important historical data that we aren't capturing that would be very useful to have. What if we could easily browse the public repos of Alan Turing or Dennis Richie? The truth is we don't have that code any more, but what if we could start today with our current heros of the day slowly contributing to something amazing that our world 50 years from now will be using. We could go back in time, long after that person has passed a way and still see their commits and the important decisions they made.

This is why we study history in school, to learn from our ancesters. In essence we are the sum total of all their contributions. I think there are important lessons to be learned from them and I strongly beleive there are important lessons to be learned from the programmers of today 50 years from now, but we need to have easy access to their code.

Calculating Longest Streak for the Current Year

December 06, 2013

Today I was able to replace the code where I parse the entire users profile page for their longest streak, which is very expensive, with a much lesser expensive request where I only get the calendar data which is returned in a javascript array.

I can then parse that array and calculate their longest streak for the year. I still will need to figure out a way to calculate the longest streak for those users who have a streak greater than 366 days.

I'm my slow netbook which I have running this script it now takes around 20 seconds to collect 100 users and calculate their profile page. On my macbook it takes 10 seconds per 100 users. The only reason why I have it running on my netbook is because it is up 100% of time since it just sits their on my desk. I'll probably move everything to rackspace or ec2, I just don't feel like paying for an extra server right now.

Once I parse the javascript array and I only have the number of commits for each day I Then just count the number of consecutive days that aren't 0's:

def calc_longest_streak(arr)
  longest = 0
  current = 0
  arr.each do |a|
    if a > 0
      current = current + 1
    else
      if current > longest
        longest = current
      end
      current = 0
    end
    if current > longest
      longest = current
    end
  end
  longest
end

Calculating Streaks Longer Than 1 Year

December 05, 2013

I set out to answer the question: who has the longest streak on GitHub? and it's turning into quite the adventure. It looks like for users who have contributed every single day for a year it doesn't calculate their actual longest streak. So not only do I have the challenge of ranking all the users I also need to find a way to get the actual streak count based on contributions older than a year. The problem is that it doesn't appear like the GitHub api has support for this built in. That's okay though, I'm up for the challenge.

Speeding Things Up

December 04, 2013

I'm still having a hard time parsing each users profile page for the longest streak value, so with help from John Otaner I'm going to now just calculate their contributions for the year and if they happen to be equal to 365 then I will parse their profile page. This should speed things up dramatically.

Here is what I have started, but I still need to calculate the streak for the year from the javascript array that this url returns:

def calendar_data(username)
  open("https://github.com/users/#{username}/contributions_calendar_data").read
end

I also wonder what it would take to add the contributions_calendar_data to the GitHub API and Octokit?

Contributing

December 03, 2013

I've always wanted to be an open source developer ever since I started using Linux some 13 years ago, but in terms of open source contributions not much has happened since then. Hopefully I can start changing that though. I don't really have any specific open source projects that I want to contribute to, but one requirement I have, although obvious, is to start contributing to something that I use on a regular basis.

While nothing major, I was able to submit two pull requests this morning. As I continue to improve as a developer and use more gems like octokit I hope I can find ways to contribute and start working on code changes that other people can benefit from.

To End is Divine

December 02, 2013

I've started several different projects as a goal to increase my understanding of Ruby and to improve as a programming, but before I start yet another project I want to make sure I finish the current ones that I'm working on. I'm not sure if any of the projects I'm working on will truly ever be "finished", but they at least need to be in a functional state so that other people can use them and benefit from.

So, with that in mind, this morning I continued to work on my "FIRST" rails app Daily Weight so that I can get it into a state where I can actually use it every day. One of my criteria for an app that I wanted to work on was that I would be something I could use every day. I've been consistently tracking my weight in excel for quite some time and so naturally I thought I could make an app out of it.

I think it is only natural to want to start project after project and never finish them, but I want to get into the habit of finishing what I start. I couldn't find the direct source of this Kevin J. Anderson quote that Chris Wanstrath mentions in this video:

To begin is human, to end is divine

I think this is a great quote to keep in mind before you abandon another project to start something new.

Joining Threads

December 01, 2013

This morning I tried to keep working on my Daily Weight app, but kept getting distracted by my Longest Streak app which was having troubles running for long periods of time. I'll talk more in depth about some of the issues I've been having, but the main one that I was running into has to do with thread.join.

I create a loop of around 100 threads that go and fetch the profile pages of each of the users and then I join all the threads before requesting more users. The problem I'm currently facing is that randomly sometimes thread.join never finishes. I've left it running for over an hour before and it never finished. The only option at this point was to kill the app and then start it up again.

But just now looking at the documentation for Thread it looks like there is a limit parameter I can pass it which may solve my problem I'm having. There also are more methods that should come in handy like status, stop, exit, and kill.

I also should mention that I did try removing the thread.join completely, but that just made the program run super slow. I think it just made way too many threads and bogged down system.

Using Threads For The First Time

November 30, 2013

If you haven't read any of my previous entries I'm currently working on a simple program to figure out who as the longest streak on GitHub. I've been progress every day and now things are really starting to speed up.

404 Not Found (OpenURI::HTTPError)

THe first problem that I fixed was I was getting 404 errors when the username didn't match a GitHub profile page error.

def page(username)
  begin 
    open("https://github.com/#{username}").read
  rescue
    "error"
  end
end

Now I just catch the exception and return "error". I could probably do some more optimization where I don't try and parse the string "error", but I think it is okay to leave it in there for now.

Using threads to parse profile pages

After what I learned yesterday about threading from the Ruby Rouges, I was able to use threads to parse all ~100 profile pages in each batch at the 'same' time instead of parsing them one by one. As you might guess this sped things up dramatically.

Sequel Pool:Timeout errors

I guess one side effect of using threads is that I started getting sequel pool_timeout errors. I "fixed" this by increasing the pool_timout value, but I'm not sure if that was really the best solution.

One thing I could do is store all the results in an array and then do one big insert of about 100 rows. I'm not sure about updating multiple rows at a time though if I don't need to do an insert.

Measuring Thread Performance

I made a quick little video just to see what the difference in speed is now that I'm using threads to parse the profile pages:

In roughly 60 seconds without threads I was able to parse 93 pages, and with threads I was able to parse 313 pages. So, by using threads I was able to increase my performance 3x. Which is huge considering I need to parse 4,000,000+ profile pages. Currently I've stored the longest streak for 105,184 users, which is a huge increase from 30,000. However, it appears to be locked up. My script is still running, it hasn't errored out, but it's not downloading any more users so I'm not sure what is going on there.

Gathering Data

November 29, 2013

Yesterday before I had to put the turkey in the oven I was able to finally start using the GitHub api to start downloading a list of all the users and to parse their profile page to get their longest streak data.

The process isn't really fast and I currently have a bug in my program where sometimes the username doesn't match with their profile page or maybe it is of a deleted user or something and so their isn't a profile page any more. Anyways, my program crashes every time it encounters one of these 404 errors so I need to make sure I catch for that so that I don't have to keep restarting my script.

I really wish that I would have had an answer by now for who has the longest streak on GitHub, but currently only have data for about 35,000 users and there happens to be over 4 millions users.

In the latest episode of the Ruby Rouges podcast they talk about Threading with Emily Stolfo so I think that is something I need to figure out how to do. Currently I get a chunk of about 100 users from GitHub, but then I have to parse the profile page of each user which takes the longest amount of time. From what little I know about threading I should be able to parse all of the users profile pages in separate threads which should speed up my app significantly.

Using API Wrappers

November 28, 2013

This morning I continued to work on my longest streak app, the first one that I started, not the rails one. Today I installed the sequel gem and was able to start writing to my sqlite database.

I was trying to get the selected users url using octokit:

@c = Connection.new
user = @c.user 'oblakeerickson'
puts user.id
puts user.html_url

it returns the id just fine, but nothing shows up for the html_url? Not sure what is going on there, so for now I'm just going to assume that the html_url will be 'https://github.com/#{username}'. But I also want to be able to get the gravatar url, so it just seems weird that none of the urls are showing up.

contributions_calendar_data only shows 1 year of data, so I'm not sure if I can use that anymore to calculate who actually has the longest streak. I'm still thinking I'm going to have to scrape each users profile page.

Still Confused

November 27, 2013

I'm still not sure the best way to go about building the Longest Streak app, but I went ahead in my Rails app for it and created my model today with validations for storing the data I'm gathering from the GitHub API. I'm still doubting myslf if I should even be using Rails at this point for my app since all I really want to be doing is calling a script that dumps data into a database. So, I'm thinking tomorrow that I'm going to go back to working on my command line app and set up the database and start importing data. I feel like I still have a lot to learn and the best thing I can do is get something working and then continue to improve it as I learn better techniques.

Confusion

November 26, 2013

I'll be honest, I'm still pretty confused about the 'best' way to build the Longest Streak app. My first attempt was to just build it in plain ruby and then dump the data into a database, but once I got the database part I got really confused about how I was supposed to test my application. I really want to be writing tests and I also want to turn Longest Streak into an API so I decided to start over and turn it into a Rails Application. Still not sure if this is the right choice or not, mainly because I don't have a clear picture of the development path going forward, but the only way I know how to procede that this point is to just start and figure it out a long the way.

Testing Now That I'm Not Using Rails?

November 25, 2013

This morning I continued to work through the Rebuilding Rails book and I completed Chapter 4 where we created the functionality to use views and erb templates.

I then went back to working on the Longest Streak app that I started yesterday. I fixed the 4 tests that I currently have that I broke yesterday while I was experimenting a bit. Now that I'm getting the data I need from the GitHub API I need to start storing stuff in my database, but now I'm not really sure how to go about testing this part of the application. I know I could just start dumping data in the database without tests, but thats what I'm trying to avoid.

Who Has The Longest Streak On GitHub?

November 24, 2013

Yesterday I set out on a quest to figure out who actually has the longest streak on GitHub. I did some Duck searches, and found Ryan Seys with a streak of 177, but also found that GitHub doesn't have a page on their website that ranks uers by their longest streak. So, there really is no way to tell if Ryan really has the longest streak or not.

It looks like there used to be a website that tracked the longest streaks, but not any more, so it looks like I have a great opportunity to make my own app.

My first thought that I had on how I should make the Longest Streak app was to parse each profile page of every single user and get their Longest Streak that is displayed on the page. Which quickly led me to the much smarter way of doing things, the GitHub API. I then played around with curl for awhile to see what all I could do. That then led me to Octokit so that I can use Ruby to make calls to their API. Now we are getting somewhere.

So, this morning I was able to start working on my app to figure out who has the longest streak. My first task was to figure out how I could get a list of all the users. You can only grab ~100 users at a time and there are only 4 million+ users, so it will take awhile to get them all, and store them in my database. But once I do I shouldn't have to do a query everyday of all the users, I can just query for new users.

Once I get a list of all the users, I'm still going to have to figure out how to calculate the longest streak for each user. Which I htink I can do with contributions_calendar_data, but not sure if I can get the previous year yet or not.

I'm off to a humble start, but you are more than welcome to join me in my quest in figuring out who has the longest streak on GitHub.

A Good First App

November 23, 2013

This morning I was able to wake up early and work on my own Rails application. I'm mostly still following the Rails Tutorial since I'm still working on building the sign up form, but it is nice to actually be working on my own app. I'm building a simple Rails app that allows users to track how much they weigh every day so that they can chart their progress and hopefully loose weight (or gain weight if that is your goal). I just thought it would be a good first app to venture out on my own with. I'll keep you updated on the progress as I continue to work on it.

Understanding Your Enigma Machine

November 22, 2013

This morning I continued to work on my own Rails app and was successfully able to get password authentication to work. I learned about the rails method has_secure_password which does a lot for you.

I've been reading The Man Who Knew Too Much: Alan Turing and the Invention of the Computer and I'm at the section where Turing is working on cracking the codes that come from the Enigma machines. The problem is that the Enigma machines keep getting more and more sophisticated and so Turing keeps having to invent more and more creative ways to figure out how to decipher the encrypted German messages. The book talks about how Turing had to create a whole new framework to crack these new codes by the latest Enigma machines and that he had books of notes over a hundred pages long. While I'm in no way putting myself on the same level as Turing or the complexity of his work with my legacy code challenges it hit me yesterday that I essentially need to do the same thing as Turing did to crack the Enigma codes as I need to do in order to get the 8 year old legacy PHP code base that I'm now in charge of under control.

What this will entail, I'm not quite sure yet, but I bet if I had a hundred pages of notes on how my app is supposed to work I'd be a lot closer to taming the beast. My goal is to turn it into a Ruby on Rails Application, but that's not so simple when you have lots of users and clients paying for enhancements every month. We can't just put everything on hold and rewrite it from scratch.

Knowing The Deepest Levels of Software

November 21, 2013

Today I started going through the Rebuilding Rails book and was able to finish Chapters 1 and 2. One of the main things that I learned was how to build a gem and use it in another app.

Here is a quote from he book:

Knowing the deepest levels of any piece of software lets you master it.

I don't want to be 'just' a programmer that builds web apps. I like to create things, and I also want to build tools that help me be a better programmer. I think there is great leverage in using Frameworks and other tools, but I do think there is a clear distinction in the type of programmer that is boxed into only being able to do what the framework provides and doesn't have the ability to create supporting tools, gems, or whole new frameworks.

I was talking with my boss yesterday and he is going to let me rewrite one of our smaller php applications into a Rails application. I think it is a huge opportunity for me and I'm super excited that I get to work in ruby at work again. It will also be good to be able to demonstrate the benefits of tests, migrations, security, and other perks of using a framework.

Subselect Statements

November 20, 2013

Today I FINISHED the Ruby on Rails Tutorial - Learn Web Development with Rails by Michael Hartl. I started going through the book on Nov. 5th so it took me around 1-2 hours a day for 16 days to get all the way through. I'm also using it heavily as a resource for building my first Rails App of my own.

A couple of things I learned about today were:

Embedding Ruby In JavaScript

November 19, 2013

This morning I was able to get almost all the way through Chapter 11 of the Rails Tutorial, but I had to stop at section 11.3 because I ran out of time. I'm glad that I made good progress on the tutorial, but I didn't give myself a chance to work on my own rails app this morning. That is something that I want to do everyday though, so I should try to find some time to do that later today. I just want to make sure I'm in the habit of making my own things and not just blindly reading tutorial after tutorial with nothing to show for it besides a lot of blog posts.

Some of the things that I learned today:

I did think it was interesting that we are embedding ruby into our javascript code. I ignorantly assumed this was a bad thing with the legacy php code I've been working with, just because it was making the code really hard to read and to segment into their own files. Now I want to read more about what the best practices are with embedding ruby/php code into your javascript.

Solidify Your Learning

November 18, 2013

This morning I was able to get all the way through Chapter 10 of The Rails Tutorial. Which means I only have one chapter left. My speed that I'm going through he book has slowed a bit since I've also been working on my own Rails App. While I have learned a lot going through this tutorial, taking the time to build my own app is really solidifying all the new knowledge that I've been taking in.

Refactoring Into app/helpers

November 17, 2013

This morning I was able to work on my own Rails app for a little bit and then I continued working the The Rails Tutorial where I was able to get part way through Section 10.3. Here are a couple of things that I learned:

Precompiling My Assets

November 16, 2013

This morning I got to section 10.2 of the Rails Tutorial and then I shifted gears and continued to work on my own rails app. I have it pushed to heroku, but for some reason its not loading my css even though it works fine on localhost.

I'm not sure if this is the best way to fix my issue with Heroku not loading my css, but I got it to work with:

`bundle exec rake assets:precompile`

Toggle!

November 15, 2013

This morning I finished Chapter 9 of the Rails Tutorial and then I went back to working on my own Rails app. I didn't get very far today, but I now have a very simple home page with one test. Hey it's a start.

Some things I learned about today:

Today on my way into work I listened to Going on a Testing Ant-Pattern Safari by Aja Hammerly from MountainWest RubyConf 2013.

Venturing Out On My Own

November 14, 2013

Today I got to section 9.3 of Chapter 9 before I got bored with just following the tutorial blindly and decided to start making my own Rails application. Don't get me wrong I'm still going to finsih working through the tutorial, I just wanted to start venturing out on my own a little.


I listend to How to Learn yesterday. The Ruby Rouges got side tracked a few times, but Katrina had a lot of good picks. One was a video about being able to learn any new skill in 20 hours and the other pick was one of my favorate books, So Good They Can't Ignore You.

Permanent Cookies

November 13, 2013

This morning I finished Chapter 8 of the Rails Tutorial. It would be nice to be able to finish the rest of the tutorial before the end of the week. There are only 3 more chapters so I think I can pull it off. Especially if I have a little extra time on Saturday.

Here are a few of the things that I learned about today:

I Only Had 20 Minutes

November 12, 2013

I only had about 20 minutes to study this morning before I need to start work, but I was able to finish another section in Chapter 8 of the Rails Tutorial. Hopefully I can set aside some time tonight so that I can finish the rest of the chapter. I really want to finish this book so that I can start working on my own Rails app. Here are a couple of the things that I learned about today:

Even though I only had a few minutes I'm glad I took the time to continue to make progress.

Strong Parameters

November 11, 2013

Today I was able to complete Chapter 7 and start working on Chapter 8 of the Rails Tutorial.

Factories

November 10, 2013

Today I started going through Chapter 7 of the Rails Tutorial where we started working on our sign up form. Some of the things I learned about were:

Has Secure Password

November 9, 2013

This morning I finished chapter 6 of the Rails Tutorial. I learned about:

Also here is a fun little video called MRI Magic Tricks that I watched this morning.

Regularly Read Your Source Code

November 8, 2013

This morning I did my best to get into work as early as possible(6:13 am) so that I would have enough time to finish Chapter 6 of the Rails Tutorial. Unfortunately upgrading to Mavericks that I did several days ago mest something up with the XCode command line tools and I had to get that fixed before I could use my 'rails' command in the console. Not sure why I didn't have a problem with this until this morning, but I did get it resolved! It just took until 7:20 am until I could actualy start going through Chapter 6.

I was only able to get to Section 6.2.2. but I did learn about setting up a test database and creating a user model. I also learned that with Rails 4 you should use find_by with a hash of what you want to find inside like, find_by(:email, 'blake@example.com') rather than find_by_email.


Last night on my way home from work I listened to Farther, further, faster. In this episode dhh talks about how he regularly reads all of the basecamnp source code. They don't have very string code reviews at 37signals and reading the source code is a good way for him to get familiar with what everybody has worked on and be able to offer any suggestions for improvment. But I liked the fact that he isn't a dictator on what goes into production and that everything doesn't has to funnel through him.

I want to be better about reading all the source code that I work on at my job. I've been here 6 months and I still haven't had a chance to read through all of it yet. Which can be frustrating at times because I often have to fix bugs in areas of code that I have never seen before or even knew existed. I also think readying through the source code solves the lack of documentation problem we have. I'm also hesitent to start writing documentation beyond some simple readme files because I fear they are just going to get out of date very quickly, but regularly reading through the source code never gets out dated.

Decoupling

November 7, 2013

Today I went through Chapter 5 of the Ruby on Rails tutorial. Some of the things I learned about were:


At work yesterday I started working on moving over one of our sections of code to use more of a MVC style layout. I made good progress, but I feel like I skipped a step and I need to first finish decoupling all of the css (style tags) and javascript that have php tags sprinkled inside of them and move them to their own separate files.

Rebuilding Rails

November 6, 2013

Today I went through the first chapter of Rebuilding Rails where I learned how to create, build, install, and use my own gem. I also built my first application on top of Rack.

Today I also finished Chapter 4 of Rails Tutorial.

Here is another resource I found yesterday about how to create your own framework(in PHP).

As one of the bullet points under "Why would you like to create your own framework?" it says:

To refactor an old/existing application that needs a good dose of recent web development best practices;

So, I'm hoping to use this guide and any other resources I can find as inspiration on how I can refactor the old code base I'm in charge of at work. Our legacy code base definitely needs help, but currently with the amount of new custom features our clients are paying for I can't justify letting the current code base sit for months while I work on a rewrite in Rails. I'm pretty confident that refactoring the application to use the MVC architecture and to have Unit tests is the proper path to take so that we can properly maintain it and add to it while we work on a rewrite on the side. Basically I'm "just" going to build in my own framework inside the existing code base. Easy right?

Great People Do Things Before They're Ready

November 5, 2013

I still don't like the fact that I don't have my very own Rails app out in the wild with users that I can work on regularly to master learning Rails, so I decided to continue going through the online Rails Tutorial book. Today I finished chapter 3. Hopefully it won't take too much longer for me to finish the rest of the tutorial and feel some what comfortable starting my own Rails application.

Just a couple of things I learned from chapter 3:

My wife found this quote on pinterest last night:

Great people do things before they're ready. They do things before they know they can do it. Doing what you're afraid of, getting out of your comfort zone, taking risks like that - that is what life is. You might be really good. You might find out something about yourself that's really special and if you're not good, who cares? You tried something. Now you know something about yourself. -Amy Poehler

I'm probably never going to be "ready" to start making production quality Rails apps by just reading a book. I'm just going to have to start making my own app (even though I'm not ready) and struggle through it. I keep trying to find the magic tutorial to teach me Rails, but I don't think it exists. Struggling through my first app and not giving up is the only real way to master this stuff.

minitest Argument Error

November 4, 2013

To get into the habbit of TDD and to master the fundamentals of ruby I'm making a simple command line application. It's an app that will track my daily weight, but the goal of writing this app is not what it does, but what I learn from making it.

Like I've said before it is really easy to just read tutorial after tutorial soaking in a ton of information, but never really taking the time to apply all of that new material. So, now I'm working on making the rubber hit the pavement and I'm working on a simple ruby app to streatch my abilities.

One of things that I learned today was testing for a raised argument error. Here is the code that I worked on today:

It actually took me awhile to figure this out this morning. These two posts helped me figure it out though:

The problem I was having was that I was creating my object before I was calling my assert_raises statement, just like I do in my first test. But I figured out that you put the code that raises the exception inside of the '{}' right after the assert_raises statement.

Good Testing

November 3, 2013

I watch this Killing Fibonacci video from Wicked Good Ruby 2013. This is a great video on TDD and I love the play by play videos. I esplecially enoyed the part where Dan refactors his redundant tests down to just one test statement. Here is a link to the source code he used during the video.

Learning About minitest

November 2, 2013

Today I read through Steve Klabnik's tutorial on minitest.

I'm trying to get into the habit of TDD and minitest seems like a great place to start for some of these command line apps I'm working on. RSpec is another testing framework I would like to learn.

Steve also used Enumerable#inject which I should practice using. I do remember using Enumerable#reduce before, but using Enumerable still doesn't come natually yet.

Tutorials are great, but I need to make sure I also spend some quality time working on my own code that expands beyond these tutorials. It's easy to get trapped into reading tutorial after tutorial and never having to really put into practice the things you are learning.

Discovering Thor

November 1, 2013

Today as I continued my quest to learn about writing command line applications in ruby I stumpled upon Thor which is: "...a toolkit for building powerful command-line interfaces. It is used in Bundler, Vagrant, Rails, and 197 other gems."

I worked through the getting started page and I like what I've seen so far and I plan on getting acquainted with Thor as I continue to write some command line tools.

I believe my first introduction to Thor was actually from the Ruby Rogues Podcast: 116 RR Non-Rails Projects, but I could be mistaken, because I see no mention of Thor in the show notes. Anyways, I did hear about Thor from one of the episodes, but failed to follow up after hearing about it. But when I stumpled upon the Thor website today, I knew I had found what I was looking for.

Ruby Command Line

October 31, 2013

Today really quick I went through some of ruby tutorials on learn to code the hard way. Here are some of the things I learned:

Habits

October 30, 2013

A couple of days ago, I listened to a great podcast episode from Giant Robots and on it they talked about the habit of writing 1,000 words every day and how much you can accomplish over time by simply being consistent.

I'm not really sure how to go about this yet, but I want to get in the habit of deliberate practice every single day. You can measure your output as a programmer by the number of lines that you write, but I don't feel like counting lines of code is really a good indicator of output. Just the other day I spent hours learning about regular expressions and all I did was write one line of code. So, probably the best indicator to track is time.

My goal with getting into the habit of daily deliberate practice is not to just write code that I'm familiar with writing, but to learn new programming techniques that stretch my mind and might be very difficult for me at the moment.

For example, writing a new web application in Sinatra would be very easy for me to do, but creating a web application using a web framework like Rails would be quite difficult at the moment. However, I'm sure that if I were to work on Rails programming for 'x' number of minutes every single day after just a few weeks I'd be very comfortable in my abilities.

LDS Archive Launch

October 16, 2013

This is a project that I started a long time ago and was originally going to be an iOS app. I haven't done much with it for awhile actually, but it's something I'm still interested in and thought I should release it to the world.

I started building LDS Archive because I was reading a lot of General Conference talks, but on the lds.org website they only have talks going back to 1971. My interest in talks pre-1971 started because I would read all the talks from one of the General Authorities, like Gordon B. Hinckley, starting with the present day and going back each conference. I then of course ran into a roadblock because there were more conference talks, but they weren't redailty availibly online.

Until now, the only way to get access to these older General Conference talk was to read the difficult to read pdf formats on the Internet Archive. So, out of my desire for more I decided that I would embark on converting all of the pdf's into easy to read markdown. I've already converted most of the talks from (October 1970)[http://ldsarchive.herokuapp.com/talks/1970_oct] and will slowly keep at it one talk at time.

I also decided to open source the project so that anyone interested in helping can do so. )

Ruby, Discourse and Jeff Atwood

October 15, 2013

Today on my way to work I was suprised to find yet another podcast with Jeff Atwood as the guest.

Anyways it was a great episode and I especially like the part about not giving up on finding ways to speed up Ruby.

Grit

September 18, 2013

Today on my way home from work I listened to Sandi Metz's talk from La Conf Paris 2013 titled Grit & Determination.

Sandi takes us on a journey about her 2001 bike race and through her experiences writing her first book.

It's a great talk about not worring about being the smartest person because it's the people who take the time to just work at it little by little each and every day that end up becoming champions.

Remove Argument-Order Dependencies

September 17, 2013

I'm now working my way through the third chapter of Practical Object-Oriented Design in Ruby where we are learning about managing dependendies between objects.

Distracted by a shiny new operator

The first thing that I want to mention is the use of the ||= operator. I had never seen the "or equals" operator before and so I was distracted for awhile from this chapter until I read enough about it's meaning to figure out what it does.

Using a hash as a paremeter

This chapter talk about several different ways to reduce your dependency on other objects, but the one about using a hash to pass in parameters really tickled my fancy. Here is an example class that I made up that passes in a hash of arguments.

class Foo
  attr_reader :apple, :orange, :taco, :juice
  def initialize(args)
    @apple    = args[ :apple]
    @orange   = args[ :orange]
    @taco     = args[ :taco]
    @juice    = args[ :juice]
  end
  ...
end

Foo.new(
  :apple  => 3,
  :orange => 7,
  :taco   => Taco.new(14, 2),
  :juice  => 19).food_calculate

The benefits of using a hash are:

  1. It removes every dependency on argument order
  2. Adds verbosity
  3. The key names in the hash tell us what we are passing in.

I really like point #3 because without the hash our code will be confusing and we won't know what the numbers mean when we create a new Foo object like this:

Foo.new(3, 7, Taco.new(14, 2), 19).food_calculate

This section of the chapter really stood out to me because I really could have used this today at work to make it much more clear about what I was passing into one of my classes.

Isolating Extra Responsibilities

September 16, 2013

Today I got a chance to read through Chapter 2 of Practical Object-Oriented Design in Ruby which is about designing classes with a single responsibility.

In this chapter we start by building a simple class with single responsibility, but then we start adding to it and it quickly starts to do more than one thing. The problem that we face as our class starts to grow is that we still aren't clear about the future responsibilities of our program and so we aren't quite ready to build a completely new class yet to separate our responsibilites. One thing you can do as you start to break apart you growing class is to create a Struct. Creating a struct might only be a temporary solution, but it allows us to clean up our class and defer any future decisions about building a second class.

Here is an example of creating a struct:

Rectangle = Struct.new(:length, :width) do
  def area
    length * width
  end
end

Here is some more info on structs from Steve Klabnik that you might find useful.

Back to the Basics of Object-Oriented Programming

September 15, 2013

So, I’m really confused right now and not really sure what to do about learning proper programming principles, techniques, and skills because at the same time I need to modify legacy code to enable new functionality that our clients need.

While I am starting to use classes and instantiate objects I still feel like I’m writing procedural programs and not true Object Oriented programs.

I want to start using a testing framework like PHPUnit but it’s inner working are very object oriented and doesn’t even work with older version on php.

I bought the book “Working Effectively with Legacy Code”, but it is also very heavy on the OO side.

My ultimate goal is to turn our existing legacy php code into Ruby on Rails applications while at the same time maintaining the legacy php in order to keep our customers happy and the business alive. In order to accomplish the enormous task I'm going to need to refactor the legacy code and starting adding in tests so that I'll know when things break as I start adding functionality. I also see all of this refactorying and testing as an important process to learning how the current code base works, so that when I start building our Rails app I'm not going to be leaving out key features and functionality that I had no ideas existed.

I’ve been trying to learn Rails, and some PHP frameworks (Zend and Lithium), but I feel like my limited knowledge in OO programming is getting in my way. And so I feel like I need to take a step back and learn the principles of Object-Oriented programming before I can truly transform the software into the clean and elegant programs I know they can become.

I have a book called “Practical Object-Oriented Design In Ruby” which I think will be a good start for me, but I’m not sure if there is a more appropriate book that I should be reading to learn the fundamentals of Object-Oriented Programming? I'll let you know how it goes.

Ignoring Appealing Side Projects When Trying To Learn Something New

July 15, 2013

I started working on a new iOS app a couple of weeks ago. The first few iOS apps I made 6+ months ago were just for learning that I never really intended to go into the app store. I'm really intending on submitting this app to the app store, but I'm really making this app because it is something I would use daily. I do have a fear that it is going to be rejected, but even if it doesn't make it into the app store I still beleive it will be a worthy pursuit.

Anyways, I did start working on my app a couple of weeks ago, but quickly got stuck. My objective-c skills were never that great to begin with and on top of that I was quite rusty because I hadn't really used xcode in 6 months. I tried looking a lot of stuff up online and even found a few great answers on stack overflow that were getting me closer to my destination, but after plugging away for a couple of days I realized I was starting to build a frakenstein of an application that should be killed now before ever being brought to life.

Realizing that I'm lacking some fundamental knowledge I decided to purchase Objective-C Programming - The Big Nerd Ranch Guide and get to work on building a solid foundation of knowledge that hopefully I can build any iOS app I want on top of.

I'll be honest that waking up early (almost) every morning to study Objective-C instead of writing code toward a new project hasn't been easy. And everytime I sit down to study I seem think of some new web app idea that I could be working on instead in a language I'm more comfortable with. But so far I've been successfull ignoring those tempting distractions that would ultimately take me away from my end goal. Right now I'm sticking to my guns and will continue to plow through mastering Objective-C so that I can not only make this app I wish I had, but so that I could make any other iOS app at a much quicker pace when the time comes.

The Best Way to Learn Lithium

April 13, 2013

I was introduced to Lithium PHP last week and since then I've been learning as much as I can about the framework.

However there comes a point when the documentation and tutorials can only get you so far. And if you really want to master something new you need to write real applications with it.

So after just a few hours of coding I came out with the first version of DailyWeight.net. It's a simple app that is far from complete, but is certainly usable. Currently you can sign up for an account, login, logout, enter your current weight for a specific day, and see a list of each of the days where you have tracked your weight.

The entire goal of making this app was to not only learn the basics of Lithium, but learn some of the advanced things it can do, as well as get me really familiar with the framework so that I can contribute to the project.

It's hard to get stuck while following tutorials. The real learning comes when you stretch yourself and attempt to make something that doesn't exist yet. Here are some of the things I learned while making dailyweight.net:

Things I learned:

Things I'm going to work on next

I already have an idea for the next app I'm going to make and as I continue to learn more about php and Lithium all the peices for it are coming together nicely in my head. I'm sure I'll start working on it soon.

What app are you going to make to learn Lithium?


Lithium Advanced Setup

April 11, 2013

So in the process if getting familiar with Lithium PHP I've probably installed it like 30 times by now and finally realized the need to store the actual lithium library files in a single location on your computer rather than having lithium installed in every single project folder you start.

I realized this was a problem when I was trying to use git while working on a project between two different computers and whenever I would do a git pull it would break the application and I couldn't even get it to run.

So, if you have already started working on a project and you have the lithium core inside of your project folder already, this is how you can remedy the situation:

cd /usr/local/lib
git clone https://github.com/UnionOfRAD/lithium.git

Now change into your projects webroot folder. It should be something like this:

cd /var/www/my_app

or on OS X:

cd /Library/WebServer/Documents/my_app

Now login in to your github account online and create a new repository with the same name as your project folder. Once that is done you can run the following commands:

git remote rm origin
git init
git rm -r library
git add .
git commit -m "removed lithium library folder"
git remote add git remote add origin https://github.com/username/my_app.git
git push origin master

Now your app is currently broken because we need to fix the location of your library folder.

Open up my_app/app/config/bootstrap/libraries.php and change the LITHIUM_LIBRARY_PATH line to be:

define('LITHIUM_LIBRARY_PATH', dirname('/usr/local/lib/lithium'));

Now our app should be working again. Browse to:

http://localhost/my_app

and you should see your app working just like before.

Now apply your changes

git add .
git commit -m "fixed location of lithium library"
git push origin master

New Project setup

If you want to create another lithium project and you already have the lithium library in /usr/local/lib/lithium you don't have to do the git submodule any more to get the new app to work.

So, to set up a new lithium project, simply type:

cd /var/www/
sudo git clone https://github.com/UnionOfRAD/framework.git new_app
sudo vim /var/www/new_app/app/config/bootstrap/libraries.php

and change the LITHIUM_LIBRARY_PATH line to:

define('LITHIUM_LIBRARY_PATH', dirname('/usr/local/lib/lithium'));

and when you browse to:

http://localhost/new_app

The default lithium page should be displayed.

Resources


How To Configure Lithium PHP On OS X

April 10, 2013

I'm currently running OS X Lion on my MacBook Pro and in order for me to get Lithium PHP working right I had to consult several different sources, so I thought I would organize all the steps I took in this blog post to hopefully help you out.

Apache

On OS X Lion they removed the gui option to enable web sharing, so we need to use the command line:

sudo apachectl start

Now open up your browser to http://localhost see that apache is running.

The web page that loads should say "It Works!"

Now we need to modify some settings in the httpd.conf file

sudo vim /etc/apache2/httpd.conf

Scroll down for awhile until you find the <Directory /> section and change

AllowOverride None

to

AllowOverride All

Then scroll down some more to the <Directory "/Library/WebServer/Documents>" section and change

AllowOverride None

to

AllowOverride All

NOTE: this section in my httpd.conf file was split up with a bunch of comments so it looks a little different.

Homebrew

We are going to be installing several different packages and the best way to do this is to use Homebrew. Paste this into your Terminal Prompt:

ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

and follow the rest of the instructions.

PHP

OS X should actually have PHP 5.3 Installed by default, but let's go ahead and install the latest version.

brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
brew install php54

Now we need to update our httpd.conf file:

sudo vim /etc/apache2/httpd.conf

Type /php5_module then press enter to find the right line. Make sure this line is commented out and then add a new line right below it that contains:

LoadModule php5_module    /usr/local/opt/php54/libexec/apache2/libphp5.so

Now if you type php -v it should still say 5.3. We don't want that so let's update your $PATH:

vim ~/.bash_profile

and add this to the very end of the file:

PATH="$(brew --prefix josegonzalez/php/php54)/bin:$PATH"

Now if you open up a new terminal window and type php -v it should say 5.4.13.

PEAR and PECL

curl http://pear.php.net/go-pear.phar > go-pear.php
sudo php -q go-pear.php

This will prompt you for a couple of things in the command line. Press 1 and change the new installation base ($prefix) to /usr/local the press enter to continue.

Now update your php.ini file

sudo vim /usr/local/etc/php/5.4/php.ini

And change this line:

;include_path = ".:/php/includes"

to:

include_path = ".:/usr/local/share/pear"

And because we already have our php.ini file open let's go ahead and fix another section that Lithium will complain about. Find the line:

magic_quotes_gpc = On

and change it to:

magic_quotes_gpc = Off

Lithium PHP

Now it's finally time to set up Lithium PHP. Change to your document root:

cd /Library/WebServer/Documents/
git clone git://github.com/UnionOfRAD/framework.git my_app
sudo chmod -R 0777 my_app
cd my_app
git submodule init
git submodule update

MongoDB

Now let's set up our database:

sudo mkdir /data sudo mkdir /data/db sudo chown -R $USER /data/db

Since we already have homebrew installed this should be easy:

brew update
brew install mongodb

Now to get mongo and php to work together type:

sudo pecl install mongo

Now we need to update our php.ini file

sudo vim /usr/local/etc/php/5.4/php.ini

and add this line to the very end of the file:

extension=mongo.so

To start mongo type:

mongod &

Now we need to modify or connections file:

sudo vim /Library/WebServer/Documents/my_app/app/config/bootstrap/connections.php

and uncomment the following lines:

Connections::add('default', array(
    'type' => 'MongoDb',
    'host' => 'localhost',
    'database' => 'my_app'
));

Is Everything Working???

Before we check to see if everything is working let's go ahead and restart apache:

sudo apachectl restart

Now you can browse to http://localhost/my_app to see the lithium status page. It should look like my screen shot below with a checkbox next to MongoDB.

Lithium

If you are lucky everything should be working now and you can finally start working on your Lithium PHP application :)

Resources


Scrum

April 10, 2013

SCRUM is a way to organize the creation of software so that you can produce your end result of shipping high quality software that meets your “clients” expectations.

At a high level overview I really like scrum because it keeps your team cross-functional (instead of everyone retreating to their silos of familiarity) and because everyone on your team is working on the same project during the sprint it breeds a much better environment for collaboration.

Below is simply a list of my notes about the keywords and ideas that make up scrum.

SPRINTS

DONE

Done means that your software is integrated, fully tested, end-user documented, and potentially shippable. At the end of the sprint if your product isn’t shippable than you probably lack some automation or your team isn’t cross-functional enough.

SCRUM ROLES

PRODUCT BACKLOG

A prioritized list of features and does not contain user stories. * Detailed Appropriately - Top priorities are more fine-grain than lower priority items * Estimated * Emergent - The product backlog is regularly refined. Items may be added, removed, modified, split, and changed in priority. * Prioritized - Most bang for your buck, tackle high risks early before the risks attack you.

SPRINT PLANNING

You have a meeting that is 1 hour long / week of sprint.

Sprint Planning Part 1:
Spring Planning Part 2:

NOTE: Only volunteer for one task at a time.

DAILY SCRUM

NOTE: This is for the benefit of the team and is not a status meeting to report to a manager.

TRACKING PROGRESS DURING THE SPRINT

PRODUCT BACKLOG REFINEMENT

TIP: Some % of each sprint should be dedicated by the whole team to refining the product backlog to support future sprints

SPRINT REVIEW

SPRINT RETROSPECTIVE

STARTING THE NEXT SPRINT

MANAGING RELEASES

Summary

Basically scrum keeps your teem from working on multiple projects at the same time, being segragated by defined rolls (which solves the John got it by a bus delema and we have no idea how to do what he does), keeps you from making software that isn't tested or documented, and should help you achieve the end goal of shipping code that will be of a higher quality then if you didn't use scrum.

Start by reading the Scrum Primer if you want to learn even more about scrum.


How to Correctly Configure Ubuntu to Run Lithium PHP

April 07, 2013

I struggled for awhile to get Lithium PHP up and running and since the documentation for it isn't the best, I thought I'd write up this little tutorial so that you don't struggle with the same things I did.

First of all I used VirtualBox to create a brand new Ubuntu 12.10 virtual machine to set everything up. I think it is always a good idea to us a VM for anything new that you are trying so that you don't screw anything up that you depend on on your host system.

Now that you have a fresh installation of Ubuntu let's get started installing and configuring the necessary software required for Lithium PHP to run.

The first thing we need to do is install PHP5 and Apache:

sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get install libapche2-mod-php5
sudo /etc/init.d/apache2 restart

Now we need to configure Apache. This is where I got hung up and it isn't mentioned in the Lithium Quick Start Guide.

Use Vim to open the default config file:

sudo vim /etc/apache2/sites-available/default

I only edited line 11 in this file, everything else should stay the same. Change AllowOverride None to AllowOverride All. The file should look like this when you are done:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

We need to enable mod_rewrite. To do this type:

sudo a2enmod rewrite

now restart apache:

sudo /etc/init.d/apache2 restart

Now let's configure PHP to display error messages:

sudo vim /etc/php5/apache2/php.ini

Once inside of vim press the '/' and type:

error_reporting

followed by the 'enter' key, then press the 'n' key. Then delete the rest of the line so that it only says:

error_reporting = E_ALL

Now scroll down around 10 or so lines and you will see

display_errors = Off

change it to be

display_errors = On

Now that we have PHP5 installed and Apache is configured correctly we can safely install Lithium PHP.

Change into the /var/www directory and run the following commands:

cd /var/www
git clone git://github.com/UnionOfRAD/framework.git my_app
cd my_app
git submodule init
git submodule update

Now we need to fix the permissions on our resources directory:

sudo chmod -R 0777 app/resources

Now we need to setup our database.

sudo mkdir /data
sudo mkdir /data/db
sudo apt-get install mongodb php-pear php5-dev
sudo pecl install mongo
sudo vim /etc/php5/apache2/php.ini

Press 'G' to go to the end of the file. Then Press 'o' to start inserting on the next line. Then Type:

extension=mongo.so

Edit the file /app/config/bootstrap/connection.php and uncomment the lines for the MongoDB Connection.

Now in your browser go to:

http://localhost/my_app

And it should look like:

Lithium

If it doesn't, something isn't configured right and you probably shouldn't move forward until you get the problem resolved.

Now that we have everything set up correctly on our fresh Ubuntu installation we can now start programming! You should be able to follow the rest of the Lithium quickstart tutorial. Start with the section where it says "MVC Starts with M".

After you create the view, you should be able to browse to

http://localhost/my_app/posts/

And you should see:

Lithium-Posts

Hopefully this little tutorial helped you get started with Lithium PHP.

Here is a list of resources that helped me along the way:


Validations

March 22, 2013

I started learning web development with Sinatra, which so far has satisfied my needs and has gotten the job done, but I think I’m starting to experience it’s limitations.

I'm in the process of learning Rails and I learned how to apply validation to forms. If you don’t know what validation are, they are basically a way to ensure that the data in a form you are submitting meets certain criteria. For example in a registration form you have an email address, username, password, password confirmation etc. and you want to make sure that a user doesn’t sign up with a username that is already taken.

When I made my registration form for networkcraft.net I hacked together my own validation, but Rails or I guess Active Record makes validation much easier. Here is an example of what I’m talking about:

validates :content, :length => { :maximum => 140 }

This limits the content field of a form to 140 characters and if you do exceed the limit it will fire off a flash error message, which is way better than having to do this manually. I'm sure there is a way to do validations in Sinatra, but I feel like Rails was designed for this.

Here are a couple of other links about validations in Rails: Active Record Validations Callbacks and Validations in Rails 3.

Depth First Learning

March 21, 2013

As I continue to learn new programming languages, frameworks and concepts its very easy to just stay in your comfort zone and only get a basic level of understanding about a multitude of subjects.

While that might be okay for a short period of time just to find out what you are interested in there is going to be a time when you need to pick one thing and dive as deep into it as possible.

It's great that I know Objective-C, C#, Python, Java, Ruby, MSSQL, MySQL, PostgreSQL, Wordpress, Sinatra, Rails, etc. but beyond making a simple todo list application with a tiny database and zero users how much to you really know about these subjects beyond an elementary level?

Part of the reason why I started to build Networkcraft was because I'm forcing myself to graduate from elementary school and on a really deep level understand a single topic: Building great web applications written in Ruby on Rails that support thousands of users.

I feel like I should have started this years ago. And I guess I have been putting off truly learning a single topic because It's far easier to just jump to the next area of interest and stay on your training wheels, then it is it dive into the unknown and do something entirely on your own and make something that doesn't exist yet.

The Best Way to Learn

January 4, 2013

I learned a lot of new things in 2012 and I wanted to share some of the methods I use whenever I come accross something new to me. I'm going to use learning a new programming language as an example, but this applicable to anything really, like learning to spaak a new language or learning how to cook.

Last year one of the new things that I learned how to do was learn how to make iOS applications. This is something that I wanted to do for a long time, but have put it off for years. One of my hickups for awhile is that I didn't have a mac that I could develop on. That changed last January, but I still put off learning ios Apps for 9 months.

I started off watching videos from Team Treehouse. I got off to a quick start, but I quickly became overwhelmed. I got a point where I was only watching the videos and not working through the examples and this just made me feel even more overwhelmed. There was a lot of new vocabulary to take in and just watching the videos wasn't cutting it.

After stopping for a few days so that I could continue to sulk and doubt my ability, I finally decided to purchase a book that I heard about awhile ago. It's called iOS Programming: The Big Nerd Ranch Guide. They also have a book for learning just objective-c that has almost nothing to do with iOS programming and the iOS programming book contains a chapter introducing the objective-c programming language which I found it covered more than enough to start out making most apps. This book helped me out tremoundously and filled in a lot of gaps left open from the team treehouse videos. I definitley think having two solid resources to learn from sped up the learning process greatly.

I worked through more than half of the nerd ranch book, but I got to a point where I was getting sick of working through their examples and I was building up enough confidence where I thought could tackle a project of my own. You are definitly going to have to work through a lot of examples to get over the initial learning curve and start putting all the pieces of the puzzle together. There comes a point that is very criticle, but I think few people reach, it is when you get just enough pieces of the puzzle that you can venture out on your own and not clench to the examples any more.

This point came to me about half way through reading the Big Nerd Ranch book and I decided to start building my own app. It was just a simple app that would have two UITableViews and a UIWebView for displaying some html documents. Even though this app was super simple, I struggled a lot. I think I started it over 4 or 5 times. It got to a point where the examples I was reading from didn't help me anymore because I was trying to do something that wasn't in my book. This is where you want to be. Even though its super frustrating and you want to throw your computer accross the room because you've tried everything, but still can't get it to work. I know it sounds crazy that is is a point in the learning process that you want to be, but trust me, in this phase all the little pieces just start stitching themselves together and as soon as you finally figure out what you've been struggling with you get that "ah ha" moment and then truly understand everything you've been doing up to this point.

My first app is called LDS Archive and you can see a video demo of it below:

Even though I still continued to struggle as I finished my first app the rest of it was much easier to figure out now that I finally "got it". Once I finished my app, I went back to my trusty book and started slogging through more examples. I'll admit this isn't always fun, but it does help. Maybe out of my bordom copying examples out of a book I got the idea to work on my second iOS app. This time I was going to make a game! This game uses only a single view, so this was a great app to cut my teath on really learning objective-c and not just the cocoa touch framework.

And here is a video demo of my 2nd app: Brick Smasher

By the time I finished my 2nd app I was feeling pretty confident, and briesed through the rest of my book. And once you finished your book you come to a critical point where it's time to let go of your crutch and start charting off on your own. This is when the idea for Toast came in to play. Toast would quickly become my third iOS application and was created to make "before and after" photos look amazing. There are a ton of before and after photos floating around the internet, but most of them look horrible and I can tell that people just need some help and a simple solution to merge two photos together and add some text. This is what Toast does very well. You can either choose to a picture from your photo library or take a picture right from the app, do this again with your after photo, add some custom text to describe you photo and press save to have it go directly into your photo library on your phone. It's really that simple.

Toast still isn't finished, but the basic funtionality is there. I'll be honest, I'm still struggling to figure some things out, but I know this is a natural part of the learning process and necessary for me to continue to progress as a programmer. I hope to submit it to the app store soon and hopefully it will help cover my $99 a year apple developer fee.

I just wanted to write this post to let you know it's very important to let go of your trusted books and tutorials and try to make something you can call your own. It's going to be very painful, and you are going to feel like you aren't making any progress, but going through this struggling stage will help you take leaps and bounds and make everything you've done seem so easy once you get to that "ah ha" moment.

Go build something. And stay with it.