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
| % 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 |
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
| # 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 |
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/ruby | |
| require 'rubygems' | |
| require 'rbench' | |
| require 'find' | |
| def glob(dir) | |
| hash = {} | |
| Dir.glob("#{dir}/**/*.rb") do |f| | |
| hash[f] = File.mtime(f) rescue next |
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
| # 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! |
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
| # 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 |
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
| # kyotocabinet: 0.9.9 | |
| # kyotocabinet-ruby: 1.1 | |
| # integer with ファイルハッシュDB | |
| KyotoCabinet::DB.process('casket.kch'){|db| | |
| db['foo'] = 1 | |
| p db['foo'] | |
| # => "1" | |
| } |
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
| % 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". |
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
| % 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..." |
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
| . | |
| |-- app | |
| | |-- controllers | |
| | | `-- Application.scala | |
| | |-- models | |
| | `-- views | |
| | |-- Application | |
| | | `-- index.html | |
| | |-- errors | |
| | | |-- 404.html |
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
| /* | |
| 「sealedの存在意義」とされている理由 | |
| 1. パターンマッチでの被覆性(網羅性)を保証したい | |
| 2. ML はコンパイラで検出できる | |
| 3. Scala ではできない (型推論が弱い、と言われる理由もここ?) | |
| 4. sealed をつけると検出できるようにした | |
| */ | |
| // 例 # via http://d.hatena.ne.jp/kmizushima/20091229/1262091617 |