Rewriting History (in Git)

Posted by chendo on May 21, 2009

We took on a new client yesterday, I had the privilege of pushing their git repository to a remote server for the first time but quickly discovered that the repository was over 800mb. The code base itself was definitely smaller than 20mb, so I figured it had to be some large binary files in the history.

A quick search on the intertubes revealed a command called git-filter-branch, which lets you effectively rewrite history. But I still needed to know what files were the culprits clogging up my repository. I found this answer on Stack Overflow which included a handy script that goes through the history and lists all blobs that are above a specified size. It revealed an assets folder that had contained some large videos.

I decided to nuke the entire assets folder from history with this command:

git filter-branch --index-filter 'git rm -r --cached --ignore-unmatch assets' HEAD

This effectively removes the references to those blobs from history, but the actual blobs are still there because git does not garbage collect them until they are more than 30 days old.

The next few lines are lifted directly from the git-filter-branch manpage at http://www.kernel.org/pub/software/scm/git/docs/git-filter-branch.html.

WARNING: These commands are DESTRUCTIVE. Make a backup first.

DISCLAIMER: We are not responsible for any damages caused by this blog post.

  • Remove the original refs backed up by git-filter-branch: say git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d.
  • Expire all reflogs with git reflog expire --expire=now --all.
  • Garbage collect all unreferenced objects with git gc --prune=now (or if your git-gc is not new enough to support arguments to --prune, use git repack -ad; git prune instead).

After all this, I managed to trim down the repository from 800mb to a respectable 80mb. I win.

Accessing Rails Documentation, Fast

Posted by chendo on April 24, 2009

Update: voloko has pulled all the changes into master, so you can now download documentation packs directly from http://railsapi.com.

Just how quickly can you bring up relevant Rails documentation? I think I've come up with a winning combination that is more than down right fierce.

Ben Hoskings showed me LaunchBar the other month, which was a shareware keyboard-driven productivity utility, similar to Quicksilver. I actually got around to using it last Friday and I'm loving it (please don't sue me, McDonalds).

LaunchBar can easily initiate a search with a few quick keystrokes. I can bring up LaunchBar, type 'g mocra' to Google for 'mocra', or ''wp quantum physics' to get to the Wikipedia article for Quantum physics, assuming you've trained it to do so (more on training LaunchBar below).

It was then the veritable incandescent bulb popped into existence above my head. It was like golden rays of glorious sunshine perforating the charcoal murkiness of the aftermath of a vigorous storm, a multitude of rainbows sprouting from the corners of the earth, a majestic symphony cascading from the heavens, scantily-clothed young maidens frolicking over the emerald meadows, the lack of Internet Explorer's existence... I think you get the point.

I thought, "Why not use it look up Rails documentation as well? Perhaps 'rdoc before_filter'?"

LaunchBar has configurable Search Templates where you can create a template that inserts your search string into the URL, so for example, the Google search template is "http://www.google.com/search?&q=*", and '*' is replaced with the search string, so I needed Rails documentation that allowed URL-based searching. I used RailsApi because it was stylish and pretty fast, but it did not have a way to search via the URL, so I hacked it in, as well as using Ctrl + I/K (C/T in Dvorak) to navigate the search results. Adding Shift to that combination makes it instantly jump to the page instead of waiting for you to press enter.

My fork of voloko's sdoc generator is up at http://github.com/chendo/sdoc/, which is actually just the generator. He's pulled in the ?q=* patch but the docs on railsapi.com don't seem to be using it yet. Until then, you can get a working copy of the RailsApi docs here.

Note that these instructions are for LaunchBar 5 beta, not LaunchBar 4.

Now, to add it as a Search Template in LaunchBar, this is what you do:

  • 1. Go to http://railsapi.com/, pick what docs you want, and then download the zip.
  • 2. Extract it to somewhere in the system. I extracted mine as ~/Sites/rdoc.
  • 3. Activate LaunchBar (Apple + Space)
  • 4. Go Index -> Show Index (or Apple  + Option + I)
  • 5. Click on "Search Templates (UTF8)", then click "Add..."
  • 6. Give the new search template a name (I used 'rdoc'). This determines what you type to invoke the search template.  Enter the full path to the index.html and append "?q=*". Close the window, and save the changes when prompted.
  • 7. Activate LaunchBar, and type the first few characters of what you called the Search Template ('rdoc' in my case). Hit space, and then enter a search term.
  • 8. Press Enter, and victory!
  • 9. Use Control + I/K (C/T if you use Dvorak like I do) to navigate the results list. Control + Shift + I/K/C/T instantly jumps to the search result.

Post your comments, suggestions, etc to @chendo on Twitter.

How to Get a Job at a Top Ruby Shop

Posted by Dr Nic on March 12, 2009

Ruby-focused news website, RubyInside, recently ran a series of quotes from various companies that use Rails/Ruby internally or for consulting titled How to Get A Job at a Top Ruby Shop:

I [Dr Nic] was quoted as saying:

“Young Guns” are the key ingredient at Dr Nic’s firm Mocra. Recruits are inspired by love of coding: attending local dev groups and RailsCamps, have contributed to open source, and are prepared to tell other guys in the office that they’re wrong or doing something inefficiently. Especially their boss.

The whole article seems to summarise a gut feeling we have at Mocra, that Ruby on Rails isn’t just a great technology—it seems to attract some of the best, most passionate software developers.

iConMerge - Free Cocoa App for Developers

Posted by Dr Nic on February 11, 2009

You can quickly access your Xcode or TextMate or whatever projects by dragging the project bundles into your dock on OS X. But they’ll all look the same unless you can give them unique icons:

Quick access to projects via dock

iConMerge creates these icons and exports them to the project bundles (or saves as a .icns icon file) in 10 sec flat.

Download and Getting Started

Don’t need instructions? Download

Want pretty pictures to explain what to do? Project Home

Tell your friends

If iConMerge is useful to you, please tell your friends so they too can have merged-icon-magic in their life. Blog about it. Twitter about it. Write postcards to relatives about it.

Open Source

iConMerge is an Objective-C/Cocoa project. It is open source. You can view the code, fork the code, improve the code and you will go to heaven for your efforts.

Get the source on GitHub.

Dr Nic and the Mocra Team on Tour Around Australia

Posted by Dr Nic on October 30, 2008

We use cutting-edge, latest technologies to track and manage our conference and holiday travel: a white-board that sits on our mini-bar fridge.

In Australia we have 6 states: Queensland (God’s Country), New South Wales (home of Sydney), Victoria, Tasmania (Dr Nic’s birthplace), South Australia, and Western Australia. Over the next two months, the travel whiteboard says that we’re visiting nearly all of them. Yikes! And this doesn’t include Dr Nic having just travel to Brazil and back for RailsSummit in São Paulo.

Most of the travel is so we can catch up with other developers: RailsCamp in Adelaide, CocoaHeads in Melbourne, and iPhone Tech Talk and Open Source Developers Conference (OSDC’08) in Sydney. Click the whiteboard photo to see the dates. Or visit Dr Nic’s Dopplr page for live updates.

We’re always happy to catch up with developers interested in iPhone and Ruby/Rails development and any potential clients whilst we’re in your city, so ping us an email! (drnic@mocra.com)