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

How to ruin your pitch, and your demo while you’re at it.

There are many ways to ruin your chances of making an impression.  Here’s a few gems from my experiences at Startup Weekend.


Ask for a show of hands or rhetorical questions.

Everyone before you asked for a show of hands.  I do not want to raise my hand again.  If you need the audience to validate you by raising their hands you’re asking too much.

“What would you say if I told you I could change your life?!”  Do you really expect me to answer you?

You’re pissing me off.

Talk quietly

What’s that?  Sorry can’t hear you.  You’ve already lost my attention.

Uhhhhhhh…. ummmmm….. so….


Ramble on and on incoherently

What I’m hearing “Blah blah blah.  Bob Loblaw’s Law Blog”.  Oh wait.  If you made an Arrested Development joke I might actually listen. You were less interesting than my computer.  You already lost.

Arrested Development reference... check.

“I don’t have much time so I’ll keep this short”

I already know you don’t have much time and you managed to waste more of it telling me what you’re going to do.  WHY HAVEN’T YOU STARTED YET?!

Read directly from notes

This should feel like a conversation, not a lecture.  If you’re speaking AT me, I’m not going to give you the time of day.  Back to my laptop…

Refuse to stop when your time is up

The elevator has stopped at my destination; if it were more socially acceptable I’d walk out.  Your time is up.  You should have been more succinct.

Tell me about your great idea that you have zero ability to work on

So you want to create another platform for social networking.  You have no skills marketing, designing, developing, selling, or really anything… but you have a lame idea.  Why in God’s name would I waste my time if you’re going to be dead weight.  Learn a skill… yesterday.

BONUS ROUND!  Demo time.

Don’t plan out your demo

“Doing it live” should be reserved for Bill O’Reilly, not for you to fumble over your words trying to show me something you created.

Ignore any microphones

Can’t hear ya buddy.  You’re now less interesting than twitter and reddit.

Ignore your sales plan

So you made something cool, and you plan to make money on it.  How the hell will anyone find it?

Show me a hockey stick and other fanciful numbers

You’re going to get astronomical growth in 3 years?  Yeah you and every other wannabe who saw “The Social Network”.  You can guarantee a million users?  Yeah… OK.  If you show me how your business plan would change as you grew you might impress me.

Avoid a use case and talk in vague generalities.

“This is going to revolutionize the market…”

“It’s going to make your life simpler”

“It’s going to bake you cakes and churn out the cure to cancer”

You might have actually made something I want to use, but if you spend your time bloating your demo with bullshit and don’t show me how I’d use it, you’re wasting time.

Make no mention of your vision

If you have a vision it can provide guidance for every decision you make.  It’s pretty binary.

if(decision.helps_me_approach(vision)) { do_it(); } else { move_on();}

Without that you’re going to try going a hundred directions at once.  You’ll be training to be a world class sumo wrestler while you train for record marathons.  You’ll fail at both.

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.

Startup Weekend Hartford – Reflections

To put it simply, I loved StartupWeekend Hartford. The whole group was very supportive and it was great seeing what we could all accomplish in such a short timeframe. I’ve heard about startupweekend before, but never experienced one. I knew it was going to be a long weekend fueled with black coffee and ambition, but I wasn’t sure how the experience would feel. It was challenging, engaging, rewarding, stressful, exciting and fun. I had more fun that weekend than I have had in a long time.

The pitches were pretty varied, people were pitching some great ideas, and some really pie in the sky ideas. Some seemed like they were impossible to show working demos for. Some ideas felt old and stale “oh that’s been done before”. I KNEW mine was done before, but what better way to learn guitar than to play your own version of “Stairway to Heaven,” It was pretty surprising that anyone was actually interested by my pitch.

It seems like everyone that joined the group though was just looking for experience, winning would have just been icing on the cake. The primary goal would be to learn what we could from the experience and build up our skill sets for when we had another idea.

Saturday we worked most of the day, but mingled with some of the other teams to see how they were doing. We talked to a few of the mentors as well for guidance but mostly we were in grind mode.

The part that stands out the most to me was the presentation on Sunday. I remember distinctly pacing back and forth while we pored over the language of the presentation to make sure we gave off the most convincing argument that we could. We fought back and forth over individual words and timing. Over what slides we would include. How we would present it. Would I read the script off a tablet? My computer? Should I print it? No, there’s no time, just use my laptop. Tick tock. Tick tock.
Seeing the everyone’s results and how much progress they made since the pitch really blew me away.

Looking back, my idea wasn’t really new. I had been pondering it and taking a few stabs at it before. What had changed was the perspective that I looked at it. There was a lot of brainstorming in those 54 hours. We went from a very basic concept: visualize your todo list, to a much more full and well rounded concept. I wish we had more time to develop and code. Balancing the load of the team was challenging as well. We had a somewhat small group. 2 developers and 2 business and marketing guys. There were times I wish we had operated more like a well oiled machine, but we were just getting to know each other.

I was definitely torn as a developer between wanting to code and also driving forward the project that I pitched.
It was difficult going across the board from varying ideas and maintaining those ideas. I really wanted to create something more tangible but we weren’t able to in the time allotted. I think with more experience in rapid team building and rapid development, we’d be able to get something more tangible in a weekend.

I think I’m much better prepared for another startup weekend from the lessons I learned. Though talking out problem is great, there’s only so much time. Actions speak louder than words. Next time I’d put much more emphasis on a working prototype and customer validation from the beginning. A functioning prototype has a lot more “wow” factor, and makes customer validation a lot easier since you can ask for feedback on something more tangible than an idea.

Another important thing I learned about brainstorming was how important it was to timebox discussions so that they don’t run away from you into non-productive territory. If we sit down with the intent to hash out a problem, we better decide how long we expect it to take, or we can go on forever, and we only have a weekend.

I still want to continue my project, but with the weekend over, and the team and the intensity lifted, it’s back to the daily grind. I’ve kept in touch with my team to keep developing it in our free time.

At the end of the weekend I went out for drinks with a few of the other participants and we discussed our pet projects and visionary ideas and how we would get there with a lot of hard work and a little bit of luck. I knew that I had found the people I needed to surround myself with. People with drive and creativity to solve problems we see around us big or small.
This is only the beginning. I’m already planning on going to SW Boston and SW New Haven. I still have a lot to learn, but I’m loving every minute of it.

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.