Skip to content

Instantly share code, notes, and snippets.

# git lye
# An attempt to make rebasing easy, by draining unnessarcy commit noise.
# No warranty, use at own risk.
# Author Hannes Tydén <[email protected]>
# Contributor Tobias Schmidt <[email protected]>
# TODO
# - Don't sign off all commits are by current user.
@raws
raws / gist:663581
Created November 5, 2010 02:55
EventMachine cleverness to capture stderr
module EventMachine
class StderrHandler < EventMachine::Connection
def initialize(connection)
@connection = connection
end
def receive_data(data)
@connection.receive_stderr(data)
end
end
@addywaddy
addywaddy / semi-colons.js
Created October 28, 2010 07:41
Sometimes semi-colons are indeed necessary in Javascript
function echo (str) {
return str
}
echo("Hello")
(function() {
echo("Goodbye")
})
# Include an anonymous module
#
# Useful for defining a class with a base module. So, instead of:
#
# class Foo
# module Base
# def bar
# # ...
# end
# end
@playerconnect
playerconnect / backend_server_port.rb
Created June 2, 2010 22:36
Resolve thin backend server port from Rails controller
# request.port is unfortunately useless from within the app, as it
# does not reflect the backend bind port, but the frontend proxy.
# So we have to reverse lookup the PID to figure out our port.
def backend_server_port
Thread.current[:backend_server_port] ||= begin
logger.debug "Attempting to reverse-lookup server port from PID file"
port = nil
Dir["#{RAILS_ROOT}/tmp/pids/thin.*.pid"].each do |f|
pid = File.read(f).chomp.to_i
if pid == $$
#!/usr/bin/env ruby
def find_deps(cookbook_dir)
nel = Hash.new { |h, k| h[k] = [] }
Dir.glob("#{cookbook_dir}/*/").each do |r|
deps_for(r, nel)
end
nel
end
# http://yehudakatz.com/2010/02/21/ruby-is-not-a-callable-oriented-language/
module DoAsYouPlease
Object.send :include, self
def method_missing(name, *args, &block)
self.class.const_get(name).call(*args, &block)
end
end
Foo = proc { 42 }