redis-commander

ローカルで開発しているときに、複数のredis-serverを立ち上げるので、たとえばsessionのテストでkeyを削除したくなったり、 アプリのデータを入れたくなったりしたときに、redis-cliで「どのプロセスに繋げばいいだっけ」ということが多々ある。

redis-commanderはブラウザで経由でredis-serverを管理してくれる。 http://nearinfinity.github.io/redis-commander/

$ npm install -g redis-commander
$ redis-commander

便利。

thinのコードネーム

が、rails serverするたびに目に入るので気になって一覧にしてみた。

$ git log -p lib/thin/version.rb | grep '\+\s*CODENAME' | awk 'match($0,/[\047"](.*)[\047"]/) { print substr($0,RSTART,RLENGTH) }'
"Straight Razor"
"Knife"
"Chromeo"
"Low-bar Squat"
"Triple Espresso"
"Double Espresso"
"Bat-Shit Crazy"
"I'm dumb"
"Black Keys Extra Plus Wow"
"Black Keys"
"Does It Offend You, Yeah?"
"No Hup"
"Crazy Delicious"
"This Is Not A Web Server"
"Flaming Astroboy"
"Astroboy"
"I Find Your Lack of Sauce Disturbing"
"Asynctilicious Ultra Supreme"
"Asynctilicious Supreme"
"Super Disco Power Plus"
"Super Disco Power"
"?"
"That's What She Said"
'The Big'
'Double Margarita'
'Rebel Porpoise'
'Dodgy Dentist'
'No Name Yet'
'Fancy Pants'
'Spherical Cow'
'Ninja Cookie'
'Rambo'
'Cheesecake'
'Big Pony'
'Bionic Pickle'
'Pony'
'Flying Mustard'
'Purple Yogurt'
'Cheezburger'
'LOLCAT'
'lolcat'

awkでシングルクォートをマッチさせるのが死にそうになった。

Amazonで配送先住所を間違って発注してしまった場合

def 住所変更可能か?
  状況 == "未発送"
end

def 配送先住所をwebから変更する(住所)
  変更する 住所
end

def 配達センターに電話する(配送会社電話番号, 伝票番号, 住所)
  電話する 配送会社電話番号, 伝票番号, 住所, "「配送先を間違えたので住所変更お願いします」"
end

def main
  if 住所変更可能か?
    begin
      配送先住所をwebから変更する(住所)
    rescue => 変更不可エラー
      # 落ち着く
      配達センターに電話する(配送会社の電話番号と伝票番号をメールから調べる, 住所)
    end
  else
    配達センターに電話する(配送会社の電話番号と伝票番号をメールから調べる, 住所)
  end
end

Enumerable#entries

にはまったというお話。

class Hash
  def method_missing(method, *args)
    ret = self[method] || self[method.to_s]
    return ret if ret
    super
  end
end

h = {root: {hoge: 1, foo: 2}, entries: [{hoge: 3, foo: 4}, {hoge: 5, foo: 6}]}
h.entries
#=> [[root: {hoge: 1, foo: 2}, entries: [{hoge: 3, foo: 4}, {hoge: 5, foo: 6}]]]

to_aだけでいいのでは、と思った。Rubyはよくaliasが提供されてるけど不要なんじゃないかと思う時もある。 や、今回のは不用意にmethod_missing使うなとか、ドキュメント嫁という話ではあるのだけれども...

免責条項

たまに「私は経験が浅く〜この記事の内容には間違いがあるかもしれません〜」という書き出しがある記事をみかけるのは、日本人の文化なのかなと思っていたら、英語圏の人もそういう文化があるんだ。

Disclaimer: This is my first blog post on frontend web application development, and the content might sound very opinionated and prone to mistakes. http://fleon.org/post/47401547699/why-i-love-ember-js

RubyやRailsの情報収集

勉強会で話していて3回くらい「どこからRubyRailsの情報を仕入れてますか」のような質問をされたので、 自分はどうやって情報収集してるんだろうとふと考えてみると、

あたりかなぁと。 あ、あとgemは毎日githubで言語毎にstar数が急上昇してるやつとか見れるので眺めて「そんなgemあるんだ」みたいな感じ。