Skip to content

Instantly share code, notes, and snippets.

View jdallien's full-sized avatar

Jeff Dallien jdallien

View GitHub Profile
@avdi
avdi / when.rb
Created December 5, 2011 22:17
Experimenting with Object#when in Ruby
def maybe_a_sandwich
nil
end
# Methods that might return nil are annoying. We want to write a nice
# confident chain:
result = nil
result = maybe_a_sandwich.add_horseradish.get_into_my_belly! rescue $!
result # => #<NoMethodError: undefined method `add_horseradish' for nil:NilClass>
@julik
julik / rackup
Created July 17, 2011 23:03
Surviving rackup crashes when no output is available
#!/usr/local/rvm/rubies/ruby-1.9.2-p180/bin/ruby
#
# This file was generated by Julik.
begin
require 'rubygems'
version = ">= 0"
if ARGV.first =~ /^_(.*)_$/ and Gem::Version.correct? $1 then
version = $1
#!/usr/bin/env ruby
# based on http://gist.github.com/29838
# logging to syslog added
# added killing orphaned procs
# added culling applications to maintain some per application limits
# Find bloating passengers and kill them gracefully. Run from cron every so often.
#
require "rubygems"
require "logging"