2014年8月7日木曜日

アメリカに行くならモバイルルータ(Wifi)よりもSIMフリーAndroid端末がおトク!?

アメリカ(ハワイ)にnexus7(2013 lte)持って行ったら大活躍した。

もしモバイルルータをレンタルしようと思ったら一日千円近くかかるのでもったいないと思い、SIMフリー端末代でテザリングすることにした。
カーナビ代わりにも使えるので、カーナビもレンタルすると一日10ドルぐらいすること考えると二度おいしい。

現地でのSIMカード調達は、t-mobile一択じゃないか?と思う。
  • Verizonに行ったらSIMカード単体では売っていないらしい。。。
  • at&tには行ってないけど、goPhoneと言うプランでSIMカード単体でも売っているがテザリングが出来ないと言う情報を目にしたので避けた。

t-mobileでは、SIMカード自体が$10、3GBまでのlteが30日間有効なプランで$30の合計$40だった。

t-mobileのお店の人にAndroid端末を見せ、プリペイドSIMカードプリーズ。で行けると思う。
言語設定を英語に変更したうえでお店の人に渡せば、あとはやってくれる。

途中で、プランをどうするか、4ケタの暗証番号、誕生日等を聞かれた。
あ、SIMカードトレーを取り出す器具(pinと呼んでいた)を持っているかも聞かれた。

Android (nexus7) でwifiに繋がらない、SSIDが見つからない場合の対処方法

原因は、無線LANのチャンネルにnexus7(android 4.4.3)が対応していないためっぽい。

無線LAN側のチャンネルが12か13だとSSIDが検出されず、WPSでも接続できない模様。

チャンネルを11に固定したところ問題なく接続できるようになった。

良かった。。。

2014年7月1日火曜日

Google Chromeで横幅があまり縮められない場合の対処法

Google Chromeを使ってレスポンシブWebデザインの確認をしようとしていると、ブラウザの横幅が思ったより縮まらなくて困ることがある。

●原因
・オムニバー(URL入力欄)の右側に並んでいる拡張機能のボタンが多い。
 (オムニバーはある一定以下の横幅に縮められないようになっている)

●対策
案1:不要な拡張機能を削除する
案2:オムニバーと拡張の間を右にドラッグし、表示される拡張ボタン数を減らす

2014年5月23日金曜日

Selenium webdriver: chromeで全画面をキャプチャする方法

見えている範囲だけをキャプチャすることはできたので、多少強引だが
  1. Javascriptを使って見えてる範囲の高さと画面全体の高さを取得
  2. スクロールしながらキャプチャ
  3. 最後の一枚のみ重複ができるのでImageMagickを使ってカット
  4. ImageMagickを使って全ての画像を結合
という流れで全体のキャプチャを実現出来た。
以下rubyの場合。
def chrome_capture(webdriver, fname_prefix)
  #1. Javascriptで画面のサイズを取得
  inner_h = webdriver.execute_script("return window.innerHeight").to_i
  scroll_h = webdriver.execute_script("return document.documentElement.scrollHeight").to_i

  repeat = (scroll_h.to_f/inner_h.to_f).ceil
  dupl_h = inner_h - (scroll_h % inner_h)

  tmp_fnames = []
  tmp_basename = fname_prefix

  #2. スクロールしながらキャプチャ
  repeat.times{|i|
    tmp_fnames << tmp_fname = tmp_basename + sprintf("%06d",i) + ".png"
    webdriver.save_screenshot(tmp_fname)
    sleep (0.3)
    webdriver.execute_script("window.scrollBy(0,#{inner_h})");
    sleep (0.3)
  }

  if tmp_fnames.length > 1
    #一時ファイルが2つ以上の場合
    #3. 最後の一枚のみ重複ができるのでImageMagickを使ってカット
    if dupl_h > 0
      `convert -chop 0x#{dupl_h} #{tmp_fnames.last} #{tmp_fnames.last}`
    end
    #4. ImageMagickを使って全ての画像を結合
    `convert -append #{tmp_fnames.join(' ')} #{tmp_basename}.png`
    File.unlink *tmp_fnames
  else
    #1つの場合は一時ファイルをリネームするだけ
    File.rename(tmp_fnames[0],"#{tmp_basename}.png")
  end

end

ちなみにMacのSafari、Chromeでも同様の方法でいけるが、Retinaの場合は重複カットする際のピクセル数を2倍(正確には、JavascriptのdevicePixelRatioで取得可能な値倍)にする必要があるため要注意。

