This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
| module User::Extras | |
| # ActiveRecord, at the time of this writing, always writes serialized attributes to the database, even if it hasn't changed. | |
| # See http://github.com/rails/rails/commit/992fda16ed662f028700d63a8dcbd1837f1d58ab for the patch that introduced this. | |
| # So to get around it, we're going to handle the serialization of the extras hash ourselves. | |
| def self.included(klass) | |
| klass.class_eval do | |
| before_save :serialize_extras_attribute | |
| end | |
| klass.extend(ClassMethods) |
This file contains hidden or 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
| module Bluepill | |
| module ProcessConditions | |
| class ProcMemUsage < MemUsage | |
| def run(pid) | |
| begin | |
| total = 0 | |
| File.read("/proc/#{pid}/smaps").split("\n").each do |line| | |
| line =~ /^(Private)_Dirty: +(\d+)/ | |
| if $2 | |
| total += $2.to_i |
This file contains hidden or 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
| int | |
| rb_str_hash(str) | |
| VALUE str; | |
| { | |
| register long len = RSTRING(str)->len; | |
| register char *p = RSTRING(str)->ptr; | |
| register int key = 0; | |
| #if defined(HASH_ELFHASH) | |
| register unsigned int g; |
This file contains hidden or 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 MergeColumn | |
| def initialize(array) | |
| @array = array | |
| @index = 0 | |
| end | |
| def value | |
| @array[@index] | |
| end | |
This file contains hidden or 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 MemcacheLock | |
| class LockTimeout < StandardError; end | |
| LOCK_VALUE = "#{Process.pid}#{Time.now.usec}".to_i # not really important right now | |
| LOCK_TTL = 40 | |
| KEEP_DURATIONS = 100 | |
| EXPIRE_DURATION_ESTIMATE = 60 | |
| MAX_RETRIES = 20 | |
| MAX_RETRY_DELAY = 0.7 | |
| def initialize(memcache, default_duration = nil) |
This file contains hidden or 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 Module | |
| UNITS = %w{second minute hour day week month year solar_year}.map { |s| s.upcase } | |
| CONVERSIONS = [1, 60, 60, 24, 7, 30 / 7.0, 365 / 30.0, 31558150 / 31536000.0] | |
| def const_missing(name) | |
| if name.to_s =~ /^T_([0-9]+)_(#{UNITS.join("|")})S?$/ | |
| num = $1.to_i | |
| unit = $2 | |
| previous_unit_index = UNITS.index(unit) - 1 | |
| value = if previous_unit_index < 0 | |
| num |
This file contains hidden or 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
| scala> class Foo extends scala.collection.mutable.Queue[Int] { | |
| | | |
| | def foo = last0 | |
| | } | |
| defined class Foo | |
| scala> new Foo | |
| res0: Foo = () | |
| scala> res0.enqueue(1) |