Skip to content

Instantly share code, notes, and snippets.

View phiggins's full-sized avatar

pete higgins phiggins

View GitHub Profile
@coreyhaines
coreyhaines / .rspec
Last active April 11, 2024 00:19
Active Record Spec Helper - Loading just active record
--colour
-I app
@burke
burke / 0-readme.md
Created January 27, 2012 13:44 — forked from funny-falcon/cumulative_performance.patch
ruby-1.9.3-p327 cumulative performance patch for rbenv

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.

@parndt
parndt / Guardfile
Created January 17, 2012 22:17
RSpec support for edge Refinery apps
engines = Dir[File.expand_path('../vendor/engines/*', __FILE__)]
guard 'spork', :wait => 60, :cucumber => false, :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch('spec/spec_helper.rb')
watch(%r{^spec/support/.+\.rb$})
@jbarnette
jbarnette / example.rb
Created April 6, 2011 14:55
A naïve state machine for ActiveRecord. Ruby 1.9.
require "stateful"
class Folder < ActiveRecord::Base
include Stateful
# ...
stateful do
state :active
state :inactive
# a daemon method that blocks until the grandchild is ready
#
# sending the pid up a pipe (grandchild -> child -> parent)
#
def daemon(options = {}, &block)
# setup
#
raise(ArgumentError, 'no block!') unless block
chdir = options[:chdir] || options['chdir'] || '.'
@mislav
mislav / http_gzip.rb
Created February 17, 2011 12:58
Use Net::HTTP in a way that handles gzip/deflate compression transparently
require 'addressable/uri'
require 'net/http'
require 'yajl'
# Wikipedia API
url = Addressable::URI.parse 'http://en.wikipedia.org/w/api.php?format=json'
# let Addressable handle query encoding
url.query_values = url.query_values.update :srsearch => 'Scott Pilgrim', :action => 'query', :list => 'search'
@raggi
raggi / em_chat_channel_server.rb
Created October 17, 2010 17:42
chat server example using EM::Channel pub-sub, with simple tracing for teaching
require 'eventmachine'
require 'socket'
class Client < EM::Connection
include EM::P::LineText2
HELP = "Server - Welcome to ghettochat. Use /nick to set your nick.\n"
def initialize(global_channel)
@global = global_channel
@apeiros
apeiros / pool.rb
Created August 26, 2010 21:10
Thread::Pool
require 'thread'
class Thread
# Example:
# pool = Thread::Pool.new(10) do |exception| handle(exception) end
# pool.execute(1,2,3) do |x,y,z| whatever(x,y,z) end
# pool.join
class Pool
require 'fiddle'
module FFI
module Library
def ffi_lib *libs
libs.each { |lib| Fiddle.dlopen lib }
end
def attach_function name, arg_types, return_type
f = Fiddle::Function.new(
###
# This is a demonstration of using SQLite3's Virtual File System API in Ruby.
#
# == Synopsis
#
# This program will store its SQLite database after the __END__ line.
#
# === In Detail
#
# SQLite3 uses the DATABase class as a proxy for our IO object. Upon