Skip to content

Instantly share code, notes, and snippets.

@thattommyhall
thattommyhall / fog_ELB.rb
Created April 1, 2011 12:09
lb_add and lb_remove take a list of dns_names and remove them from ELB
require 'fog'
ELB = Fog::AWS::ELB.new
COMPUTE = Fog::Compute.new( :provider => 'AWS')
def server_from_dns_name dns_name
COMPUTE.servers.all.find {|server| server.dns_name == dns_name}
end
def id_from_dns_name dns_name
@thattommyhall
thattommyhall / Output.txt
Created April 1, 2011 11:31
Why do the tasks in deploy get executed before the before stuff?
Tom-Halls-MacBook-Pro:hen-night-hq-facebook-app tomh$ cap deploy
METHOD IN DEPLOY
* executing `task_in_deploy'
TASK IN DEPLOY
* executing `deploy'
triggering before callbacks for `deploy'
* executing `do_before'
BEFORE
* executing `deploy:update'
** transaction: start
@thattommyhall
thattommyhall / deploy.rb
Created April 1, 2011 11:29
Testing before/after in Cap
def method_in_deploy
puts "METHOD IN DEPLOY"
end
task :task_in_deploy do
puts "TASK IN DEPLOY"
end
task :do_before do
puts "BEFORE"
@thattommyhall
thattommyhall / hive.conf
Created March 9, 2011 18:22
Upstart script for hive
start on runlevel [2345]
stop on runlevel [06]
respawn
expect fork
script
export HOME="/home/deploy"
export JAVA_HOME="/usr/lib/jvm/java-6-sun"
export HIVE_HOME="/usr/lib/hive"
@thattommyhall
thattommyhall / sig-rescue-E.rb
Created February 24, 2011 16:37
Playing with signals in Ruby
puts "I have PID #{Process.pid}"
Signal.trap("USR1") {puts "prodded me"}
loop do
begin
puts "doing stuff"
sleep 10
rescue Exception => e
puts e.inspect
@thattommyhall
thattommyhall / sinatraHTML5
Created February 18, 2011 17:11
Getting Sinatra to output nice HTML5
configure do
set :haml, { :attr_wrapper => '"', :format => :html5 }
end
@thattommyhall
thattommyhall / create_contact.rb
Created February 16, 2011 23:27
Create a contact in FreeAgent using freeagent_api from https://github.com/aaronrussell/freeagent_api
require 'freeagent_api'
include Freeagent
Freeagent.authenticate({
:domain => 'tthuk.freeagentcentral.com',
:username => 'tom@tthuk.com',
:password => 'NotMyRealPassword'})
Contact.new({ :first_name => 'Tom',
:last_name => 'Hall',
@thattommyhall
thattommyhall / john.rb
Created February 10, 2011 15:25
The AI for the ScroobyDoll
class John
def like_your_work
puts 'I like your work'
end
def x_your_face x
puts "I'll #{x} your face"
end
end
@thattommyhall
thattommyhall / filter_standard_in.rb
Created February 2, 2011 16:00
Not bothering to learn Sed and Awk
#!/usr/bin/env ruby
ARGF.each_with_index do |line, i|
puts line if line =~ /AirPort/ and i % 5 == 0
end
@thattommyhall
thattommyhall / gist:706994
Created November 19, 2010 19:24
FULL OF WIN
> map <- expression({
+ lapply(seq_along(map.values),function(r){
+ x <- runif(map.values[[r]])
+ rhcollect(map.keys[[r]],c(n=map.values[[r]],mean=mean(x),sd=sd(x)))
+ })
+ })
>
> z <- rhmr(map, ofolder="/tmp/test", inout=c('lapply','sequence'),
+ N=10,mapred=list(mapred.reduce.tasks=0),jobname='test')
Error: could not find function "rhmr"