ruby

Railscasts

Tagged:  

So I was pointed in the direction of Railscasts.com and duly leeched the site:


curl "http://feeds.feedburner.com/railscasts_ipod" \
| grep -Eo "http://media.railscasts.com/ipod_videos/.*m4v" \
| sort | xargs -n1 wget -c

did the trick.

Now I need to find time to watch them all :)

Check Email Script

Tagged:  

So I've been playing with conky again and wanted it to check all my email accounts for new mail.

I found this script but I wanted to check multiple accounts and show the total mail count in my inbox.

After some hacking here is what I came up with... and yes I've removed the base64 encoding as it doesn't add any security what so ever!

#!/usr/bin/env ruby

require "optparse"
require "net/imap"
#
# Parse options
#
def parse_options(args)

  # Hash to hold options
  options = Hash.new

  parser = OptionParser.new do |opts|

    opts.on('-H host', '--host host', 'Host') do |v|
      options[:host] = v
    end

    opts.on('-u user', '--user user', 'User') do |v|
      options[:user] = v
    end

    opts.on('-p password', '--password password', 'Password') do |v|
      options[:password] = v
    end

    opts.on('-h', '--help', 'Displays usage information') do
      puts opts
      exit 1
    end
  end

  # Parse Parameters
  begin
    parser.parse!(args)
  rescue OptionParser::ParseError => e
    puts "Parse Error: " + e
    puts parser.to_a
  end

  # Check for required params
  if (options.has_key?(:host) && options.has_key?(:user) && options.has_key?(:password))
    #
    # Return options
    #
    options
  else
    puts parser.to_a
    exit 1
  end

end
options = parse_options(ARGV)

#
# Lets check some mail!
#
imap = Net::IMAP.new(options[:host])
imap.login(options[:user], options[:password])

#
# Get total mail
#
status = imap.status("inbox", ["MESSAGES", "UNSEEN"])
puts "#{status['UNSEEN']}/#{status['MESSAGES']}"
imap.disconnect

DrySQL

Tagged:  

Currently investigating this Ruby on Rails thing that everyone is raving about and so far I'm liking it.

DrySQL is one of the many examples as to why Rails rocks :)

DrySQL is a Ruby plug-in that extends ActiveRecord and applies the DRY principle to Object-Relational Mapping.

The idea behind DrySQL is that you define columns, keys, constraints, and relationships on your database, and you shouldn't need to re-define any of these things in your application code.

Shame about this thou...

has_and_belongs_to_many association generation is not implemented at this point

... hopefully it'll be supported soon.

Syndicate content