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 | |
# --*-- encoding: UTF-8 --*-- | |
# RPCFN: Ruby Fun (#4) | |
# @author 梁智敏(Gimi Liang) liang.gimi at gmail dot com | |
class Polynomial | |
COEFFICIENT_PATTERN = '%+d'.freeze | |
ANNOYING_COEFFICIENT = /\A([+-])1\Z/.freeze |
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
# RPCFN #5: Mazes | |
# @author 梁智敏(Gimi Liang) [gimi.liang at gamil dot com] | |
# @date 2009/12/29 | |
class Maze | |
START_POINT_MARKER = 'A'.freeze | |
END_POINT_MARKER = 'B'.freeze | |
INFINITE = (1.0 / 0.0).freeze | |
class Cell | |
WALL = '#'.unpack('c').first.freeze |
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
# Factory girl, relaxed. | |
# | |
# Factory.define :user do |f| | |
# f.login 'johndoe%d' # Sequence. | |
# f.email '%{login}@example.com' # Interpolate. | |
# f.password f.password_confirmation('foobar') # Chain. | |
# end | |
# | |
# Factory.define :post do |f| | |
# f.user { Factory :user } # Blocks, if you must. |
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 'yaml' | |
require 'sinatra/base' | |
require 'sequel_core' | |
class MyApp < Sinatra::Base | |
configure do | |
DB = Sequel.connect YAML.load(File.read(__FILE__).split("__END__\n")[-1])[ENV['RACK_ENV'] || 'production'] | |
Sequel::Mysql.convert_tinyint_to_bool = false | |
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
ActionController::Routing::Routes.draw do |map| | |
map.connect "/", :controller => "admin", | |
:conditions => { :subdomain => "admin" } | |
map.connect "/", :controller => "blog" | |
# ... | |
end | |
# jamisbuck/routing/routeset.rb | |
module JamisBuck | |
module Routing |
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 'eventmachine' | |
require 'em-websocket' | |
require 'json' | |
class Connection | |
attr_accessor :socket, :user_id | |
def initialize(socket, user_id) | |
@socket = socket |
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
''' | |
redis_search.py | |
Written by Josiah Carlson July 3, 2010 | |
Released into the public domain. | |
This module implements a simple TF/IDF indexing and search algorithm using |
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 | |
# pws | |
# see http://rbjl.net/41-tutorial-build-your-own-password-safe-with-ruby for more information | |
require 'rubygems' if RUBY_VERSION[2] == ?8 | |
require 'openssl' | |
require 'fileutils' | |
require 'clipboard' # gem install clipboard |
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 'rack' | |
class Object | |
def webapp | |
class << self | |
define_method :call do |env| | |
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?) | |
[200, {}, send(func, *attrs)] | |
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
pid_file = "someapp.pid" | |
pid = File.read pid_file | |
begin | |
Process.kill 'TERM', pid | |
rescue Errno::ESRCH | |
puts $! | |
end | |
require 'timeout' |
OlderNewer