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 'servolux' | |
require 'logger' | |
server = Servolux::Server.new('Basic', :interval => 1, :logger => Logger.new(STDOUT)) { | |
puts "running #{Time.now}" | |
} | |
server.startup | |
server.join |
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
STDOUT.sync = true | |
require 'rubygems' | |
require 'servolux' | |
require 'logger' | |
require 'beanstalk-client' | |
module JobProcessor | |
def before_executing |
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
STDOUT.sync = true | |
require 'enumerator' | |
module Kernel | |
def interruptible_select( rd, wr = nil, er = nil, timeout = nil ) | |
t = Thread.current | |
t[:select_signal_pipe] = IO.pipe if t[:select_signal_pipe].nil? | |
p = t[:select_signal_pipe] | |
p.first.read_nonblock rescue nil |
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 'servolux' | |
require 'logger' | |
require 'beanstalk-client' | |
module JobProcessor | |
def before_executing | |
STDOUT.puts "[C] #$$ before_executing" | |
@beanstalk = Beanstalk::Pool.new(['localhost:11300']) | |
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
# This module defines a class method called "descendants" that will return a | |
# list of all classes that inherit from the current class. | |
# | |
# Array.descendants | |
# Hash.descendants | |
# ActiveRecord::Base.descendants | |
# | |
module Descendants | |
def descendants | |
ary = [] |
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 'mongo' | |
connection = Mongo::Connection.new | |
database = connection.db 'oddball' | |
collection = database.create_collection('foo', :capped => true, :size => 10 * 1024 * 1024) | |
docs = [] | |
100.times {|n| docs << {'count' => n, 'time' => Time.now.utc.to_s}} |
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
function good_to_go(video) { | |
video.on_event(function(time) { | |
$('#time-display').text(time); | |
}); | |
// at this point in time, our callback function is registered and "prev" | |
// is null | |
video.seek(42); | |
// now we have set the video time - unless we happen to _exactly_ nail the |
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 FastOpenObject | |
def method_missing( symbol, *args, &block ) | |
eigenclass = class << self; self; end | |
eigenclass.class_eval <<-__ | |
def #{symbol} | |
@#{symbol} ||= Hash.new {|h,k| h[k] = Hash.new(0)} | |
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
# A time interval represents a period of time between two instants. | |
# Intervals are inclusive of the start instant and exclusive of the end. | |
# The end instant is always greater than or equal to the start instant. | |
# | |
# Intervals have a fixed duration (or length) seconds. This is the | |
# difference between the start and end instants. | |
# | |
# Methods that are passed an interval as a parameter will treat +nil+ as a | |
# zero length interval at the current instant in time. | |
# |
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
# Be sure to restart your server when you modify this file | |
# Specifies gem version of Rails to use when vendor/rails is not present | |
RAILS_GEM_VERSION = '2.3.8' unless defined? RAILS_GEM_VERSION | |
# Bootstrap the Rails environment, frameworks, and default configuration | |
require File.join(File.dirname(__FILE__), 'boot') | |
require 'logging-rails' | |
Rails::Initializer.run do |config| |