Skip to content

Instantly share code, notes, and snippets.

@sdeming
sdeming / pred.rb
Created January 29, 2012 01:48
predicate method chaining
module PredicateMethods
module Firewalls
class Allow
def initialize(what)
@wrappee = what
end
def method_missing(name, *args, &blk)
begin
@sdeming
sdeming / factorials_in_cc.rb
Created January 26, 2012 03:48
Use callcc for non-recursive factorials.
require 'continuation'
class FactorialsInCC
def fact(n)
factorial = 1
callcc { |fact_jmp| @fact_jmp = fact_jmp }
factorial *= n
n -= 1
@sdeming
sdeming / Makefile
Created December 14, 2011 19:29
Old .so to redirect .svn directories to another place, keeping your local directory tree clean. From years ago at site5. AKA the Load Bearing Kludge. Build then use the .so in your LD_PRELOAD before executing svn.
#
# The simplest of makefiles.
#
# Perhapse after some refactoring this will be more complex, but for now
# it is sweet and simple.
#
# SD 2005-10-23
#
class Object
def in? *others
[others].flatten.include? self
end
end
@sdeming
sdeming / gist:981231
Created May 19, 2011 17:04
spec_helper.rb, patch for using transactions with Sequel
class Spec::Example::ExampleGroup
def execute(*args, &block)
DB.transaction do
begin
super(*args, &block);
ensure
raise Sequel::Error::Rollback
end
end
end
@sdeming
sdeming / syncdaemon.conf
Created April 21, 2011 14:21
UbuntuOne sync config that ignores sublime session file (save it as ~/.config/ubuntuone/syncdaemon.conf)
[__main__]
ignore.default = \A#.*\Z
\A.*~\Z
\A.*\.py[oc]\Z
\A.*\.sw[nopx]\Z
\A.*\.swpx\Z
\A\..*\.tmp\Z
\A\.~lock\..*#\Z
\A.*\Session.sublime_session\Z
@sdeming
sdeming / gist:869717
Created March 14, 2011 19:33
Get DDL to create foreign key constraints in Oracle... Wooooo hoo!
select 'alter table ' || source_table || ' add constraint ' || constraint_name || ' foreign key (' || con_columns || ') references ' || target_table || ' (' || ind_columns || ') enable' data
from (select constraint_name, source_table, target_index, target_table, con_columns, wm_concat(column_name) ind_columns
from (select a.constraint_name, a.source_table, a.target_index, b.table_name target_table, a.con_columns, b.column_name, b.column_position
from (select a.constraint_name, a.source_table, a.target_index, wm_concat(a.column_name) con_columns
from (select a.constraint_name,
a.table_name source_table,
a.r_constraint_name target_index,
b.column_name,
b.position
from user_constraints a