Heres a small script from Ben Hoskings which is immensely useful. It lists all the branches in your git project ordered by when you last worked on them. It also highlights branches which have not yet been merged into your current branch, which is super useful when looking to prune some branches.

Continue Reading

I'm switching things up this time. This post has nothing to do with code, and everything to do with an awesome gadget. Today my nest learning thermostat came!

If you're unfamiliar with the nest, it is a replacement for your programmable thermostat that learns your habits and programs itself, among other things like monitoring energy usage to help save you money. If that isn't cool enough, it is wi-fi enabled which means it auto-updates itself, I can set the schedule from a website, and I can control the temperature in the house from anywhere in the world. Is it lame to get so excited about a thermostat? Probably, but who cares, this thing is fucking cool. Check it out.

Continue Reading

I spend a lot of time using the command line, and I find these features particularly useful. This might be old news to some, but they are still immensely helpful. (Also, these are extremely hard to google for, so hopefully this will save you time in more ways than one!) I tried to include as many examples as I could to make these easy to understand.

Continue Reading

Making advanced search forms for your backend kinda sucks, right? I ran into this problem with a project and decided to come up with something similar to how Google handles search queries. No dropdowns, no checkboxes, no radios, none of that stuff. I just wanted to be able to type status:active user:rob [term] and get what I asked for. I came up with a pretty nice utility class that can handle some basic query syntaxes and give you back hashes or arrays and the left over query.

Continue Reading

I may be a devout rubyist, but I still have a soft spot for WordPress -- and maybe even a little for PHP too. One of the things I think is lacking is a good way to manage WordPress updates since, as we all know, WordPress updates constantly. I wrote this quick thor script to help me update to the latest version from the command line so I can do quick version testing. As an added bonus, there is also an export task as well which will simulate doing a wordpress XML export from the dashboard.

So, for all you WordPress guys out there who hate doing manual updates, check this out. It may make life a little bit easier.

Continue Reading

There are tons of PHP logging apps out there, but here is my take on it. This is a simple drop-in class that is 1 file and is pretty flexible. In my opinion this is about all that is required of a PHP logging class, and its been working out well for me.

Continue Reading

If you look around this site you'll notice that I'm hosting all my code snippets on GitHub's awesome gist feature. While this allows me to not maintain syntax highlighter plugins and libraries, as well as lets me change the code snippet without updating the blog is nothing short of awesome. The only thing that kind of sucks is that I/we are losing the ability to have our code be search engine friendly since a gist is a 1-line javascript include. This sucks not so much from the "index me!" perspective, but more of the "if I google a line of code/error, will I find relevant code?"

To tackle this, I ended up with a small project: given a gist ID, generate the embed code along with NOSCRIPT tags so the content is indexable. This will only solve the initial problem, as updates will not propagate to the blog, but... you can always manually update.

Continue Reading

This one is a pretty specific hack. I've had the need to build mini reporting apps, using Sinatra, that aggregate data from multiple databases and produce a report. This is all fine since ActiveRecord is awesome, but I've always missed AR's query caching ability.

After some digging I found that query caching is only enabled on AR's Base connection and all other models must use that awkward Model.cache{} construct -- which is annoying to use. I've hacked up a solution that works, although it relies on :send and instancevariableset which isn't very elegant or solid.

For what it's worth, here is a "simple" way to get Sinatra to use ActiveRecord's native query caching for more than 1 database:

Continue Reading

I use contentfor a lot in Rails code, but a large percentage of my projects are done as a simple Sinatra app, so I find myself missing a lot of features that Rails has. One big one was contentfor -- so I drafted this up to fill the void.

It is similar to how rails 2.x implements it, so in your main layout you can check if that content is there and if so display it, otherwise you can use defaults, or ignore it. This particular gist uses it to create custom sidebars based on what page you are on: if you are logged in, in a particular area, etc.. I like this approach as opposed to having a single sidebar partial with tons of display logic, I just think it keeps thing tidy.

Continue Reading

I was creating a project the other day that used anonymous pages for users and I wanted to make it a little less "guessable" but more human friendly than a SHA1 hash, so I decided to make a small home-brew URL shortener similar in format to Tiny URL.

The neat thing about ruby is that when you turn a Fixnum to a String with tos you can specify the base, and when you turn a String back to a Fixnum you can also specify a base in toi. This lends itself perfectly to turning (large) IDs into a shortened URL thats easier to remember.

In the first gist you can see how this would work with a model to make simple url shortening in rails -- or, you can use randomized values to generate more user friendly "unique" tokens (as opposed to using SHA1 hashes for user confirmation/password reset pages).

Continue Reading