俺の胃の調子が悪いのがオフィスで飲みまくるコーヒーのカフェインのせいじゃないかと思い、ノンカフェインのルイボスティーをAmazonで買って飲んでました。

100個入りで1029円という恐るべきコストパフォーマンス。

今日、使い切ったので随分お気に入りで飲んだなーと思う一方、同じぐらいコーヒーを飲んでたのかと思うと恐ろしく思いました。

胃の調子は確かにマシになりましたが、他にも色々対策してたのでルイボスティーは関係ないかも。でも美味しいです。

Thread作りすぎにならないように10個ずつ送る。

threads = []
1000.times do
  threads << Thread.new { post_request(url, data) }

  if threads.size >= 10
    threads.each(&:join)
    threads.clear
  end
end

rubocopプラグインを入れたが下記のようなエラー。

ググって出て来るのはGemfileにrubocopを入れてないというエラーで俺の場合は違う。

https://gyazo.com/6640aec9d7216b15f5bcc1c296ca046b

ProcessNotCreatedException: Failed to run RuboCop command - is it installed? (SDK=/usr/local/var/rbenv/versions/2.3.1/bin): Cannot run program "rubocop" (in directory "/Users/komagata/dev/src/github.com/fjordllc/kowabana"): error=2, No such file or directory

.ktとい拡張子はkotlinかな?javaやkotlinのデバッグはやりたくないな。

RubyMineはしばらく置いておこう。

Failed to run RuboCop command - is it installed? (SDK=/usr/local/var/rbenv/versions/2.3.1/bin): Cannot run program "rubocop" (in directory "/Users/komagata/dev/src/github.com/fjordllc/kowabana"): error=2, No such file or directory
com.intellij.execution.process.ProcessNotCreatedException: Cannot run program "rubocop" (in directory "/Users/komagata/dev/src/github.com/fjordllc/kowabana"): error=2, No such file or directory
    at com.intellij.execution.configurations.GeneralCommandLine.createProcess(GeneralCommandLine.java:358)
    at org.jetbrains.plugins.ruby.ruby.run.RubyCommandLine.createProcess(RubyCommandLine.java:64)
    at io.github.sirlantis.rubymine.rubocop.RubocopTask$runViaCommandLine$1.invoke(RubocopTask.kt:173)
    at io.github.sirlantis.rubymine.rubocop.RubocopTask$runViaCommandLine$1.invoke(RubocopTask.kt:25)
    at io.github.sirlantis.rubymine.rubocop.RubocopTask.parseProcessOutput(RubocopTask.kt:67)
    at io.github.sirlantis.rubymine.rubocop.RubocopTask.runViaCommandLine(RubocopTask.kt:173)
    at io.github.sirlantis.rubymine.rubocop.RubocopTask.run(RubocopTask.kt:60)
    at io.github.sirlantis.rubymine.rubocop.RubocopAnnotator.doAnnotate(RubocopAnnotator.kt:157)
    at io.github.sirlantis.rubymine.rubocop.RubocopAnnotator.doAnnotate(RubocopAnnotator.kt:24)
    at com.intellij.codeInsight.daemon.impl.ExternalToolPass.b(ExternalToolPass.java:212)
    at com.intellij.codeInsight.daemon.impl.ExternalToolPass.access$500(ExternalToolPass.java:44)
    at com.intellij.codeInsight.daemon.impl.ExternalToolPass$1.run(ExternalToolPass.java:160)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:320)
    at com.intellij.util.ui.update.MergingUpdateQueue.execute(MergingUpdateQueue.java:310)
    at com.intellij.util.ui.update.MergingUpdateQueue.lambda$flush$1(MergingUpdateQueue.java:260)
    at com.intellij.util.ui.update.MergingUpdateQueue.flush(MergingUpdateQueue.java:274)
    at com.intellij.util.ui.update.MergingUpdateQueue.run(MergingUpdateQueue.java:229)
    at com.intellij.util.concurrency.QueueProcessor.runSafely(QueueProcessor.java:222)
    at com.intellij.util.Alarm$Request$1.run(Alarm.java:378)
    at com.intellij.util.Alarm$Request.run(Alarm.java:389)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at com.intellij.util.concurrency.SchedulingWrapper$MyScheduledFutureTask.run(SchedulingWrapper.java:227)
    at com.intellij.util.concurrency.BoundedTaskExecutor.runFirstTaskThenPollAndRunRest(BoundedTaskExecutor.java:178)
    at com.intellij.util.concurrency.BoundedTaskExecutor.access$000(BoundedTaskExecutor.java:40)
    at com.intellij.util.concurrency.BoundedTaskExecutor$2.run(BoundedTaskExecutor.java:197)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: Cannot run program "rubocop" (in directory "/Users/komagata/dev/src/github.com/fjordllc/kowabana"): error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at com.intellij.execution.configurations.GeneralCommandLine.startProcess(GeneralCommandLine.java:368)
    at com.intellij.execution.configurations.GeneralCommandLine.createProcess(GeneralCommandLine.java:354)
    ... 28 more
Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
    at java.lang.ProcessImpl.start(ProcessImpl.java:134)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
    ... 30 more

