Roll Your Own Remember Me

October 11, 2009

I’ve been setting up Fluid Applications for a lot of the web applications I use frequently. This lets you run a web application in a lightweight browser, like it’s a native OS X application. Instead of having Gmail, Google Reader, Pivotal Tracker, and New Relic running in tabs in a browser I have them running as separate applications that I can switch between using the normal Cmd-Tab.

This has been working really well for me, until I hit one annoyance with New Relic. This web app doesn’t have a remember me feature. Its login cookies expire every time you close your browser session (as is the default in ruby on rails). This meant that every time I would pop it open I would have to re-enter my login credentials. Turns out I like to quit and reopen this application a lot, and was starting to get really irritated by having to retype my email and password to do a quick check of the production servers.

Installing an Interactive Javascript Shell

June 26, 2009

When you’re brainstorming some ideas for a program or learning a new language its great to have an interactive console to play with. It lets you start typing out code, inspect the return values, and experiment or debug in a really helpful way. You get immediate feedback on what each line of your code is doing. That’s why irb for ruby or script/console for your rails app are such great and useful tools. Once you get used to being able to dive into your application environment and fiddle around you wonder how you ever did without it.

There’s a cross-platform Javascript shell, which is super easy to get up and running. It uses Rhino which is an open-source implementation of JavaScript written entirely in Java.

I’ll show you how to install it on OS X in under 5 minutes.

Most of this should work on Linux (and maybe Windows) too with some minor tweaks.

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();
      };
    });
  });
});

Resizing Textareas as You Type with Prototype

May 27, 2009

In my last post I described how you can use jQuery to easily add dynamically scaling textareas to your site. Now here’s one for everyone using Rail’s standard javascript framework Prototype:

Resizing Textareas as You Type with jQuery

May 26, 2009

Here’s some code I’m going to use on every project from now on. It makes all the textarea fields in your forms resize dynamically as the user types. Drop it unobtrusively into any page (running jQuery) and all your textareas expand to fit the text the user has entered.