uoz 作業日記

様々な作業の記録を共有するブログです。

usb type-c の 電源ケーブル予備をかったよ | mac book pro 2016 touch bar

前のmacbook pro 15インチ(mid 2015)が壊れたから、新しいmacbook proを買ったよ。

13インチタッチバー付きで、SSD256GBのやつ。
それにともなっていろいろ買い物をしたので、久しぶりにアフィ記事を書く。

秋葉原のヨドバシに行ったら売り切れてて、1週間くらい待つという話だったので、ソフマップに行ったら普通に在庫があった。
仕事のためすぐ欲しかったのでそれを買った。

前は家用と持ち運び用で、電源のアダプタを2つ使っていたんだけど、
新しいmacbook proは端子がUSB type-cに統一されてしまったので、
予備用のACアダプタを買い直した。

続きを読む

kuroko2つかおう

手順

rails new my_kuroko2 --database=mysql --skip-turbolinks --skip-javascript -m https://raw.githubusercontent.com/cookpad/kuroko2/master/app_template.rb

このテンプレートのままだとなんか失敗

手動で

bundle install 

これも失敗

Bundler could not find compatible versions for gem "rails":
  In Gemfile:
    rails (= 4.2.6)

    kuroko2 was resolved to 0.2.0, which depends on
      rails (>= 5.0.0.1)

gemfileを編集してrailsを5にした

$ bundle exec rake db:create
$  bundle exec rake db:migrate

動かすにはforemanってのが必要らしい

$ gem install foreman

その後、

$ foreman start

動かねえ

template.rbが途中でコケてるせいて、koruko2のマイグレーションが実行されてないせいだ
https://raw.githubusercontent.com/cookpad/kuroko2/master/app_template.rb
を見て、

$ bundle exec rake 'kuroko2:install:migrations’
$ bundle exec rake db:migrate
$ foreman start

