Skip to content

Instantly share code, notes, and snippets.

2012-09-27 18:08:53.258 growlnotify[83684:707] Got disconnected: Error Domain=NSPOSIXErrorDomain Code=61 "Connection refused" UserInfo=0x7fb3e2a0f900 {NSLocalizedDescription=Connection refused, NSLocalizedFailureReason=Error in connect() function}
2012-09-27 18:08:53.260 growlnotify[83684:707] <GrowlGNTPRegistrationAttempt: 0x7fb3e2a0f770> failed because Error Domain=NSPOSIXErrorDomain Code=61 "Connection refused" UserInfo=0x7fb3e2a0f900 {NSLocalizedDescription=Connection refused, NSLocalizedFailureReason=Error in connect() function}
2012-09-27 18:08:53.260 growlnotify[83684:707] Failed to register with (null)
@jjb
jjb / gist:3733242
Created September 16, 2012 17:03
Restart httpd when it is eating memory
#!/bin/env ruby
require 'rubygems'
require 'pony'
# total memory used
total_memory_used = `free | awk '$1=="Mem:" {print $3 / $2 * 100}'`.to_i
# active memory used
used = `awk '$1=="Active:"{active=$2}$1=="MemTotal:"{total=$2}END{print active/total * 100}' /proc/meminfo`.to_i
@jjb
jjb / 1. code.rb
Created September 16, 2012 01:32
Timeout raising an error wherever the inner code happens to be
require 'timeout'
Timeout.timeout(rand) do # random number between 0 and 1 (seconds)
sleep 0.1
sleep 0.1
sleep 0.1
sleep 0.1
sleep 0.1
sleep 0.1
sleep 0.1
@jjb
jjb / gist:3730588
Created September 16, 2012 00:43
raising an exception inside a child thread
def do_jobs
begin
while true
# do interesting things
end
rescue NoMoreDiskSpace
# tidy things up
end
end
@jjb
jjb / 1. thread_raise.rb
Created September 16, 2012 00:19
Ruby Thread#raise raises at wherever the thread happens to be
require 'thread'
t = Thread.new{
sleep 0.1
sleep 0.1
sleep 0.1
sleep 0.1
sleep 0.1
}
@jjb
jjb / 1.code.rb
Created September 15, 2012 05:38
t = Thread.start{
begin
puts "starting executing code!"
sleep 1
puts "done executing code!" # we don't expect to reach here
rescue Exception
puts "rescuing!" # we don't expect to reach here
ensure
puts "ensuring!" # will we reach here????? (yes)
end
@jjb
jjb / 1.rb
Created August 25, 2012 21:22
method which accepts multiple blocks
def generate_continue_object(*args)
args.each{|a| puts a.inspect}
yield if block_given?
continue_object = Object.new
def continue_object.next_block
if block_given?
yield
@jjb
jjb / gist:3237811
Created August 2, 2012 15:13
List an ActiveRecord model's callbacks
self.class._create_callbacks.select { |callback| callback.kind.eql?(:after) }.collect(&:filter)
@jjb
jjb / gist:3149039
Created July 20, 2012 06:26
tests illustrating problems with Timeout.timeout
def subject(throws, catches)
$inner_succeeded=nil
$raised_in_inner=nil
$caught_in_inner=nil
$raised_in_outer=nil
$not_raised_in_outer=nil
begin
Timeout.timeout(0.1, throws){
begin
@jjb
jjb / 1. code.rb
Created July 13, 2012 14:37
Problems with Timeout.timeout's use of Thread#raise
require 'timeout'
def process_foos(error_to_rescue)
begin
# -> process Foos
# -> if we run out of Foos, raise
sleep 2
rescue error_to_rescue
# -> email the manager that we ran out of Foos
puts <<-MESSAGE