2014年4月22日火曜日

Vagrantで楽々開発環境構築(失敗)

遅まきながらVagrantに挑戦してみた。
参考文献↓
VagrantでRails開発環境を整備 (CentOS 6.5/Nginx/mysql5.6/rbenv/ruby2.1.0) - 酒と泪とRubyとRailsと
http://morizyun.github.io/blog/vagrant-centos-nginx-mysql-rbenv/
Winodows環境で試したが、
bundle exec berks install --path site-cookbooks
を実行した際に以下のエラーが表示されたため、下記の対応を実施後、Berksfileを下記の通り修正した
エラーメッセージ↓
>bundle exec berks install --path site-cookbooks
Using mysql (4.1.2)
Using database (2.0.0)
Using nginx (2.4.4)
Using base (0.1.0) at './site-cookbooks/base'
Using mysql56 (0.1.0) at './site-cookbooks/mysql56'
Using ruby_build (0.8.0)
Failed to download 'rbenv' from github: 'fnichol/chef-rbenv' with branch: 'master' over protocol: 'git'
Cookbook 'rbenv' not found in any of the default locations
下記コマンド実行↓
>cd site-cookbooks
>git clone https://github.com/fnichol/chef-rbenv.git
>cd ..
Berksfile変更前↓
site :opscode
cookbook 'mysql'
cookbook 'database'
cookbook 'nginx', path: 'site-cookbooks/nginx'
cookbook 'base', path: 'site-cookbooks/base'
cookbook 'mysql56', path: 'site-cookbooks/mysql56'
cookbook 'ruby_build', github: 'fnichol/chef-ruby_build'
cookbook 'rbenv',  github: 'fnichol/chef-rbenv'
cookbook 'ruby_gem', path: 'site-cookbooks/ruby_gem'
Breksfile変更↓(rbenvをpathに変更)
site :opscode
cookbook 'mysql'
cookbook 'database'
cookbook 'nginx', path: 'site-cookbooks/nginx'
cookbook 'base', path: 'site-cookbooks/base'
cookbook 'mysql56', path: 'site-cookbooks/mysql56'
cookbook 'ruby_build', github: 'fnichol/chef-ruby_build'
cookbook 'rbenv',  path: 'site-cookbooks/chef-rbenv'
cookbook 'ruby_gem', path: 'site-cookbooks/ruby_gem'
と思ったら、なんだかエラーが出て失敗した。
今日はここまでにしておこう。。。
エラーメッセージ↓
[2014-04-22T13:20:41+00:00] DEBUG: Re-raising exception: Chef::Exceptions::CookbookNotFound - Cookbook base not found. If you're loading base from another cookbook, make sure you configure the dependency in your metadata
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/cookbook/cookbook_collection.rb:38:in `block in initialize'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ohai-7.0.2/lib/ohai/mash.rb:77:in`yield'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ohai-7.0.2/lib/ohai/mash.rb:77:in`default'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ohai-7.0.2/lib/ohai/mash.rb:77:in`default'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/run_context/cookbook_compiler.rb:277:in `[]'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/run_context/cookbook_compiler.rb:277:in `each_cookbook_dep'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/run_context/cookbook_compiler.rb:255:in `add_cookbook_with_deps'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/run_context/cookbook_compiler.rb:88:in `block in cookbook_order'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/run_context/cookbook_compiler.rb:86:in `each'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/run_context/cookbook_compiler.rb:86:in `cookbook_order'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/run_context/cookbook_compiler.rb:98:in `compile_libraries'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/run_context/cookbook_compiler.rb:71:in `compile'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/run_context.rb:88:in `load'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/policy_builder/expand_node_object.rb:73:in `setup_run_context'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/client.rb:265:in `setup_run_context'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/client.rb:429:in `do_run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/client.rb:213:in `block in run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/client.rb:207:in `fork'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/client.rb:207:in `run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/application.rb:217:in `run_chef_client'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/application/solo.rb:221:in `block in run_application'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/application/solo.rb:213:in `loop'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/application/solo.rb:213:in `run_application'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/application.rb:67:in `run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/bin/chef-solo:25:in `<top (required)>'
/usr/bin/chef-solo:23:in `load'
/usr/bin/chef-solo:23:in `<main>'
[2014-04-22T13:20:41+00:00] ERROR: Running exception handlers
[2014-04-22T13:20:41+00:00] ERROR: Exception handlers complete
[2014-04-22T13:20:41+00:00] FATAL: Stacktrace dumped to /var/chef/cache/chef-stacktrace.out
[2014-04-22T13:20:41+00:00] DEBUG: Chef::Exceptions::CookbookNotFound: Cookbookbase not found. If you're loading base from another cookbook, make sure you configure the dependency in your metadata
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/cookbook/cookbook_collection.rb:38:in `block in initialize'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ohai-7.0.2/lib/ohai/mash.rb:77:in `yield'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ohai-7.0.2/lib/ohai/mash.rb:77:in `default'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/ohai-7.0.2/lib/ohai/mash.rb:77:in `default'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/run_context/cookbook_compiler.rb:277:in `[]'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/run_context/cookbook_compiler.rb:277:in `each_cookbook_dep'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/run_context/cookbook_compiler.rb:255:in `add_cookbook_with_deps'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/run_context/cookbook_compiler.rb:88:in `block in cookbook_order'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/run_context/cookbook_compiler.rb:86:in `each'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/run_context/cookbook_compiler.rb:86:in `cookbook_order'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/run_context/cookbook_compiler.rb:98:in `compile_libraries'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/run_context/cookbook_compiler.rb:71:in `compile'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/run_context.rb:88:in `load'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/policy_builder/expand_node_object.rb:73:in `setup_run_context'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/client.rb:265:in `setup_run_context'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/client.rb:429:in `do_run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/client.rb:213:in `block in run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/client.rb:207:in `fork'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/client.rb:207:in `run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/application.rb:217:in `run_chef_client'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/application/solo.rb:221:in `block in run_application'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/application/solo.rb:213:in `loop'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/application/solo.rb:213:in `run_application'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/lib/chef/application.rb:67:in `run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.12.2/bin/chef-solo:25:in `<top (required)>'
/usr/bin/chef-solo:23:in `load'
/usr/bin/chef-solo:23:in `<main>'
[2014-04-22T13:20:41+00:00] ERROR: Cookbook base not found. If you're loading base from another cookbook, make sure you configure the dependency in your metadata
[2014-04-22T13:20:41+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
Chef never successfully completed! Any errors should be visible in the output above. Please fix your recipes so that they properly complete.

2014年4月14日月曜日

WindowsでSublime TextのRubyTestの実行に失敗する場合の対処法

Windows環境でRailsTutorialに沿って進めていたら3.6.4 Tests inside Sublime Textで躓きました。

Build Consoleに下記が表示されていました。

[Decode error - output not utf-8]
[Finished in 0.1s with exit code 1]
[cmd: [' bundle exec rspec spec\\requests\\static_pages_spec.rb -l50']]
[dir: C:\***\sample_app]
[path: C:****;]

いろいろ試行錯誤した結果、run_ryby_test.pyの下記(201行目あたり)を修正することで、何とか実行できるっぽい?ことが判明。

self.view.window().run_command("exec", {
"cmd": [command],
"shell": True,
"working_dir": working_dir,
"file_regex": r"([^ ]*\.rb):?(\d*)"
})

self.view.window().run_command("exec", {
"cmd": command, # ←[]除去
"shell": True,
"working_dir": working_dir,
"file_regex": r"([^ ]*\.rb):?(\d*)"
})

#最初はメッセージに「Decode error」と表示されていたから
エンコードの問題かと思って下記のようにしてみたのですが、

self.view.window().run_command("exec", {
"cmd": [command],
"shell": True,
"working_dir": working_dir,
"file_regex": r"([^ ]*\.rb):?(\d*)",
"encoding": "cp932"
})

こうすると、コンソールに「指定されたパスが見つかりません。」と出たので、
commandが間違っているようだとわかりました。

ちなみに、Windows環境でListing 3-34は「# gem 'win32console', '1.3.2'」のコメントアウトをはずすとエラーになるっぽいです。Ruby2.0では、Win32consoleは必要ないみたいです。

#参考:Error “cannot load such file — 2.0/Console_ext” running unit tests in RubyMine

#この問題は一応本家のrailstutorialに報告してみたので、もしかしたらそのうち修正されているかもしれません。

2014年4月7日月曜日

namazuに代わるサイト内全文検索ツールを模索中

あまりしっくりくるものが見つからない。 fessはどうだろうか。 専用サーバーを用意しないと重いかな。そうすると冗長化とかややこしいな。。 elasticsearchとかsolr+nutch?はどうなんだろうか。かなり作り込みが必要になりそうで気が引けるなぁ。