About a week ago I finally decided that I wanted to start blogging again. I love talking about programming, but I often find it difficult to motivate myself to write a blog post about it. I sat down to write a post, and sure enough, I couldn’t think of anything to blog about. So instead I procrastinated by thinking about all of the things I wanted to do to make my blog better.
If you’re reading this and your first thought is, “there are 3 ways to get the size of a relation?”, then
you’ve come to the right place! Basically, given a relation like
User.first.posts, when you
want to know the size, you’ve got 3 choices:
count. At first glance, it seems like these
might do the same thing, right? Not so! There are some key differences between them.
This is a quick one, and the title says most of it. Basically, you should never have code like this in your app:
1 2 3 4 5 6 7 8 9 10 11
Stop me if this sounds familiar. You’re tooling around in the Rails console, testing out some new code you’re working on (or debugging some slow/broken code), and you see a ton of repeat queries.
I have this experience frequently; usually I can figure out what’s going on, but sometimes it can be quite tricky to track down the source of extra queries. Whenever I want to figure out where a method is getting called from, one easy and lazy solution is to add a debugger statement in that code. But where the heck do I add a debugger for sql statements?
This is my first blog post! I setup up my blog using Octopress, which was incredibly easy. They’ve got some great guides on their site, but just to give you a sense of exactly how easy it is, I simply:
- Created a repository on github named a-warner.github.com - the standard naming conventions that Github Pages expects if I want a-warner.github.com to resolve to this blog
- Cloned Octopress via
git clone git://github.com/imathis/octopress.git a-warner.github.com, ran
- Next step was to run
- Then it’s as simple as
- Creating this blog post just involved running
rake new_post["My first blog post"]
The writing process is extremely simple - just run
rake preview until it looks right, and then
rake deploy after committing your changes.
Not that I should be surprised, but using Octopress is really a breeze, and I highly recommend it to anybody looking to crank out a quick blog with minimal setup and maintenance.