Skip to content

Instantly share code, notes, and snippets.

@kaichen
kaichen / gist:1247010
Created September 28, 2011 04:46
Odd behavior here.
‹ruby-1.9.3@devel› $ irb
ruby-1.9.3-preview1 :001 > YAML
=> YAML
ruby-1.9.3-preview1 :002 > YAML.method(:load)
=> #<Method: Module(Kernel)#load>
ruby-1.9.3-preview1 :003 > YAML.load "--- hello world!"
NoMethodError: private method `load' called for YAML:Module
from (irb):3
from /Users/kaichen/.rvm/rubies/ruby-1.9.3-preview1/bin/irb:16:in `<main>'
ruby-1.9.3-preview1 :004 > require 'yaml'
@kaichen
kaichen / adjust-volume.scpt
Created September 25, 2011 08:43
A applescript file for adjusting volume
#!/usr/bin/osascript
# Get this from http://blog.xupeng.me/2011/09/23/precisely-adjust-volume-in-lion/
# with one fix
on usage()
set _usage to "Usage: adjust-volume number\n"
set _usage to _usage & "For example:\n"
set _usage to _usage & " adjust-volume 2\t - increase volume by 2\n"
set _usage to _usage & " adjust-volume -2\t - decrease volume by 2"
return _usage
require "rubygems"
require "active_record"
require "squeel"
n = 5000
conn = { :adapter => 'sqlite3', :database => ':memory:' }
ActiveRecord::Base.establish_connection(conn)
class User < ActiveRecord::Base
window.Utils = class Utils
@className: (obj)->
regex = /^function\s*([^\(]+)/
fnSource = obj.constructor.toString()
regex.exec(fnSource)[1]
@underscore: (word) ->
hanlder = (str, p, offset, s) ->
l = p.toLowerCase()
if offset == 0 then l else "_#{l}"
@kaichen
kaichen / dummy.coffee
Created July 1, 2011 14:43
js function wtf
foobar = (x) -> not_exist
foobar(1)
@kaichen
kaichen / sample.html
Created July 1, 2011 06:58
html5 video sample w/ jquery.tmpl
<!doctype html>
<html>
<head>
<title>Html5 video with jq.tmpl sample</title>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script>
<script type="text/javascript">
$(document).ready(function () {
@kaichen
kaichen / kaichen.zsh-theme
Created June 28, 2011 09:11
My zsh theme
local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
local current_dir='%{$terminfo[bold]$fg[blue]%} %~%{$reset_color%}'
local current_path='%{$terminfo[bold]$fg[blue]%}%c%{$reset_color%}'
local rvm_ruby='%{$fg[red]%}‹$(rvm-prompt i v g)›%{$reset_color%}'
local git_branch='$(git_prompt_info)%{$reset_color%}'
local current_time='%{$fg[yellow]%}%D{[%I:%M:%S]}%{$reset_color%}'
local arrow="%{$fg_bold[red]%}$%{$reset_color%}"
PROMPT="${current_dir} ${git_branch}${arrow} "
@kaichen
kaichen / config.ru
Created June 27, 2011 08:04
config.ru with sass autocompile support
require 'sass/plugin/rack'
Sass::Plugin.options.merge!(:css_location => "./path/to/stylesheets")
use Sass::Plugin::Rack
run Rack::Directory.new(".")
@kaichen
kaichen / rails.zsh
Created March 19, 2011 12:00
a function for rails 2 & 3 via rails 3 cli interface
org_rails_cmd=`which rails`
function rails {
if [ $# -eq 0 ];then
$org_rails_cmd
elif [ -e script/rails ]; then
./script/rails $@
elif [ $1 = 'c' ];then
shift
./script/console $@
// try ruby-like mixin in javascript
function mixin(object, name, fn) {
var orignal = object[name];
object[name] = function() {
try {
this.super = orignal;
return fn.apply(this, arguments);
} finally {