This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'memcached' | |
def sleep_for(count) | |
sleep((2**count) / 2.0) | |
# sleep (1 / (count + 1).to_f) * 0.6 | |
# sleep [0.2, (rand / 3)].max | |
end | |
class Error < Exception; end | |
def acquire_lock(memcache, key, retries = 100) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
env_vars = "RAILS_ENV=production PATH=/sb/thehierarchy/ruby/bin:/sb/thehierarchye/nginx/sbin:$PATH RUBY_HEAP_MIN_SLOTS=500000 RUBY_HEAP_SLOTS_INCREMENT=250000 RUBY_HEAP_SLOTS_GROWTH_FACTOR=1 RUBY_GC_MALLOC_LIMIT=50000000" | |
RAILS_ROOT = "/var/www/apps/thehierarchy/current/" | |
Bluepill.application("thehierarchy") do |app| | |
app.process("scheduled_notifications") do |process| | |
process.group = "thehierarchy" | |
process.pid_file = File.join(RAILS_ROOT, "tmp", "pids", "scheduled_notifications") | |
process.daemonize = true | |
process.start_command = "/usr/bin/env #{env_vars} rake --rakefile=#{RAILS_ROOT}/Rakefile app_name:scheduled_notifications" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RackProctitle | |
def initialize(app, options = nil) | |
@app = app | |
@prefix = options.delete(:prefix) if options | |
@revision = APPLICATION_VERSION if defined?(APPLICATION_VERSION) | |
@mutex = Mutex.new | |
@titles = [] | |
@request_threads = [] | |
@queue_length = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# bash completion support for core Git. | |
# | |
# Copyright (C) 2006,2007 Shawn O. Pearce <[email protected]> | |
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/). | |
# Distributed under the GNU General Public License, version 2.0. | |
# | |
# The contained completion routines provide support for completing: | |
# | |
# *) local and remote branch names |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# inject but doesn't need you to return the memo, uses the same object. Doesn't work with immutable (i.e. summing) | |
module Enumerable | |
def inject_into(obj) | |
each {|e| yield(obj, e)} | |
obj | |
end | |
end | |
a = [1,2,3].inject_into([]) do |m, e| | |
m << (e + 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# a maybe valid use-case of flip flops | |
begin | |
puts "hi" | |
raise Exception | |
rescue Exception => e | |
retry if ((i ||= 1) == 1)..((i += 1) >= 2) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#fails | |
class AnonymousFunction | |
def initialize(&func) | |
self.class.send(:define_method, :call, &func) | |
end | |
end | |
blah = 1 | |
s = AnonymousFunction.new do |blah| | |
puts blah |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="body"> | |
<div id="link_test"> | |
<a href="#should_not_show_up" id="the_link">Click Me</a> | |
</div> | |
<script type="text/javascript"> | |
function TestCase() { | |
document.getElementById('link_test').addEventListener('click', function(){ | |
console.log('clicked from container'); | |
return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def multi_choose(choices, size, index = 0, hax = Hash.new) | |
return [] if index == choices.size | |
hax[[size, index]] ||= begin | |
base = [choices[index]] * size | |
s = base | |
multisets = [base] | |
0.upto(size - 1) do |i| | |
s = s.dup | |
s.pop | |
multi_choose(choices, i + 1, index + 1, hax).each {|s2| multisets << s + s2} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://www.facebook.com/jobs_puzzles/index.php?puzzle_id=8 | |
require 'set' | |
class Node | |
@@nodes = Hash.new {|h, k| h[k] = Node.new(k)} | |
class << self | |
def find_clusters | |
Node.solidify! | |
clusters = [] | |
nodes.values.each do |n| |