Skip to content

Instantly share code, notes, and snippets.

View virtualstaticvoid's full-sized avatar

Chris Stefano virtualstaticvoid

View GitHub Profile
@virtualstaticvoid
virtualstaticvoid / XPathHelp.cs
Created January 24, 2011 09:55
Utility for determining the XPath of a given node
using System;
using System.Text;
using System.Xml;
using System.Xml.XPath;
public static class XPathHelp
{
public static string GetXPathForNode(XmlNode node)
{
@virtualstaticvoid
virtualstaticvoid / git-checkout-branch.sh
Created February 23, 2011 20:10
Checkout single Git branch
#!/bin/bash
#
# Creates a Git repository, fetches and checks out a single branch from the remote repository
#
url=$1
branch=$2
git init
@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")
@virtualstaticvoid
virtualstaticvoid / delete_svn.sh
Created March 25, 2011 06:41
Delete ".svn" directories
#!/bin/sh
rm -rf `find . -type d -name .svn`
@virtualstaticvoid
virtualstaticvoid / schema_utils.rb
Last active September 25, 2015 07:47
Multi-schema support for migrations in Rails
#
# http://www.developerit.com/2010/05/07/creating-a-multi-tenant-application-using-postgresqls-schemas-and-rails
#
module SchemaUtils
def self.add_schema_to_path(schema)
conn = ActiveRecord::Base.connection
conn.execute "SET search_path TO #{schema}, #{conn.schema_search_path}"
end
def self.reset_search_path
@virtualstaticvoid
virtualstaticvoid / access_control.rb
Created March 26, 2011 15:28
Simple role based access control
module AccessControl
extend self
def configure(&block)
instance_eval(&block)
end
def definitions
@definitions ||= Hash.new
end
module ActiveSupport
module Callbacks
module ClassMethods
def define_callbacks(*callbacks)
config = callbacks.last.is_a?(Hash) ? callbacks.pop : {}
callbacks.each do |callback|
class_attribute "_#{callback}_callbacks"
send("_#{callback}_callbacks=", CallbackChain.new(callback, config))
__define_runner(callback)
end
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)