Skip to content

Instantly share code, notes, and snippets.


Marc Ignacio padi

View GitHub Profile
padi / report.rb
Created Oct 5, 2011
Rake Task for Updating Conditions
View report.rb
desc 'Update traffic condition'
task :update_condition => :environment do
Report.all.each do |report|
report.update_attribute(:conditions, unless report.user

Literate Ruby

Inspired by Literate CoffeeScript.

$ cat
Here's a simple program

    puts "Hello, world"
$ ruby litrb.rb <
Hello, world
View README.txt
The purpose of all this is to see if sphinx, thinking sphinx and thinking sphinx delayed delta are all working properly.
I created a test controller on a separate monit subdomain that simply generates and posts a test value and then uses curl to retrieve it. If the two values match, then sphinx is working properly with delayed delta.
This example assumes a Linux installation.
The file '' spawns the `rake ts:dd` process in the background, saving its PID to tmp/pids in your Rails project. You can start and stop it by running '/etc/init.d/ start' and '/etc/init.d/ stop'. You will use these in your monitoring to, see the monitrc snippet.
In a crontab, every X seconds or minutes, run '' to see if records are properly being inserted and indexed. If they aren't, then kill all Thinking Sphinx processes and monit should restart them.
View resque_retry.rb
# inspired by
# retry all failed Resque jobs except the ones that have already been retried
# This is, for instance, useful if you have already retried some jobs via the web interface.
Resque::Failure.count.times do |i|
Resque::Failure.requeue(i) unless Resque::Failure.all(i, 1)['retried_at'].present?
# retry all :)
Resque::Failure.count.times do |i|

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

# remap prefix to Control + a

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.


You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.

build_package_combined_patch() {
local package_name="$1"
curl | patch -p1
./configure --prefix="$PREFIX_PATH" $CONFIGURE_OPTS
make -j 8
make install
} >&4 2>&1