100s cheatsheets for Ruby and Rails

Posted by Dr Nic on September 03, 2006

Ok, disclaimer. As of writing there aren’t exactly 100+ cheatsheets available on errtheblog’s wonderful new cheatsheet tool, but its only a matter of time til my title is correct. Then I will rewrite this introduction paragraph and I will be the earliest dating author to declare how large and wonderful cheat is.

“What is cheat?” All your cheatsheets on the command line - where you are already working.

Check this out:

>cheat sprintf
sprintf:
  %s => string
  %d => number
  %f => float

>cheat strftime
strftime:

  %a - The abbreviated weekday name (“Sun”)
  %A - The  full  weekday  name (“Sunday”)
  %b - The abbreviated month name (“Jan”)
  %B - The  full  month  name (“January”)
  %c - The preferred local date and time representation
  %d - Day of the month (01..31)
  %H - Hour of the day, 24-hour clock (00..23)
  %I - Hour of the day, 12-hour clock (01..12)
  %j - Day of the year (001..366)
  %m - Month of the year (01..12)
  %M - Minute of the hour (00..59)
  %p - Meridian indicator (“AM”  or  “PM”)
  %S - Second of the minute (00..60)
  %U - Week  number  of the current year,
          starting with the first Sunday as the first
          day of the first week (00..53)
  %W - Week  number  of the current year,
          starting with the first Monday as the first
          day of the first week (00..53)
  %w - Day of the week (Sunday is 0, 0..6)
  %x - Preferred representation for the date alone, no time
  %X - Preferred representation for the time alone, no date
  %y - Year without a century (00..99)
  %Y - Year with century
  %Z - Time zone name
  %% - Literal “%” character

   t = Time.now
   t.strftime(”Printed on %m/%d/%Y”)   #=> “Printed on 04/09/2003″
   t.strftime(”at %I:%M%p”)            #=> “at 08:56AM”

All your cheatsheets are now available via the console.

“All of them”? Yes, well no, but yes. The cheatsheets are written up on a public wiki, and thecheat command retrieves the requested text, caches it locally, and fills your ASCII virtual world with the cheatsheet. So, want to add another cheatsheet? Create a new wiki page, insert cheatsheet, save, done.

“But what cheatsheets are available? How do I know what I can get my dirty, cheating hands on?”

Watch, young reader, and gasp with amazement:

>cheat sheets
All Cheat Sheets:
  assertions
  bash
  cheat
  environments
  iomodes
  migrations
  sprintf
  sti
  strftime
  validations

To my thinking, cheat is a next-generation man tool. Instead of bundling manual pages with your application/gem/library, you could now host a set of live manual pages. Perhaps errtheblog or RubyForge could provide a separate wiki + command line for gem manual pages (hint: gemman or mangem)?

Lord, I love thy software industry.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. Dr Nic » 53 cheat sheets and growing Thu, 19 Oct 2006 10:43:06 UTC

    [...] I said previously that errtheblog’s cheat app would have 100s+ of cheat sheets. [...]

  2. Nick Tue, 03 Jul 2007 23:12:34 UTC

    How would one turn something like 2007-07-03T13-:35:09+00:00 into something like July 3, 2007 …. on the browser side where the browser is able to convert it into the correct time zone?

    Thanks much for any help, I enjoy your blog.

    Nick

Comments