bsd-mailxってやつらしい。 ちょこっとローカルメールみるのにいいですよね。

$ sudo apt-get install bsd-mailx -y
$ mail
No mail for komagata

$BASH_SOURCEって変数が使えるらしい。

#!/bin/bash
BASE_DIR=$(dirname $BASH_SOURCE)
echo $BASE_DIR
$ ./path.sh
/Users/komagata/dev/src/github.com/fjordllc/kowabana

postgresでいうgenerate_series的なのは無いようなのでベタに書く。

SELECT * FROM
  (SELECT 1 as n),
  (SELECT 2 as n),
  (SELECT 3 as n),
  (SELECT 4 as n),
  (SELECT 5 as n),
  (SELECT 6 as n),
  (SELECT 7 as n),
  (SELECT 8 as n),
  (SELECT 9 as n),
  (SELECT 10 as n)

https://gyazo.com/c5222b1be7c9412d4ca285f9ebac360e

ホントにこれでいいのかな?

テーブル作成・データインポートは一気にできる。

$ bq load --source_format=CSV my_dataset.posts gs://my-bucket/posts.csv.gz "id:INTEGER,title:STRING,created_at:TIMESTAMP"
  • ローカルからアップしてのインポートは遅く、Cloud Storageからのインポートの方が断然速い。
  • gzip圧縮したCSVに対応してるので料金・速度の面からもやっといたほうがいい。
  • スキーマは引数で指定できる。
  • TIMESTAMPは色々なフォーマットをパースしてくれる。(今回はUNIXTIMESTAMP形式を読み込ませた。)Data Types  |  BigQuery Documentation  |  Google Cloud Platform

GCSへのアップは速いのに、BigQueryへの直接アップが遅いのはズルい。

スキーマを作る。

posts.json:

[
  {
     "name": "id",
     "type": "INTEGER"
  },
  {
     "name": "title",
     "type": "STRING"
  },
  {
     "name": "created_at",
     "type": "TIMESTAMP"
  }
]

テーブルを作る。

$ bq mk -t my_dataset.posts ./posts.json

https://gyazo.com/64ec12b4124fea7fbc2c7e003e87d047

便利じゃのう。

$ gsutil cp foo_*.csv gs://my-bucket-name/

便利ですね。

404などのページをassets pipelineを使って作れるgakubuchi gemを使っています。

capistranoでデプロイする時、これのassets:precompileで落ちてデプロイできてないことがよくある。(落ちないこともある)

もう一度デプロイすると動くので騙し騙し使っている。デバッグしないとなあ・・・。