略  .rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/thor-0.19.3/lib/thor/base.rb:534:in `thor_reserved_word?': "run" is a Thor reserved word and cannot be defined as command (RuntimeError)

こんな感じで動かない

Gemfileにforemanいれてbundle execで動かしてみる

$ bundle exec foreman start

やっと立ち上がった

lcalhost:5000
がディフォルト

使ってみよう

Intellij Ideaでcakehp3のphpunitを動かす

webstormとかphpstormとか全部一緒だと思う。

下のstackoverflowに書いてあるやつの翻訳です.

1. Intellij の設定画面を開く

2. Languages & Frameworks > PHP を開く

3. Interpreter: でphpの実行ファイルを選ぶ
例えばosxMAMPだと
/Applications/MAMP/bin/php/php5.6.25/bin/php
とか

4. PHPUnitを選ぶ

5. PHPUnit Library 欄で、User Composer autoloaderを選んで、下の「Path to script」の右の欄にアプリディレクトリ内 vendor/autoload.phpへのパスを入れる

6. Test Runner 欄 で、「 Default configuration file」にチェックし、右のボックスに phpunit.xml.distのパスを入れる

!全部のパスは絶対パス


How to configure PhpStorm 10.x to run unit tests in CakePHP 3.x? - Stack Overflow

Without trying to solve your specific error, here's how I have configured PhpStorm.

In Languages & Frameworks > PHP

> Interpreter: Pointing to a local PHP executable
> PHPUnit > PHPUnit Library: Checked Use custom autoloader, pointing to vendor/autoload.php in the app folder.
> PHPUnit > Test Runner: Checked Default configuration file, pointing to phpunit.xml.dist in the app folder.

All paths should be absolute ones!

And that's all, running tests via the file/folder/code context menus Run ... command works just fine.

docker on mac を intelij から使いたい

blog.dekstroza.io


unixドメインソケットをtcpソケットとして使うためにsocatを使うという手法
qiita.com


homebrewでsocatをインストール

  $ brew install socat

その後socatを起動

  $ socat -d -d TCP-L:8099,fork UNIX:/var/run/docker.sock

intelijのdockerプラグインの設定開いて、
api URLに
tcp://localhost:8099
をいれる

OSXで使えるpostgresqlのGUIクライアント

f:id:uoz:20160815122511j:plain

最近使っている3種類の比較です。


ssh経由の接続などは皆できる。

pg commander

PG Commander, a PostgreSQL client for Mac

f:id:uoz:20160815223508j:plain

良い点

  • 無料板あり
  • テーブル構造が見られる

悪い点

  • インポート機能がない
  • テーブル構造が変えられない(2016-08-14時点)
  • フル機能版は¥5,800

psquel

http://www.psequel.com/
mysqlの有名クライアント、sequel proに影響を受けたクライアントソフト。

良い点

  • 完全無料
  • テーブル構造が見られる

悪い点

  • インポート機能がない
  • テーブル構造が変えられない(2016-08-14時点)

その他解説記事

postpico

Postico – a modern PostgreSQL client for the Mac

f:id:uoz:20160815223833j:plain

良い点

  • CSV等インポート機能有り
  • 無料版有り

悪い点

  • フル機能版は有料¥4,800

DockerMachineでGMOのクラウド仮想サーバを操れる

このアルタスのこと

パブリッククラウドならGMOクラウド ALTUS(アルタス) | 無料体験付き

参考

docker-machineのgenericプロバイダを使う - Qiita

サーバ

ubuntu14.04のイメージでミニサーバつくる。

セキュリティグループでポート443を空けないとダメらしい。

固定IPを割り当てる。

パスワード無しsudoできるユーザをつくる

公開鍵認証できるようにする。

~/.ssh/id_rsaにカギがあるとする。

参考

https://www.server-world.info/query?os=Ubuntu_14.04&p=initial_conf

http://jeromejaglale.com/doc/unix/ubuntu_sudo_without_password

ローカルで

docker-machine -D create  --driver generic  --generic-ip-address=xxx.xxx.xxx.xxx --generic-ssh-key ~/.ssh/id_rsa --generic-ssh-user ユーザ名 マシン名

centos7でもできるはずだが、私はできなかった。

# railsって遅いのかね

cake, rails, spring boot, expressで、ほとんど同じアプリを作ってざっくり試してみる

Jmeterで負荷をかけることに

Jmeterインストール

$ brew install jmeter --with-plugins
$ jmeter

f:id:uoz:20160702170840j:plain

1. Railsで最初にちょっと試してみる

Railsアプリをlocalhsot:3000で立てて...

rails 4.2.6 ruby 2.3.1 mysql 5.7.10

アプリ

こんなアプリ

f:id:uoz:20160702170936j:plain

/articles で記事+コメント一覧を表示する

コントローラ app/controllers/articles_controller.rb

class ArticlesController < ApplicationController
  def index
    @article = Article.includes(:comments).all
  end
end

ビュー app/views/articles/index.erb

<h1>test</h1>


<table>
  <tr>
    <th>
      タイトル
    </th>
    <th>
      内容
    </th>
    <th>
      更新日
    </th>
  </tr>
  <% @article.each do |article| %>
    <tr>
      <td>
        <%= article.name %>
      </td>
      <td>
        <%= article.content %>
        <% if article.comments.present? %>
            <br />コメント:
            <% article.comments.each do |comment| %>
                <br /><%= comment.content %>
            <% end %>
        <% end %>
      </td>
      <td>
        <%= article.updated_at %>
      </td>

    </tr>
  <% end%>
</table>

Alt text

テスト実施

このサイトの通り、パスだけアプリの/articlesに変えて

http://language-and-engineering.hatenablog.jp/entry/20081014/1223905380

左ペインの「テスト計画」を右クリックし,「追加」→「スレッドグループ」。

スレッド数: 50 Ramp-Up期間(秒): 10  (←スレッド立ち上げ期間のこと)

と入力。

左ペインの「スレッドグループ」を右クリックし,「追加」→「サンプラー」→「HTTPリクエスト」。

サーバ名またはIP: localhost パス: ./x.php

と入力。

左ペインの「スレッドグループ」を右クリックし,「追>加」→「リスナー」→「結果を表で表示」。

Ctrl+S し,保存。

ツールバーで「実行」→「開始」。

結果

平均25msってこと? webrickで、デバックで動かしてこれ

f:id:uoz:20160702171144j:plain

unicornでproductionだと、半分くらいになった。

f:id:uoz:20160702171153j:plain

2. 次はcake

cake php 3.2です

php 5.6 mysqlも5.6 細かいバージョンは忘れた

手抜きでmampで動かす DBはrailsと同じ感じだけど、カラム名等はcake標準になるように

アプリ

コントローラ /src/Controller/ArticlesController.php

<?php

namespace App\Controller;

class ArticlesController extends AppController
{
    public function index(){
        $articles = $this->Articles->find('all');
        $this->set(compact('articles'));
    }
}

ビュー /src/Template/Articles/index.ctp

<h1>test</h1>


<table>
    <tr>
        <th>
            タイトル
        </th>
        <th>
            内容
        </th>
        <th>
            更新日
        </th>
    </tr>
    <? foreach($articles as $article){ ?>
    <tr>
        <td>
            <?= $article->name ?>
        </td>
        <td>
            <?= $article->content ?>
            <? if(count($article->comments) > 0){ ?>
            <br />コメント:
            <? foreach($comment as $article->comments){ ?>
            <br /><?= $comment->content ?>
            <? } ?>
            <? } ?>
        </td>
        <td>
            <?= $article->modified ?>
        </td>

    </tr>
    <? } ?>
</table>

テスト実施

debugでない

平均 170ms なんでこんなに遅いのかな?

ここを参考に、OPcacheとついでにxdebugを止めてみる http://www.y-com.info/contents/?p=1165

がかえって遅くなる f:id:uoz:20160702171300j:plain

dockerでサーバ立ててみたら更に遅い

3. spring boot(java)

spring boot 1.3.5 java 1.8.0_92

java8をいれるところから

brew cask install java

DBにつなげられない.....

途中

4. express(node.js)

途中

結果まとめ

途中

参考

spring boot

http://maplesystems.co.jp/blog/programming/18474.html https://www.jetbrains.com/help/idea/2016.1/creating-spring-boot-projects.html https://pgcolony.com/entry/117 http://confrage.jp/springmvc%E3%81%A7modelattribute%E3%82%A2%E3%83%8E%E3%83%86%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%99%E3%82%8B/ http://www.riem.nagoya-u.ac.jp/~ohta/etc/springboot-3.html

java8 http://www.task-notes.com/entry/20150406/1428289200 http://qiita.com/shuntaro_tamura/items/60b8c19f62edfd942c2e

jmetor

http://language-and-engineering.hatenablog.jp/entry/20081014/1223905380 めっちゃ古いけど

おまけ

ある時、 railsでこんなエラーがでるように

undefined method `tr' for nil:NilClass Did you mean? try
Extracted source (around line #37):

         raise "Database URL cannot be empty" if url.blank?
          @uri     = uri_parser.parse(url)
          @adapter = @uri.scheme.tr('-', '_')
          @adapter = "postgresql" if @adapter == "postgres"

          if @uri.opaque

database.ymlがうまく読み込まれていない

ヒント http://raysapida.github.io/more-debugging/

別なプロジェクトでDATABASE_URLという環境変数を設定してしまったせいだった

Rails使ってる環境でDATABASE_URLには気をつけろ