Skip to content

Instantly share code, notes, and snippets.

View afair's full-sized avatar

Allen Fair afair

View GitHub Profile
@afair
afair / parse_hstore.pl
Created August 2, 2011 17:58
Perl methods to parse and create PostgreSQL hstore column data
##----------------------------------------------------------------
## HSTORE: PostgreSQL key-value store column type
##----------------------------------------------------------------
# Double-quotes the value, escaping embedded double-quotes. This is NOT the
# same as db quoting (which uses apostrophes), and any value here must also
# be quote()'ed before sending to the database.
sub double_quote {
my ($self, $v) = @_;
$v =~ s/"/\\"/g;
@afair
afair / confident.rb
Created May 8, 2011 23:40
Notes on Advi Grimm's "Confident Code" talk
# http://avdi.org/talks/confident-code-2010-01-12/confident-code.html
# Narrative structure: Four Parts
#==========================================================
# Gather input:
# Coerce
param.to_s #to_i #to_sym Array() ... use liberally!
messages = Array(messages)
# Decorators
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
class Cleaner
def read
f = File.open("nelson.xml")
@doc = Nokogiri::XML(f)
f.close
end
require 'active_support'
class MyLogger < ActiveSupport::BufferedLogger
SEVERITY_NAME = %w( DEBUG INFO WARN ERROR FATAL UNKNOWN )
def custom_line(severity, message)
# Customized Log Format!
message = [Time.now.strftime("%Y-%m-%d %H:%M:%S"), ENV['BL_JOB_ID']||$$, SEVERITY_NAME[severity], message].join("\t")
end
def add(severity, message = nil, progname = nil, &block)
#!/bin/bash
# Update the system first
sudo ntpdate ntp.ubuntu.com
sudo apt-get update
sudo apt-get upgrade
# Ubuntu stuff
sudo apt-get -y install git-core openssh-server openssh-client build-essential wget ntp-simple
# be aware: vim vim-ruby installed x crap :(
#!/bin/bash
# Inspired by http://blog.fiveruns.com/2008/9/24/rails-automation-at-slicehost
apt-get update
apt-get upgrade -y
apt-get -y install build-essential libssl-dev libreadline5-dev zlib1g-dev
apt-get -y install mysql-server libmysqlclient15-dev mysql-client
apt-get -y install ruby ruby1.8-dev irb ri rdoc libopenssl-ruby1.8
RUBYGEMS="rubygems-1.3.0"