Skip to content

Instantly share code, notes, and snippets.

% vi Thorfile
...
desc "console ENV", "Start Monk console in the supplied environment"
def console(env = ENV["RACK_ENV"] || "development")
verify_config(env)
exec "env RACK_ENV=#{env} irb -r init -Ku"
end
...
% thor monk:console
# sinatra syntax is cool!
get "/users/:id" do
@user = User.find(params[:id])
haml :user
end
# become ugly when error handling is added
get "/users/:id" do
#!/usr/bin/ruby
require 'rubygems'
require 'rbench'
require 'find'
def glob(dir)
hash = {}
Dir.glob("#{dir}/**/*.rb") do |f|
hash[f] = File.mtime(f) rescue next
# current
class App < Thor
desc "install APP_NAME", "Install one of ..."
def install(name)
...
# The first arg of desc is too redundant
# Because it can automatically be reflected in src like merb_args.
# Then we can get following code. Cool!
# example for usage-completions
# using http://github.com/maiha/thor/
# compare: http://github.com/maiha/thor/tree/complete-usage
class Rails < Thor
desc "Open console via irb"
def console(env = 'development')
system("ruby script/console #{env}")
end
end
# kyotocabinet: 0.9.9
# kyotocabinet-ruby: 1.1
# integer with ファイルハッシュDB
KyotoCabinet::DB.process('casket.kch'){|db|
db['foo'] = 1
p db['foo']
# => "1"
}
% echo $PATH
/data/apps/maglev/bin:/home/maiha/bin:/usr/local/bin:/usr/bin:/bin
% echo $MAGLEV_HOME
/data/apps/maglev
% cd $MAGLEV_HOME
/data/apps/maglev% rake maglev:start
startstone[Info]: Starting Stone repository monitor "maglev".
% irb -r rubygems -r manga_helpers
irb(main):001:0> MangaHelpers.titles.naruto.chapters.latest.download.url
=> "http://media5.mangahelpers.com/download/manga-releases/a110..."
.
|-- app
| |-- controllers
| | `-- Application.scala
| |-- models
| `-- views
| |-- Application
| | `-- index.html
| |-- errors
| | |-- 404.html
/*
「sealedの存在意義」とされている理由
1. パターンマッチでの被覆性(網羅性)を保証したい
2. ML はコンパイラで検出できる
3. Scala ではできない (型推論が弱い、と言われる理由もここ?)
4. sealed をつけると検出できるようにした
*/
// 例 # via http://d.hatena.ne.jp/kmizushima/20091229/1262091617