Skip to content

Instantly share code, notes, and snippets.

@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
@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: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
class Object
def in? *others
[others].flatten.include? self
end
end
@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
#
@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 / 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 / avos.rb
Created January 31, 2012 21:08
AutoVivifying OpenStruct
module AutoVivifying
def method_missing name, *args
if name.to_s !~ /\=$/
self.send(:"#{name}=", self.class.new)
else
super
end
end
end
@sdeming
sdeming / centos5-ruby192-chef.sh
Created February 1, 2012 05:25
Bootstrap ruby 1.9.2 with chef on CentOS 5, needs updating to CentOS 6 and ruby 1.9.3
#!/bin/bash
export GIT_SSL_NO_VERIFY=true
# rpmforge
rpm -Uhv http://apt.sw.be/redhat/el5/en/x86_64/rpmforge/RPMS//rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
yum update -y
# dev requirements
yum groupinstall -y "Development Tools"
yum install -y \
@sdeming
sdeming / parasite.rb
Created March 20, 2012 03:29
Sometimes it's fun to give any old object an obscure payload. AKA, a parasite.
module Parasite
def self.infect(object)
(class << object; self end).class_eval do
include Beasties
end
end
module Beasties
def __parasites__