Archive for the ‘Uncategorized’ Category

Generating Fixtures from your Test DB (Rails 3.1)

If you’re like me and figuring out rails as you go, you likely have a lot of code without proper test coverage yet.  Well, now it’s time to build a test suite because smoke testing in Chrome just won’t cut it anymore.

Since my app has a pretty complex series of models, it’s a pain in the ass to create fixtures manually, so I did some googling and found a nifty little rake task to help.  It’s a great starting point to get that test suite built out.

I’ve updated it to work with Rails 3.1.  Hope it helps.

#put in lib/tasks/fixtures.rake
namespace :db do 
  namespace :fixtures do 
    desc 'Create YAML test fixtures from data in an existing database. 
    Defaults to development database. Set RAILS_ENV to override.' 
    task :dump => :environment do 
      sql = "SELECT * FROM %s" 
      skip_tables = ["schema_migrations"] 
      (ActiveRecord::Base.connection.tables - skip_tables).each do |table_name| 
      #("users").each do |table_name| 
        i = "000" + "/test/fixtures/#{table_name}.yml", 'w') do |file| 
          data = ActiveRecord::Base.connection.select_all(sql % table_name) 
          file.write data.inject({}) { |hash, record| 
          hash["#{table_name}_#{i.succ!}"] = record 



PS: If you want to insert code snippets into a hosted WP, use sourcecode tags and not a gist… understandably, WP, does not like script tags in posts.

Punk Rock Rails

This is a repo

$git init

This is a rails app

$rails new walking_into_mordor_the_blog

This is a scaffold

$rails generate scaffold blog_post title:string content:text

This is a live blog

$rails server

Now build a webapp.

See also: Punk Rock

I Choo- Choo- Choose you Ruby

Mining for gems

A few friends have mentioned some interest in getting involved in Ruby and Ruby on Rails to see what all the buzz is aboot.

I was originally going to write a long and well thought out post, then I realized how helpful Michael Hartl’s guide was to me in getting set up and spooled up.

Rails Tutorial Dot Org
Rather than reinvent the wheel check his tutorial for…

1. Installing Ruby [use RVM!]
2. What is MVC
3. Setting up a super minimalist blog as a hello world.

The first time I read thru it it seemed like most of it was overkill, but after more and more tinkering, it’s r

eally valuable. As much as I usually glaze over for cookbook tutorials, this one is VERY informative.

A few other resources:
If you haven’t heard of this

yet… wait… honestly?
Ask questions thoughtfully and include as much code as is neccessary. #ruby or #rubyonrails
It’s kind of hit or miss who’s online and willing to help, but I’ve gotten some great feedback.
Often I figure it out myself once I’ve taken the time to ask the question well.

Ryan Bates has done a great job doing video walkthroughs of common issues with Rails.
Be careful though, some of his solutions are for older versions of Rails.

Ruby Koans:
If you want to try and learn more about ruby syntax and behavior I highly recommend Ruby Koans
It’s more of a guided exploration rather than a cookbook tutorial.

Learn code the hard way:
I came across “Learn code the hard way” as well. Haven’t checked it out, looks very cookbook tutorial.

Project Euler
If you’re looking for some problems to chew on with ruby try out Project Euler. You’re on your own with the ruby side, but the problems are tractable enough for a noob. I prefer to learn my development on an ad-hoc basis with google and so this is what I’d prefer.

That’s it.

Right now I’m battling problems with Rails more than Ruby.
Track my progress here:

Edit after SWBoston:

Some of the guys recommended Rails For Zombies.  Haven’t tried it, seems interesting enough.
Tangential but related…

960 Grid System:
A beautiful way of laying out a website using a grid. Definitely more programmer friendly than auto-generated stuff from Dreamweaver and the like.

Twitter Bootstrap:
Like but with some JS libs built in to give you a lot of the functionality of jquery without all the weight.

Baby Steps and Momentum

I’ve set the goal to post every day.

At a minimum all I need to commit is 50 words.

That’s pretty easy to start with, especially if I haven’t gotten this to be a part of my routine yet.

I don’t need to stop at 50 just set a minimum.

It’s almost as shallow as a tweet.



Feedback on a beta app

I wrote an app to fill a need I had.
I want to figure out how much time I spend on everything without using a really obnoxious spreadsheet and manually clocking time.

Enter: Time Tracker.

I’ve got some grand vision for its future, but for now I’m just looking for some basic feedback. I can post the feature backlog if anyone would like to see it.

Until I set up a built-in system to collect feedback, this blog and my email will suffice.

Link here:

Will likely break in the future.

Motivation for this Blog

Over the past year I’ve been slowly working towards my goal of running a successful website.  After some fits and starts with classmates and friends, I’ve decided to work on my own projects to learn the current landscape.  While I’m a bit too risk averse to pursue this full time, I will devote some significant time while moonlighting.

In my projects to date, I haven’t been the driving force, I’ve really been a bit of a back seat rider.  It’s now time to take the wheel.

I’ve been trying to learn Ruby on Rails, as frameworks appear to be the next step forward in web development, and the community seems pretty lively.  As with all things relating to free time and motivation, it’s been pretty tough to keep the discipline to continue pushing forward when I run into setbacks.  I’ve learned some productivity tricks along the way, which have definitely helped, but it can be hard since this is something to pursue in my free time.  Doing something productive, however rewarding, instead of leisure while outside of work isn’t exactly relaxing.

What I’ve come to realize in the fits and starts, is that I have become somewhat institutionalized by my education both primary, secondary and at the university.  I have become dependent on people to hold me accountable and make me  hand in assignments, or tell me that I’ll be tested on material.  Since that dominated my education and I never had any significant problems therewith, I did what I needed to and spent my free time procrastinating on the internet on various blogs and aggregators.  Once that pressure is lifted, my idle hands crave something to do.  Those news aggregators, movies and TV just don’t satisfy.  I need that pressure, though, or I flounder and leave things unfinished.  I need a fire under my ass.

This brings me to my current pet project.  An application that will help me set a goal, and pursue it week-by-week.  I’ll have a friend as a bit of a gym buddy / coach to keep me honest and keep me from falling off when I’m feeling lazy.  With all the standard fare in the internet start-up community “Do what you know”, “Build a Minimum Viable Product… minimum being the key word”, “Ask yourself if you’d use it”, etc. I decided to solve my most pressing problem.  A need for some external motivation.  So what do I do?  I learn some more development skills by solving my own problem.  If it works out well in the end and it can help solve other people’s problems too.  If it doesn’t work out, I learn more about my own motivators and “how to play guitar,”  You don’t become a rock star unless you put in some time to learn the craft and what people want and how you can deliver that.  Has this song been played before by more talented developers?  Probably.  But you have to start somewhere and I could still use to improve my rendition of “Mary Had a Little Lamb”.

As far as my web apps and the blog, it’s likely just more noise.  Who wants to read my blog or use my app?  Not the general population… not yet.  For now, this is for me, and my friends, and my coworkers, and some web crawlers, and maybe a few spam bots.  I’m more concerned about tracking my own progress and sharing what I’ve learned with anyone that might find it interesting.  To many, this will be just another Wantrepreneur in the crowd, but to me, it’s progress.

Here’s to a successful journey.