Skip to content

Instantly share code, notes, and snippets.

View afair's full-sized avatar

Allen Fair afair

View GitHub Profile
#!/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"
#!/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 :(
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)
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
class Cleaner
def read
f = File.open("nelson.xml")
@doc = Nokogiri::XML(f)
f.close
end
@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
@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 / gist:2402068
Last active September 21, 2024 21:06
Perl References for Kittens

Perl References

Simple Perl variables are called scalars. Examples of scalar values are

   $number      = 123;
   $string      = "String";
   $file_handle = open "<filename";
   $null_value  = undef;
 $instance = MyClass-&gt;new;
@afair
afair / get_mxers.rb
Created April 24, 2012 14:38
Ruby: lookup email MX servers for a domain
require 'resolv'
class Domain
def mxers(domain)
mxs = Resolv::DNS.open do |dns|
ress = dns.getresources(domain, Resolv::DNS::Resource::IN::MX)
ress.map { |r| [r.exchange.to_s, IPSocket::getaddress(r.exchange.to_s), r.preference] }
end
return mxs
@afair
afair / trails.sh
Created May 14, 2012 15:23
Script to initiate (or connect to) a tmux session running a rails project
#!/usr/bin/env bash
#
# Script to initiate (or connect to) a rails project
# tmux session.
if [[ "$1" != "" ]]; then
app=$1
APPDIR=$HOME/src/$app
cd $APPDIR
else
@afair
afair / udata.rb
Created June 5, 2012 20:37
UData - A Ruby 1.9 Unicode Demonstration Class
#!/usr/bin/env ruby
# encoding: UTF-8
###############################################################################
# Ruby 1.9 Unicode Demonstration
###############################################################################
require 'rubygems'
require 'unicode' # gem unicode
require 'unicode_utils' # gem unicode_utils
require 'rchardet19' # gem rchardet19