Skip to content

Instantly share code, notes, and snippets.

View virtualstaticvoid's full-sized avatar

Chris Stefano virtualstaticvoid

View GitHub Profile
@virtualstaticvoid
virtualstaticvoid / fbr.rb
Created February 28, 2011 17:07 — forked from tmm1/fbr.rb
Poor Man's Fiber
# Poor Man's Fiber (API compatible Thread based Fiber implementation for Ruby 1.8)
# (c) 2008 Aman Gupta (tmm1)
unless defined? Fiber
require 'thread'
class FiberError < StandardError; end
class Fiber
def initialize
@virtualstaticvoid
virtualstaticvoid / testing.rb
Created March 10, 2011 15:56 — forked from anonymous/testing.rb
ruote usage example
require 'rubygems'
require 'ruote'
engine = Ruote::Engine.new(Ruote::Worker.new(Ruote::HashStorage.new))
engine.register do
catchall Ruote::StorageParticipant
end
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
module Test
module Unit
TestCase = RSpec::Core::ExampleGroup
end
end
class Test::Unit::TestCase
def self.inherited(host)
host.set_it_up host.name.gsub(/(Spec|Test)/,'')
def host.method_added(name)
@virtualstaticvoid
virtualstaticvoid / .irbrc
Created June 8, 2011 13:21 — forked from wtnabe/.irbrc
A model dumper for rails console ( Rails 3 or later ) and .irbrc for rails env
# -*- mode: ruby; coding: utf-8 -*-
if defined? Rails
railsrc = __FILE__ + '.rails'
load railsrc if File.exist? railsrc
envrc = File.join( Rails.root, '.irbrc' )
load envrc if File.exist? envrc
end
@virtualstaticvoid
virtualstaticvoid / pagination.md
Created August 10, 2011 15:28 — forked from mislav/pagination.md
"Pagination 101" by Faruk Ateş

Pagination 101

Article by Faruk Ateş, [originally on KuraFire.net][original] which is currently down

One of the most commonly overlooked and under-refined elements of a website is its pagination controls. In many cases, these are treated as an afterthought. I rarely come across a website that has decent pagination, and it always makes me wonder why so few manage to get it right. After all, I'd say that pagination is pretty easy to get right. Alas, that doesn't seem the case, so after encouragement from Chris Messina on Flickr I decided to write my Pagination 101, hopefully it'll give you some clues as to what makes good pagination.

Before going into analyzing good and bad pagination, I want to explain just what I consider to be pagination: Pagination is any kind of control system that lets the user browse through pages of search results, archives, or any other kind of continued content. Search results are the o

@virtualstaticvoid
virtualstaticvoid / nginx.conf
Created September 5, 2011 06:32 — forked from thewebfellas/nginx.conf
sample nginx.conf for thin
user nginx;
worker_processes 5;
error_log /var/log/nginx.error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
@virtualstaticvoid
virtualstaticvoid / domain.rb
Created December 30, 2011 15:55 — forked from erikrozendaal/domain.rb
Simple Ruby DSL for CQRS+ES aggregates
# CQRS+ES Domain DSL
class Symbol
def snake_case
to_s.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
gsub(/([a-z\d])([A-Z])/, '\1_\2').
tr("-", "_").
downcase.to_sym
end
@virtualstaticvoid
virtualstaticvoid / redis_pubsub_demo.rb
Created March 18, 2012 18:44 — forked from pietern/redis_pubsub_demo.rb
Simple demo to showcase Redis PubSub with EventMachine
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
@virtualstaticvoid
virtualstaticvoid / databases.rake
Created May 11, 2012 20:41 — forked from wbailey/databases.rake
ActiveRecord migrations outside of Rails
require 'yaml'
require 'logger'
require 'active_record'
namespace :db do
def create_database config
options = {:charset => 'utf8', :collation => 'utf8_unicode_ci'}
create_db = lambda do |config|
ActiveRecord::Base.establish_connection config.merge('database' => nil)