Skip to content

Instantly share code, notes, and snippets.

View rares's full-sized avatar
🌑

(╯°□°)╯︵ ┻━┻ rares

🌑
View GitHub Profile
# Parallel map
# Originally from http://project.ioni.st/post/2332#snippet_2332
class Array
def pmap
threads = []
0.upto(size - 1) do |n|
threads << Thread.new do
yield(at(n))
end
end
@rares
rares / gist:8152
Created August 30, 2008 23:21 — forked from defunkt/gist:6857
module URI
def self.parse_with_options(uri_str, opts = {})
parsed_uri = self.parse(uri_str)
sing = (class << parsed_uri; self end)
sing.send :define_method, :options do
opts
end
parsed_uri
end
end
# capistrano tip:
# log into target server for first time an type this:
ssh git@github.com
# this will allows capistrano to perform the clone without issue.
require 'rubygems'
require 'xmpp4r-simple'
require 'pp'
im = Jabber::Simple.new("user", "password")
Jabber::debug = true
class Handler
def on_message(message)
puts message
$:.unshift File.dirname(__FILE__) + "/lib"
require "oauth/consumer"
require "pp"
consumer = OAuth::Consumer.new(
"<consumer.key>",
"<consumer.secret>",
{
:site => "http://api.netflix.com",
:request_token_url => "https://api-user.netflix.com/oauth/request_token",
@rares
rares / god.rb
Created November 18, 2008 18:52 — forked from defunkt/god.rb
rails_root = "/data/github/current"
20.times do |num|
God.watch do |w|
w.name = "dj-#{num}"
w.group = 'dj'
w.interval = 30.seconds
w.start = "rake -f #{rails_root}/Rakefile production jobs:work"
w.uid = 'git'

Lessons Learned

Be Confident

Tests build confidence. Write 'em. They'll save your ass, and they'll let you take a chainsaw to your code without being afraid of unintended consequences.

Be Lazy

# 1) Point *.example.com in your DNS setup to your server.
#
# 2) Setup an Apache vhost to catch the star pointer:
#
# <VirtualHost *:80>
# ServerName *.example.com
# </VirtualHost>
#
# 3) Set the current account from the subdomain
class ApplicationController < ActionController::Base
# at the very least, use inheritance!
class Object
alias_method :try, :send
end
class NilClass
def try(*args)
nil
end
@rares
rares / gist:60858
Created February 9, 2009 16:43 — forked from imbriaco/gist:60855
desc "Do rolling restarts of the Mongrel servers in pairs, at 90s intervals."
task :rolling do
servers = []
roles[:app].each do |server|
next unless server.options.fetch(:listener, true)
servers << [] if servers.first.nil? || servers.last.length > 1
servers.last << server.host
end