irb snippets

Generate a 56-bit DES encrypted (htpasswd) password with Ruby

Tagged ruby, irb, htpasswd, nginx, apache  Languages css

Run the following in an irb console to generate a 56-bit DES encrypted password:

"password".crypt("salt")

The password can be used in an Apache or Nginx htpasswd file to enable basic authentication.

The generated password can also be used in other Unix password files.

How to customize Hirb output

Tagged hirb, irb, console, rails  Languages ruby

Only print id, created_at and title for FeedItem class:

Hirb.disable
  Hirb.enable :output => {
    "FeedItem"=>{
      :options=>{
        :fields=>%w{id created_at title}
      }
    }
  }