Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

Matt Mower http://matt.blogs.it/

« Newer Snippets
Older Snippets »
2 total  XML / RSS feed 

Ruby script to delay execution of a command (intended for @reboot crontab)

#!/usr/local/bin/ruby
# Start after delay
#

# Delay specifications must be one of Xs (secs), Xm (mins), Xh (hours)
case ARGV[0]
when /(\d+)s/
@delay = $1.to_i
when /(\d+)m/
@delay = 60 * $1.to_i
when /(\d+)h/
@delay = 3600 * $1.to_i
else
raise "Incorrect delay specification"
end

# A random factor of up to 10% will be added to any given delay
@rf = ( @delay * 0.1 ).to_i
@delay += rand( @rf )
sleep( @delay )

# Join up remaining arguments to form the command to be executed
ARGV.slice!( 0 )
@command = ARGV.join( ' ' )
exec( @command )

TextMate indenting

class Feed < ActiveRecord::Base
has_many :items

def self.aggregate

Feed.find_by_sql( "SELECT * FROM feeds WHERE is_enabled = 1 AND ( DATE_ADD( last_read, INTERVAL 1 HOUR ) < NOW() OR last_read = 0 OR last_read IS NULL )" ).each do |feed|
« Newer Snippets
Older Snippets »
2 total  XML / RSS feed