Tasks: TOP => deploy:assets:precompile
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as root@app1.kowabana.jp: rake exit status: 1
rake stdout: I, [2016-09-16T10:01:36.563918 #30643]  INFO -- : Writing /srv/kowabana.jp/releases/20160916010102/public/assets/blocks-25f0ada07701275b817165481ea227bf448e4b33b160e18e4e4e5ff988e4ec06.css
I, [2016-09-16T10:01:36.565468 #30643]  INFO -- : Writing /srv/kowabana.jp/releases/20160916010102/public/assets/blocks-25f0ada07701275b817165481ea227bf448e4b33b160e18e4e4e5ff988e4ec06.css.gz
I, [2016-09-16T10:01:48.018613 #30643]  INFO -- : Writing /srv/kowabana.jp/releases/20160916010102/public/assets/application-ed4db3deeeed188beda19cdd3571fffe28eac2adfd49a4c948d14dee05076639.js
I, [2016-09-16T10:01:48.019534 #30643]  INFO -- : Writing /srv/kowabana.jp/releases/20160916010102/public/assets/application-ed4db3deeeed188beda19cdd3571fffe28eac2adfd49a4c948d14dee05076639.js.gz
I, [2016-09-16T10:01:56.640992 #30643]  INFO -- : Writing /srv/kowabana.jp/releases/20160916010102/public/assets/application-36e5ebe3ef6a536d04cf635d1343bbfb50cd9c2de9b70bec0d72b0469565bf1c.css
I, [2016-09-16T10:01:56.641414 #30643]  INFO -- : Writing /srv/kowabana.jp/releases/20160916010102/public/assets/application-36e5ebe3ef6a536d04cf635d1343bbfb50cd9c2de9b70bec0d72b0469565bf1c.css.gz
I, [2016-09-16T10:01:56.804354 #30643]  INFO -- : Writing /srv/kowabana.jp/releases/20160916010102/public/assets/404-f5b8eac98ade00d0f719281af5b7b9103e7403700bda2ea175fefb8fff1ccfc5.html
I, [2016-09-16T10:01:56.805071 #30643]  INFO -- : Writing /srv/kowabana.jp/releases/20160916010102/public/assets/404-f5b8eac98ade00d0f719281af5b7b9103e7403700bda2ea175fefb8fff1ccfc5.html.gz
I, [2016-09-16T10:01:56.848952 #30643]  INFO -- : Writing /srv/kowabana.jp/releases/20160916010102/public/assets/406-67bca5a0e35c21ad811db2b88cca0ea5537cf59d85269977c274cb94dee913aa.html
I, [2016-09-16T10:01:56.849368 #30643]  INFO -- : Writing /srv/kowabana.jp/releases/20160916010102/public/assets/406-67bca5a0e35c21ad811db2b88cca0ea5537cf59d85269977c274cb94dee913aa.html.gz
I, [2016-09-16T10:01:56.905607 #30643]  INFO -- : Writing /srv/kowabana.jp/releases/20160916010102/public/assets/422-ef00dd8611c3e3d04be35eb07806ac98bad01d2e91f1777e01f7bbc340849e49.html
I, [2016-09-16T10:01:56.906426 #30643]  INFO -- : Writing /srv/kowabana.jp/releases/20160916010102/public/assets/422-ef00dd8611c3e3d04be35eb07806ac98bad01d2e91f1777e01f7bbc340849e49.html.gz
I, [2016-09-16T10:01:56.962076 #30643]  INFO -- : Writing /srv/kowabana.jp/releases/20160916010102/public/assets/500-cf3665c336cdd9870de6ce60459b74d0d4280ac369f48ef590922fbac639673e.html
I, [2016-09-16T10:01:56.962528 #30643]  INFO -- : Writing /srv/kowabana.jp/releases/20160916010102/public/assets/500-cf3665c336cdd9870de6ce60459b74d0d4280ac369f48ef590922fbac639673e.html.gz
rake aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - /srv/kowabana.jp/releases/20160916010102/public/assets/406-1a8f57ba17cdbf23ab495f461eea0f1e844b30e0789aab4c933385017f437c27.html
/srv/kowabana.jp/shared/bundle/ruby/2.3.0/gems/gakubuchi-1.2.2/lib/gakubuchi/fileutils.rb:8:in `copy_p'
/srv/kowabana.jp/shared/bundle/ruby/2.3.0/gems/gakubuchi-1.2.2/lib/gakubuchi/task.rb:15:in `block in execute!'
/srv/kowabana.jp/shared/bundle/ruby/2.3.0/gems/gakubuchi-1.2.2/lib/gakubuchi/task.rb:10:in `each'
/srv/kowabana.jp/shared/bundle/ruby/2.3.0/gems/gakubuchi-1.2.2/lib/gakubuchi/task.rb:10:in `execute!'
/srv/kowabana.jp/shared/bundle/ruby/2.3.0/gems/gakubuchi-1.2.2/lib/tasks/after_precompile.rake:3:in `block in <top (required)>'
/srv/kowabana.jp/shared/bundle/ruby/2.3.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'
/usr/local/rbenv/versions/2.3.1/bin/bundle:23:in `load'
/usr/local/rbenv/versions/2.3.1/bin/bundle:23:in `<main>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
rake stderr: Nothing written


** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:


 DEBUG [3390349e]   I, [2016-09-16T10:01:56.905607 #30643]  INFO -- : Writing /srv/kowabana.jp/releases/20160916010102/public/assets/422-ef00dd8611c3e3d04be35eb07806ac98bad01d2e91f1777e01f7bbc340849e49.html

 DEBUG [3390349e]   

 DEBUG [3390349e]   I, [2016-09-16T10:01:56.906426 #30643]  INFO -- : Writing /srv/kowabana.jp/releases/20160916010102/public/assets/422-ef00dd8611c3e3d04be35eb07806ac98bad01d2e91f1777e01f7bbc340849e49.html.gz

 DEBUG [3390349e]   

 DEBUG [3390349e]   I, [2016-09-16T10:01:56.962076 #30643]  INFO -- : Writing /srv/kowabana.jp/releases/20160916010102/public/assets/500-cf3665c336cdd9870de6ce60459b74d0d4280ac369f48ef590922fbac639673e.html

 DEBUG [3390349e]   

 DEBUG [3390349e]   I, [2016-09-16T10:01:56.962528 #30643]  INFO -- : Writing /srv/kowabana.jp/releases/20160916010102/public/assets/500-cf3665c336cdd9870de6ce60459b74d0d4280ac369f48ef590922fbac639673e.html.gz

 DEBUG [3390349e]   

 DEBUG [3390349e]   rake aborted!

Errno::ENOENT: No such file or directory @ rb_sysopen - /srv/kowabana.jp/releases/20160916010102/public/assets/406-1a8f57ba17cdbf23ab495f461eea0f1e844b30e0789aab4c933385017f437c27.html

/srv/kowabana.jp/shared/bundle/ruby/2.3.0/gems/gakubuchi-1.2.2/lib/gakubuchi/fileutils.rb:8:in `copy_p'

/srv/kowabana.jp/shared/bundle/ruby/2.3.0/gems/gakubuchi-1.2.2/lib/gakubuchi/task.rb:15:in `block in execute!'

/srv/kowabana.jp/shared/bundle/ruby/2.3.0/gems/gakubuchi-1.2.2/lib/gakubuchi/task.rb:10:in `each'

/srv/kowabana.jp/shared/bundle/ruby/2.3.0/gems/gakubuchi-1.2.2/lib/gakubuchi/task.rb:10:in `execute!'

/srv/kowabana.jp/shared/bundle/ruby/2.3.0/gems/gakubuchi-1.2.2/lib/tasks/after_precompile.rake:3:in `block in <top (required)>'

/srv/kowabana.jp/shared/bundle/ruby/2.3.0/gems/rake-11.2.2/exe/rake:27:in `<top (required)>'

/usr/local/rbenv/versions/2.3.1/bin/bundle:23:in `load'

/usr/local/rbenv/versions/2.3.1/bin/bundle:23:in `<main>'

Tasks: TOP => assets:precompile

(See full trace by running task with --trace)