params.each do |key, value| self.instance_variable_set("@#{key}", value) self.class.send(:define_method, key, proc { self.instance_valiable_get("@#{key}") }) end
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find ./app/views/comments/ -name '*erb' | \ | |
xargs ruby -e 'ARGV.each { |i| puts "html2haml -r #{i} #{i.sub(/erb$/,"haml")}"}' | \ | |
bash |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Don't you ever use this on production environment | |
rake db:migrate:reset db:seed db:test:clone --trace |
Delete all your CouchDB databases:
rm -Rf /usr/local/var/lib/couchdb/*
URL to browse CouchDB databases: 127.0.0.1:5984/_utils
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'fileutils' | |
def fail!(msg = "Failure!") | |
puts(msg) | |
exit(1) | |
end | |
REPOSITORY_URL = 'git://github.com/mexpolk/homebrew.git' | |
PACKAGE_URL = 'http://github.com/mexpolk/homebrew/tarball/master' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rebase | |
$ git commit -a -m "Commit message" | |
$ git fetch | |
$ git rebase [branch] # origin/master | |
$ git push | |
# Stash | |
$ git stash | |
$ git pull | |
$ git stash apply |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Random chars | |
chars = ('a'..'z').to_a + ('A'..'Z').to_a | |
(0...10).collect { chars[Kernel.rand(chars.length)] }.join | |
=> "nmhhuMrybz" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
puts Benchmark.measure { "a"*1_000_000 } | |
0.060000 0.000000 0.060000 ( 0.067556) | |
=> nil | |
n = 50000 | |
Benchmark.bm do |x| | |
x.report { for i in 1..n; a = "1"; end } | |
x.report { n.times do ; a = "1"; end } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# = Mixin Template | |
# == Usage | |
# ActionController::Base.send :include, MixinModuleName | |
module MixinModuleName | |
def self.included(recipient) | |
recipient.extend(ClassMethods) | |
recipient.class_eval do | |
include InstanceMethods |