Err the Blog Atom Feed Icon
Err the Blog
Rubyisms and Railities
  • “Cheat Again!”
    – Chris on October 15, 2006

    It wasn’t so long ago that Cheat! was loosed upon the world. We started with five (5) sheets. That’s one hand. Hold up one hand. We now have forty-two (42). That’s eight hands and two fingers. Hold up eight hands and then another hand, but only put up two fingers on the ninth hand. Ha! You can’t! That’s not nearly possible.

    forty two

    Today marks the proud release of Cheat 1.1.0. A few things have changed, but don’t let that get in your way. Upgrade immediately:

    $ sudo gem update cheat

    or

    $ sudo gem install cheat

    Command Line Editing

    This is the real big change. It separates the men from the boys, the 1.1.0s from the 1.0.3s, etc. You can now edit and create cheat sheets straight from the command line.

    Edit the rjs cheat sheet:

    $ cheat rjs --edit

    Create the nonsense cheat sheet:

    $ cheat nonsense --add

    By default, Cheat will try to use your VISUAL or EDITOR environment variable to determine which editor to launch. If it can’t find either variable, it tries to launch vim.

    To edit using TextMate:

    $ export VISUAL=’mate -w’

    Go ahead and stick that in .bashrc or whatever init script your shell uses to ensure $ cheat --edit and $ cheat --add always use TextMate.

    Windows users: this new functionality could use some testing, bugfixing, and patching. All I knows is it works on POSIX.

    One million thanks to the mysterious commenter known only as nornagon who submitted the patch. Who is this phantom coder?

    Tabbin’ Around

    King of bash Kevin Marsh, perhaps inspired by a bit of past rakery, conjured some tab completion magic for Cheat.

    # Cache, and complete, Cheats
    if [ ! -r ~/.cheats ] || [[ ! "" == `find ~ '.cheats' -ctime 1 -maxdepth 0` ]]; then
      echo "Rebuilding Cheat cache... "
      cheat sheets | egrep '^ ' | awk {'print $1'} > ~/.cheats
    fi
    complete -W "$(cat ~/.cheats)" cheat
    

    POSIXers can stick that in your .bashrc (or wherever) and enjoy sweet, sweet tab completion. Go ahead and try it: restart you shell then do $ cheat m<TAB>. You should see a glorious list of sheets.

    Thanks to Evan, the tab completion list will refresh itself every day.

    Printing

    Once again in the news, up-and-coming all star Kevin Marsh fandangled a print style sheet for our lovely cheat sheets. There’s nothing to it: surf to a cheat sheet and hit ‘print.’ Like normal.

    print

    That totally defeats the purpose, but I don’t care. Print away!

    Captcha

    Using Andreas Schwarz’s Captchator web service, the Cheat wiki now has a captcha. The damn spammers kept reverting and messing with sheets so, for now, this seems the best solution (next to the other solution I’ll talk about in a second).

    captcha

    It shouldn’t really get in your way all that much. Let me know if it does. Hats off to Andreas for the simple service.

    Remember!

    We still have TextMate and jEdit integration, among other tricks, at the original Cheat post. And then there’s the RSS feed, too.

    rss

    As always, it’s never too late to write about or contribute to Cheat. You might think this is an ego thing, but it’s not: the more cheat sheets everyone makes, the easier all our lives become. What would you rather be doing, drinking tequila on a secluded Mexican beach or slaving away in your cubicle? That’s what I thought. Get to work.

    Update:

    42 web 2.0

    Update 2:

    42 web 1.0

    Update 3:

    42 ascii

    Update 4:

    Fixed the auto-complete Cheat .bashrc thingie (thanks cdcarter).

  • Kevin Marsh, about 13 hours later:

    Good work!

  • Matz, about 13 hours later:

    ma na na nop!

  • Kevin Rose, about 13 hours later:

    Digg it!

  • nornagon, about 14 hours later:

    Awesome, thanks for dropping in my patch. Looks like it basically offers a way to dodge the captcha, though …?

  • nornagon, about 14 hours later:

    Oh yeah, who’s this Chris guy I keep hearing about?

  • Chris, about 15 hours later:

    The Captcha is only meant to protect against spam-bots, not targeted attacks. If someone were to take the time to read the source code they could figure out how the Cheat gem bypasses the Captcha, sure. But then they’d also figure out that the wiki doesn’t support hyperlinks—so what’s the point?

    As for the Chris guy, I don’t know who you’re talking about. I don’t know anyone named Chris.

  • evan, about 15 hours later:

    I’m Chris.

  • Dr Nic, about 16 hours later:

    I’m Chris and so is my wife.

  • nornagon, about 19 hours later:

    Ah, okay :) Haven’t looked at the modified source yet.

    Awesome stuff!

    TODO:

    cheat rjs --revisions
    cheat rjs --diff n1[:n2]
    cheat rjs --revert n
    

  • Chris, about 20 hours later:

    I’m Sparticus…Chris…whatever

  • Michael Leung, 1 day later:

    Nice!

  • Assaf, 2 days later:

    Awesome! This is getting to be my favorite Wiki: tab completion and local edits!

    What about caching sheets locally, to deal with Wifi not always being around?

  • jer, 4 days later:

    It’d be nice to namespace the cheat sheets by category (rails, ruby, javascript, etc)

    would allow more to be added without making it a bit crazy to find what you need :)

  • Shalev, 25 days later:

    So for some reason when I gem install(ed) cheat I got a series of:

    Whoa, some kind of Internets error! => 404 Not Found from http://cheat.errtheblog.com:80/y/

    every time I tried to search for something.

    Looking at the source revealed that the call: fetch_sheet(uri, @sheet) if @sheet didn’t match up to the method signature of: def fetch_sheet(uri, try_to_cache = true).

    I guess because of this, the sheet name wasn’t being added to the URI and it was trying to open the base path. I added in a third argument to the method and had the open call use that:

    def fetch_sheet(uri, the_sheet, try_to_cache = true) open(uri+the_sheet, headers) do |body|

    Everything seemed to work after that.

  • Chris, 26 days later:

    This should be fixed in 1.2.1 which is on its way to the gem servers now. Thanks, Shalev.

    Assaf: Cheat sheets are cached locally. (Wifi lag caused this reply to be a month late btw)

  • Robin Lu, about 1 year later:

    Inspired by your great tool ‘cheat’, I implemented yet another cheat call ‘chit’ which is based on git.

    I host the ‘chit’ at http://github.com/robin/chit . Could you have a look and give some comments? Thanks!

  • Sixteen people have commented.
    Chime in.
    Sorry, no more comments :(
This is Err, the weblog of PJ Hyett and Chris Wanstrath.
All original content copyright ©2006-2008 the aforementioned.