ack: the fast code search tool

September 08, 2009

One of the handiest tools in my programming toolkit is ack, a Perl script that is great for searching through code (or really any text files). I use it a lot while refactoring, for example when I want to rename a method every time it’s called in a project.

You can install ack with this command (from http://betterthangrep.com/):
$curl http://betterthangrep.com/ack-standalone > ~/bin/ack && chmod 0755 ~/bin/ack 

Assuming that ~/bin/ack is in your path searching code is as easy as this:

$ ack my_poorly_named_method

Instant Search in pure Javascript (almost instantly)

June 17, 2009

Here’s a really simple method for creating an instant search for a list of items. It lets you quickly filter a long list or table down to the few items you’re looking for.

First here’s a demo.

What’s nice is this only takes a few lines of code (and the magic of jQuery.)


$().ready(function(){
  // Instant Search
  $('#q').keyup(function(){
    $('.search_item').each(function(){
      var re = new RegExp($('#q').val(), 'i')
      if($(this).children('.search_text')[0].innerHTML.match(re)){
        $(this).show();
      }else{
        $(this).hide();
      };
    });
  });
});