Dr Nic

100s cheatsheets for Ruby and Rails

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
  %s => string
  %d => number
  %f => float

>cheat 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:

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.

Related posts:

  1. Validate and Save your Ruby in TextMate – with secret Rubinus superpowers In some TextMate bundles, if you save a file it...
  2. Future proofing your Ruby code. Ruby 1.9.1 is coming. Bugger. I’m a Ruby monogamist. I use the Ruby...
  3. Unit Testing iPhone apps with Ruby: rbiphonetest Everything to love about Ruby: the concise, powerful language;...
  4. Using Ruby within TextMate snippets and commands I didn’t know you could run Ruby within TextMate snippets....
  5. The explicit Ruby metaclass you know you always wanted When you define a “static” or “class” method on a...

3 Responses to “100s cheatsheets for Ruby and Rails”

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

  2. Nick says:

    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.


  3. Brendon Muir says:

    Hi there, you might want to add the undocumented %l (lowercase L) which gives the 12 hour hour without the leading zero :)