Skip to content

Instantly share code, notes, and snippets.

View thinkerbot's full-sized avatar

Simon Chiang thinkerbot

View GitHub Profile
@thinkerbot
thinkerbot / progress_bar.rb
Created January 20, 2011 00:37
a crappy progress bar
class ProgressBar
attr_reader :format
attr_reader :length
attr_reader :period
attr_reader :char
attr_reader :io
def initialize(format, options={})
options = {
:length => 7,
@thinkerbot
thinkerbot / test.sh
Created January 18, 2011 23:46
shell script assertions
assert_status_equal () {
expected=$1; actual=$2; lineno=$3
if [ $actual -ne $expected ]
then
echo "[$0:$lineno] exit status $actual (expected $expected)"
exit 1
fi
}
@thinkerbot
thinkerbot / active_record_example.rb
Created January 7, 2011 19:05
Demonstrates abstraction of columns via a method
require 'rubygems'
require 'fileutils'
require 'active_record'
# >ruby active_record_example.rb
# a
# b
# a.b
# x
# y
@thinkerbot
thinkerbot / mtime_test.rb
Created December 20, 2010 15:16
Illustrate mtime behavior
require 'fileutils'
dir = File.expand_path('../mtime', __FILE__)
file = "#{dir}/file.txt"
format = "%5s:%-20s %s"
FileUtils.rm_rf(dir)
FileUtils.mkdir_p(dir)
puts format % [:dir, "mkdir", File.mtime(dir)]
@thinkerbot
thinkerbot / context.yml
Created December 20, 2010 00:51
ERB vs Erubis Shootout
list:
- name: Adobe Systems
name2: Adobe Systems Inc.
url: http://www.adobe.com
symbol: ADBE
price: 39.26
change: 0.13
ratio: 0.33
- name: Advanced Micro Devices
name2: Advanced Micro Devices Inc.
@thinkerbot
thinkerbot / public_enc_example.sh
Created November 19, 2010 04:56
Public-key encryption example using OpenSSL
#!/bin/bash
#
# Public-Key Encryption and Decryption
# * http://www.openssl.org/
# * http://barelyenough.org/blog/2008/04/fun-with-public-keys/
#
# Mac OS X 10.6.4
# OpenSSL 0.9.8l 5 Nov 2009
# Generate keys
@thinkerbot
thinkerbot / gem_env.sh
Created November 8, 2010 18:28
Illustrates GEM_HOME vs GEM_PATH
# Two ENV variables control the 'gem' command:
#
# GEM_HOME: the single path to a gem dir where gems are installed
# GEM_PATH: a standard PATH to gem dirs where gems are found
#
# A gem directory is a directory that holds gems. The 'gem' command will lay
# out and utilize the following structure:
#
# bin # installed bin scripts
# cache # .gem files ex: cache/gem_name.gem
@thinkerbot
thinkerbot / couchdb_cheats.txt
Created September 22, 2010 23:00
CouchDB Cheats
# Post a tempview
curl -X POST http://127.0.0.1:5984/database/_temp_view -H "Content-Type: application/json" -T _temp_view.json
@thinkerbot
thinkerbot / rails_config_order.txt
Created September 22, 2010 15:11
Rails Config Order
The configuration order - Rails 2.3.3.
1. config/preinitializer.rb
2. config/environment.rb
3. config/environments/#{RAILS_ENV}.rb
4. plugin initialization
5. gem initialization
6. config/initializer/*.rb
7. all after_initialize blocks, in the order they were defined in (so same order as above)
8. any junk left below the Rails::Initializer.run call/block in environment.rb
@thinkerbot
thinkerbot / rvm_bug_desc.txt
Created September 14, 2010 16:25
rvm PATH bug
I have observed a bug in PATH on 'rvm use' where an extra ' :' is added,
preventing discovery of executables along that last path. Without the debug
info the relevant commmands and output are:
% echo $PATH
/Users/Simon/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/usr/local/instantclient-10.2
% rvm use 1.8.6@chiangs --create
Using /Users/Simon/.rvm/gems/ruby-1.8.6-p399 with gemset chiangs
% echo $PATH
/Users/Simon/.rvm/gems/ruby-1.8.6-p399@chiangs/bin:/Users/Simon/.rvm/gems/ruby-1.8.6-p399@global/bin:/Users/Simon/.rvm/rubies/ruby-1.8.6-p399/bin:/Users/Simon/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/usr/local/instantclient-10.2 :