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 'servolux' | |
require 'logging' | |
# This is a simple demonstration server that shows how to register a signal handler | |
# for toggling the log level of your application. This is very useful in a production | |
# application where you want to enable debug messages for a brief period of time. The | |
# Servolux::Server class looks for a few special methods and registers them as signal | |
# handlers. Here, the "usr1" method will be called when the USR1 signal is sent to the | |
# process. |
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 is a very simple-minded and inelegant way to prevent others from | |
# modifying (monkey patching) your code. A global method "monkey_proof" is | |
# provided that can be used to prevent monkey patching on most any Object or | |
# Class. | |
# | |
moddule MonkeyProof | |
VERSION = '1.0.0' | |
def self.included( other ) |
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
#!/usr/bin/env | |
# Possibly one of the faster wasy to concatenate two files in ruby. | |
# Another way might be to use the lower level IO#sysread, IO#syswrite methods | |
# I think the main benefit in this case is the reusing of the String instance as | |
# the buffer. | |
dest = ARGV.shift | |
src = ARGV.shift |
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
Thread.abort_on_exception = true | |
require 'directory_watcher' | |
STDOUT.sync = true | |
puts "Directory Watcher v #{DirectoryWatcher.version}" |
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 'yajl' | |
module Rack | |
# A Rack middleware for parsing POST/PUT body data when Content-Type is | |
# <tt>application/json</tt>. | |
# | |
class JsonPostBody |
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 'socket' | |
require 'open-uri' | |
require 'rubygems' | |
require 'servolux' | |
require 'nokogiri' | |
PATH = '/tmp/web_fetch.socket' | |
# Create a UNIX socket at the tmp PATH |
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 fix_escape( str ) | |
str.gsub(%r/\\(\d+|[nr])/) { |match| | |
case $1 | |
when 'n': "\n" | |
when 'r': "\r" | |
else | |
[$1.to_i(8)].pack('C') | |
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
# 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| |
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
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 |