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 »
5 total  XML / RSS feed 

Example crontab using delay script

#
# Delay the startup of my daemon processes. The start_after_delay
# script is a Ruby script which will Kernel.sleep the given time
# (plus a random 10% extra) before executing the given command
#
@reboot /home/mmower/bin/start_after_delay 45m /usr/local/bin/ruby /home/mmower/domains/metavalues.com/apps
/instiki-0.10.2 --port nnnn --storage /home/mmower/domains/metavalues.com/apps/instiki-0.10.2/storage
@reboot /home/mmower/bin/start_after_delay 45m /usr/local/sbin/lighttpd -f /home/mmower/lighttpd/lighttpd.c
onf

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 )

A query from ActiveRecord that isn't working

SELECT
t.*, j.* FROM terms_values j, values t WHERE t.id = j.value_id AND j.term_id = 310

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|

Looking for the MySQL socket

Irulan:~/Projects/MetaValues matt$ ps wwaux |grep mysql
root 220 0.0 0.2 27792 884 ?? S Tue12PM 0:00.04 /bin/sh ./bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/Irulan.local.pid
mysql 239 0.0 1.2 62328 6328 ?? R Tue12PM 3:22.34 /usr/local/mysql/bin/mysqld --defaults-extra-file=/usr/local/mysql/data/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --pid-file=/usr/local/mysql/data/Irulan.local.pid

When in fact what we wanted was mysqladmin -p variables | grep socket
« Newer Snippets
Older Snippets »
5 total  XML / RSS feed