Git Smart - Painless git pulling and merging

rob 25 Mar 2012
?

I don’t mean to imply that git pulling and merging is painful, because it isn’t. I just wanted to showcase a pretty nice gem called git-smart. You can install it using gem install git-smart.

What this gem does is pretty simple, it attempts to do the “right” thing depending on the situation. I’ll run through a few of the commands:


Git Branch Time

rob 10 Mar 2012
?

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.


My New Nest Thermostat

rob 03 Mar 2012
?

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.


Useful Bash Tricks and Commands

rob 01 Jan 2012
?

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.


Advanced search query parsing with Ruby

rob 23 Dec 2011
?

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.


Update or Export WordPress with Ruby and Thor

rob 12 Nov 2011
?

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.


Logging in PHP

rob 09 May 2011
?

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.


SEO Friendly GitHub Gists

rob 27 Apr 2011
?

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.


Active Record Query Caching with Sinatra and multiple Databases

rob 15 Apr 2011
?

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 instance_variable_set 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:


Rails-like content_for in Sinatra

rob 01 Apr 2011
?

I use content_for 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 content_for – 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.


URL Shortening in Ruby on Rails

rob 15 Mar 2011
?

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 to_s you can specify the base, and when you turn a String back to a Fixnum you can also specify a base in to_i. 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).


Super Simple “Thread Pooling” in Ruby

rob 21 Feb 2011
?

I recently had a need to parallel process some tasks for a non-critical app, but really didn’t want it to get out of hand. I wrote this as a simple way to multi-thread without the pain of worrying about synchronizing and queues and being thread safe.

It achieves ghetto thread pooling by chunking the result set into whatever size slice is needed and spins up some threads, once that set is done it will repeat until the data is all processed before moving on.

It ended up working out really well as a direct drop-in, and speeded up the processing greatly. I wouldn’t recommend this for production code, however.


Easy way to add paths to $PATH in bash

rob 01 Feb 2011
?

This little script is a convenient way to add paths to your $PATH variable without worrying about duplication. I generally break out my .bash files to be organized across multiple servers/computers and each one seems to need different paths appended – so thats where this little guy comes in handy. Just a simple push_path and no worries.


Send Entourage mails from the command line with Ruby

rob 07 Jan 2011
?

I’ve been spending a lot of time creating reports lately, and I generally live in a terminal, so naturally I started to think of ways to easily send emails with these reports attached. I’m stuck using Microsoft Entourage here at work, but thankfully they have a pretty robust AppleScript library. Mixing some stuff together I pulled together this Ruby script which will allow me to do some neat stuff:

  • pipe data into the email command to create a body
  • use aliases as groups to send emails to common groups of people, etc
  • add multiple attachments to emails straight from the command line!
  • not have to move my hands from the keyboard when sending emails!

At its core, it is nothing more than a simple ruby shell script which compiles AppleScript and uses osascript to execute the AppleScript. When run it will pop open a new Entourage mail window with the To/CC/Subject filled out, as well as any attachments and moves focus to the window. If I had piped anything to STDIN that would be the body, otherwise it would blank and ready for a quick message. Then a quick CMD-ENTER and off the mail goes. Simple and elegant, yet kind of powerful :)


Check piped STDIN in Ruby Shell Scripts without Prompting

rob 15 Dec 2010
?

I was writing a small shell script in Ruby today that needed to check STDIN for data, but I didn’t want to prompt the user to enter data when nothing was found (I only wanted piped in data). This turned out to involve a little more effort than just checking STDIN.read.

Luckily, I found a solution at Footle that worked out great. Heres to anyone who needs only piped in data from STDIN without prompting the user.


Active Record Query Caching with Sinatra

rob 01 Dec 2010
?

Sinatra is awesome, but Rails has a lot of useful features. One of those is Active Record’s Query Caching. I never realized how useful this is until I started to optimize Sinatra apps and felt its absence. Here is a simple way to enable active record query caching in Sinatra.


Make iTunes Suck Less

rob 28 Nov 2010
?

As we all know, iTunes is opinionated, but we can lessen that with a few defaults write commands. One thing that is annoying is their new PING feature, which I consider useless. Another thing is their Store Arrows which can be obnoxious. This will reverse those and make it so the PING icon is hidden, and the store arrows actually search within your library. (This is common knowledge, but useful nonetheless)


OpenSSL Encryption Fun

rob 22 Nov 2010
?

I re-discovered the fun that is OpenSSL’s encryption today when I was cleaning up some bash aliases and though I’d share them.

This allows you to do some really stupid but fun things like encrypt backups, or messages to pass to a buddy. The uses are endless!


Directly link to Google JSAPI libraries

rob 15 Oct 2010
?

I’ll start off by saying that I love Google’s JSAPI. The other day all hell broke loose when, due to internal server issues, http://www.google.com/jsapi started throwing up 503 errors – which subsequently broke JavaScript in all 12 or so internal apps using JSAPI. In other words, a major headache since I was faced with having to manually update the apps with the proper JS dependencies. Luckily I found out where those jsapi libs were stored, and through another stroke of luck found that they were resolving properly. So for any of you out there that get yourself into this odd situation, or wish to avoid using google.load(...) by directly linking to the libraries themselves, here ya go.


PHP 5.3.3 MySQLi compile woes: my_global.h and error: duplicate ‘unsigned’

rob 08 Oct 2010
?

It seems like every time I re-compile PHP I get some whacky error. Anyway, I was fortunate enough that a quick Googling found a solution from katmai for compile error.

I’m popping this up here as a reminder to my future self, as well as anyone else who stumbles into this.

If you get this error when attempting to compile PHP 5.3.3 with MySQLi on, in my case, Snow Leopard

/usr/local/include/mysql/my_global.h:1008: error: duplicate ‘unsigned’
/usr/local/include/mysql/my_global.h:1008: warning: useless type name in empty declaration

Was solved with a simple patch to ext/mysqli/php_mysqli_structs.h


Page 1 of 2 1 2