Skip to content

Instantly share code, notes, and snippets.

View thinkerbot's full-sized avatar

Simon Chiang thinkerbot

View GitHub Profile
@thinkerbot
thinkerbot / ddl.sql
Created July 27, 2010 15:55
Eager loading gotchas
create table depts (
id integer primary key,
name varchar2(20),
city varchar2(20),
state varchar2(2)
);
create table jobs (
id integer primary key,
name varchar2(20)
@thinkerbot
thinkerbot / heuristics.txt
Created August 10, 2010 15:26
Heuristics from Clean Code
Ten particularly good heuristics for good code (from Clean Code).
E1. Build Requires More Than One Step
E2. Tests Require More Than One Step
G5. Duplication
G10. Vertical Separation
G21. Understand the Algorithm
N1. Choose Descriptive Names
T1. Insufficient Tests
T3. Don't Skip Trivial Tests
@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 :
@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 / 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 / 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 / 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 / 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 / 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 / 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