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
#!/bin/zsh | |
for b in `git branch -r | grep "^ origin" | cut -c 10- | fgrep -v HEAD | grep -v master`; do | |
git checkout -t origin/${b} | |
done |
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
git :init | |
git :add => '.' | |
git :commit => "-m 'Initial commit'" | |
remove_file 'public/index.html' | |
git :add => 'public' | |
git :commit => "-a -m 'rm public/index.html'" | |
generate :model, 'user name' | |
generate :model, 'recipe title user:references' |
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
class Hash | |
def try(*a, &b) | |
if (a.size == 1) && a.first.is_a?(Array) && (a.first.size == 1) | |
self.fetch a.first.first | |
else | |
super | |
end | |
end | |
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
SRC_DIR = '/Users/a_matsuda/Music/iTunes/iTunes Media/Music' | |
TARGET_DIR = '/Users/a_matsuda/Bitcasa/backup/Music/iTunes/iTunes Media/Music' | |
def cache_is_empty? | |
s = `du -s ~/Library/Caches/com.bitcasa.Bitcasa/Data/bks/outgoing | awk '{print $1}'` | |
s.to_i.zero? | |
end | |
def already_copied?(artist) | |
File.exists? "#{TARGET_DIR}/#{artist}" |
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
ruby-1.9.3-p0> Benchmark.ms { 100000.times { 'a-b-c-d-e'.gsub /-/, '_' } } | |
=> 422.281 | |
ruby-1.9.3-p0> Benchmark.ms { 100000.times { 'a-b-c-d-e'.gsub '-', '_' } } | |
=> 471.096 |
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 'open-uri' | |
class Http | |
def self./(url) | |
open("http://#{url}").read | |
end | |
end | |
class String | |
def com | |
self + '.com' |
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
# put this function in your .zshrc | |
function v() {vim ${${=*/:/ +}/:*}} |
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
% rspec spec/models/user_spec.rb | |
.F.F. | |
Failures: | |
1) User | |
Failure/Error: it { should query :where => {:name => 'bar'} } | |
expected [:where] to query {:where=>{:name=>"bar"}} | |
# ./spec/models/user_spec.rb:6 |
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 'tempfile' | |
t1 = Tempfile.new 'foo.txt' | |
t2 = t1.dup | |
t1 = nil | |
GC.start | |
p File.exists?(t2.path) | |
p t2.read |
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
% rails -v | |
Rails 3.1.0.beta1 | |
% ls app/models | |
user.rb | |
% rails g scaffold user name:string -s | |
invoke active_record | |
create db/migrate/20110507060923_create_users.rb | |
skip app/models/user.rb |