ドワンゴの会社見学行ってきたよ!!

本日、会津大の主催のドワンゴの見学に行ってきた。
銀座にある本社だ。 歌舞伎タワーの12-15階をぶちぬいて作られている。 f:id:nukisakineko:20150929124729j:plain

毎週のLTで使われるというフロアで、会津大のOBと交流し、バックエンドとインフラをしている開発者に話を聞いた。
開発者と話してみると、自分たちの製品について自信を持っていて、自分をサポートしてくれる環境とその環境を作ってくれる会社に感謝していた。
また、開発現場も回った。エンジニアのフロアは清潔感のあるオフィスで、エンジニアに優しそうだった。

OB交流の内容とかはどこまで書いていいかわからないから、簡単にリンクを貼っておく。
KADOKAWA・DWANGO、「カドカワ株式会社」に社名変更 - ITmedia ニュース
【さよならドワンゴ】角川・ドワンゴが社名を変更してヤバい - Togetterまとめ
とか、
「技術的負債」の返済ルールを作る 株式会社ドワンゴ 清水俊博 氏 |IT・Web業界の転職ならDODAエンジニア IT
ドワンゴのエンジニア新人研修2015:dwango エンジニア ブロマガ:ドワンゴ研究開発チャンネル(ドワンゴグループのエンジニア) - ニコニコチャンネル:生活
とか、
Developers Summit 2014 「Play2/Scalaでドメイン駆動設計を利用した大規模Webアプリケーションのスクラム…
とか、この辺と、OBさんの経歴とかを聞いた。

あと、「カドカワ株式会社」も「KADOKAWA・dwango」も、経営統合(≠合併)したというのが真実らしい。 (合併と違う点は、会社二社は存命。親会社を作って、親会社に二社の経営を放り投げただけ。 [KADOKAWA・dwango]->[カドカワ,ドワンゴ]みたいな感じらしい)

感想として、今回の説明会では(5人中3人が会津大OBだったから偏っているかもしれないが)半数は中途採用されている人が多かったのが印象的。
職場環境とかもいい感じ、ツールが充実しているみたい。
関数型プログラムが中で流行っているっていいなとかは思った。
久しぶりの前線の人たちとの交流で、活力をもらえた。
前線で働いている人たちが眩しい。
今日も頑張ろう。

Getting Started with Ruby on Herokuをやったので概要だけまとめる。

Introduction

ruby をインストールするだけ。

Set up

heroku toolbeltをインストールするコマンドをコピペするだけ。

Prepare the app

git cloneするだけ。

Deploy the app

heroku上でgit cloneしたアプリを動かす。コマンドコピペ。

View logs

heroku上でのログの見方

Define a Procfile

herokuアプリはProcfileで定義されてるよ。ね?見えるでしょ。catコマンド。

Scale the app

herokuの制限時間のお話と起動してから何時間立ったか見る方法。

Declare app dependencies

ローカルでbundle installしてみよう。 nukisakineko.hatenablog.com

Run the app locally

ローカルでdbを作ってみよう。 nukisakineko.hatenablog.com

Push local changes

牛に喋らせてみよう。

Provision add-ons

アドオンあります。

Start a console

herokuでリモートコンソールを開くには。

Define config vars

configの変数を設定できるよ。

Use a database

データベースを使っていることを確かめよう。

herokuのRun the app locallyでbundle exec rake db:create db:migrateできなくてはまった話

ここに至る手順

bundle exec rake db:create db:migrate

を行う前にthese instructionsを踏んでpostgresqlのインストールを行わなければならない。

行わないと

could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

や

Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "database"=>"ruby-getting-started_development"}
could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?

というエラーが出てきてハマる。つか、はまった。
(ドキュメントが英語だからって読まないで進めようとするから……)

うし、公式のコピペだー。

sudo apt-get install postgresql
which psql
psql

そして、psqlでエラーが発生した。

psql: FATAL:  role "nukisashineko" does not exist

ロールの設定が必要という・・・。


PostgreSQLの初期導入のエラーにもてあそばれ、格闘すること2時間余り、
UbuntuでPostgreSQLをインストールからリモートアクセスまでの手順 - Qiita
FreeBSD + PostgreSQL 9.3.2 外部からの接続を許可する - Symfoware
などを見て、やっと設定が完成する。

解決法

最終的にherokuのbundle exec rake db:create db:migrateを行うために必要な手順。
ちな、全て行わないとバグる。

1. postgresqlのインストール

sudo apt-get install postgresql

2. ロール(ユーザみたいなもん)の作成

sudo su - postgres
createuser ruby-getting-started  --createdb --login   --pwprompt
Enter password for new role: 
Enter it again: 

と入力して、postgresの権限で、パスワード持ちのユーザーを作成。

3. ログイン時の認証制限の緩和

/etc/postgresql/{version}/main/pg_hba.confの90行付近のlocalに対するpeer認証を外して、無条件でlocalなら無条件で入れるようにする。
(peer認証 == 現在のシェルログイン者と同一のロールでなければログイン拒否をする機構)

# "local" is for Unix domain socket connections only
local   all             all                                    peer
# "local" is for Unix domain socket connections only
local   all             all                                    trust

と変更。で、/etc/init.d/postgresql restartと再起動して、設定を反映。

4. railsのDBの設定の変更

heroku/ruby-getting-started/config/database.ymlを編集。 development,testの配下にそれぞれ、 username: ruby-getting-started password: password を追記する。 コメントを全部消すとこんな感じ。

default: &default
  adapter: postgresql
  encoding: unicode
  pool: 5
development:
  <<: *default
  database: ruby-getting-started_development
  username: ruby-getting-started
  password: password
test:
  <<: *default
  database: ruby-getting-started_test
  username: ruby-getting-started
  password: password
production:
  <<: *default
  database: ruby-getting-started_production
  username: ruby-getting-started
  password: <%= ENV['RUBY-GETTING-STARTED_DATABASE_PASSWORD'] %>

で、これで、bundle exec rake db:create db:migrateすると、とりあえず動く。 commitしても、とりあえず動く、heroku側ではproductionの設定を使用しているようだ。

ubuntsu 15.04 でgem pg install に失敗する。

原因:

libpq-fe.hが見つからないことでインストールに失敗する。
また、ubuntsu 15.04でlibpq-devをインストールしただけだとパスに乗っかってないから、やっぱりlibpq-fe.hが見つからない。
よって、gem install に使うconfigにパスを明示してやる必要性がある。

解決方法:

sudo apt-get install libpq-dev  
export CONFIGURE_ARGS="with-pg-include=/usr/include/postgresql/libpq-fe.h"  
bundle install  

備忘録:

herokuのpgインストール中に下記のエラーが発生。

Installing pg 0.17.1 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /home/nukisashineko/.rvm/rubies/ruby-2.2.3/bin/ruby -r ./siteconf20150906-8484-b5czan.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/home/nukisashineko/.rvm/rubies/ruby-2.2.3/bin/$(RUBY_BASE_NAME)
    --with-pg
    --without-pg
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib

extconf failed, exit code 1

Gem files will remain installed in /home/nukisashineko/.rvm/gems/ruby-2.2.3/gems/pg-0.17.1 for inspection.
Results logged to /home/nukisashineko/.rvm/gems/ruby-2.2.3/extensions/x86_64-linux/2.2.0/pg-0.17.1/gem_make.out
An error occurred while installing pg (0.17.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.17.1'` succeeds before bundling.

Can't find the 'libpq-fe.h header
ということで、libpq-fe.hが見つからないらしい。

こんな時のapt-fileコマンドを使って

apt-file update
apt-file search  libpq-fe.h
 libpq-dev: /usr/include/postgresql/libpq-fe.h  
 postgres-xc-server-dev: /usr/include/postgres-xc/server/gtm/libpq-fe.  

と返ってくる。

つまりlibpq-devを入れれば解決するはず・・・。

sudo apt-get install libpq-dev

やったか・・・?

gem install pg
Installing pg 0.17.1 with native extensions

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    /home/nukisashineko/.rvm/rubies/ruby-2.2.3/bin/ruby -r ./siteconf20150906-8484-b5czan.rb extconf.rb
checking for pg_config... yes
Using config values from /usr/bin/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/home/nukisashineko/.rvm/rubies/ruby-2.2.3/bin/$(RUBY_BASE_NAME)
    --with-pg
    --without-pg
    --with-pg-config
    --without-pg-config
    --with-pg_config
    --without-pg_config
    --with-pg-dir
    --without-pg-dir
    --with-pg-include
    --without-pg-include=${pg-dir}/include
    --with-pg-lib
    --without-pg-lib=${pg-dir}/lib

extconf failed, exit code 1

Gem files will remain installed in /home/nukisashineko/.rvm/gems/ruby-2.2.3/gems/pg-0.17.1 for inspection.
Results logged to /home/nukisashineko/.rvm/gems/ruby-2.2.3/extensions/x86_64-linux/2.2.0/pg-0.17.1/gem_make.out
An error occurred while installing pg (0.17.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.17.1'` succeeds before bundling.

くぅ、ダメか。


ネットを探し回ると、

rails install pg - Can't find the 'libpq-fe.h header - Stack Overflow

On Mac OS X run like this:

gem install pg -- --with-pg-config=/path/to/pg_config

/path/to/pg_config is path to pg_config

ruby on rails - Can't find the 'libpq-fe.h header when trying to install pg gem - Stack Overflow

export CONFIGURE_ARGS="with-pg-include=/Library/PostgreSQL/9.1/include/"
gem install pg

というふうにライブラリの場所を直接指定してやれという回答を発掘。


さっきインストールしたlibpq-fe.hがどこにあるか調べると

sudo updatedb
locate libpq-fe.h

/usr/include/postgresql/libpq-fe.h

にあるらしい。

つまり、うちのマシンでは

export CONFIGURE_ARGS="with-pg-include=/usr/include/postgresql/libpq-fe.h"
gem install pg

Building native extensions. This could take a while... Successfully installed pg-0.18.3 1 gem installed

で成功する。

で、肝心の

export CONFIGURE_ARGS="with-pg-include=/usr/include/postgresql/libpq-fe.h"
bundle install

でも成功することを見届けてherokuのexampleがlocalで動くことを確認。

tx1310 m1でbiosにhddが認識されずにハマった件

症状

ubuntsu server 14.04 LTS 64bitをインストールした後、何故かhddがbootメニューに出力されない。

対策

biosが起動した時にf2を押してbios設定画面に入る
Advanced メニュー>SATA Configuration>SATA Mode(default:RAID Mode) を AHCI Modeに変更する。

原因

ubuntu installはwindowみたいにraidのドライバーがないで止まらない。
よって、raidでインストールされててるのか、ahciでインストールされてるのか、わからないです。
あと、raidってbiosで設定されてると、raidの初期化されたhddしか、読み込まなくなるなんてことも……そんなこと、しるかー!!

経緯

原因仮定「2TBの壁?」

インストール作業自体は全く何も問題が起きずに進み、サーバを立ち上げられると考えていると、何故か起動できなくてこける。
最初は3TBのhddを使っているからなのかな(2TBの壁問題か?)と思って、2TBのhddを購入し、再度インストールするも、起動できなくてこける。

原因仮定「UEFI」

次に、UEFIってやつが原因かもと思いだした。

富士通の公式ページに次の記述を見つける。

Fujitsu Server PRIMERGY TX 1310 M1 ご使用上の留意・注意事項 2014年5月 富士通株式会社

(1)UEFIモードについての留意本装置では UEFI モードはご使用になれません。 UEFI モードでの OS インストールは未サポートとなります。 BIOS 設定の [Boot] メニュー – [B oot Option Priorities] 上に UEFI モードの起動メニューが表示されますが、ご使用 になれません

更新日:2015年5月22日 UEFI対応情報によると

PRIMERGY TX1310 M1 のバージョン 1.1以上ならUEFIは作動可能

おい、富士通、どっちだ!?

結局、Legacyモードでインストールしようとするも失敗。

それにいくつものサイトでUEFIでインストール(windowsだけど)できているような記述を見たのでこれではないと気づく。

原因仮定「RAID? AHCI?」

探しているうちに同じような不自然な記述を見つける。

PRIMERGY TX1310にWindows8をインストールするメモ

RAIDは使わないのでBIOSでSATA ModeをAHCIに変更する。こうしないとWin8インストールのパーティション選択時に進めなくなる。切り替えた直後は各ポートがEmptyと表示されるが再起動すればちゃんと認識する。

ファイルサーバー・ストレージのあれこれ、初級編(第四回)

またWindows Server 2012(R2)では別途デバイスドライバを適用しないと組んだRAIDが認識されず単体のHDDとして認識されてしまう問題があります。
このままインストールを進めると途中でインストールが頓挫してしまうので必ずドライバを適用してください。

価格.com - 『UEFIによる起動方法について』 ASRock B75M のクチコミ掲示板

SATA ポートを AHCI モードにしてください。

windowsのインストールではSATA ModeをRAIDからAHCIに変えないと躓く? ん?

とりあえず、AHCI設定をしてみると、今まで認識されなったP0(sata port0の略)が認識されている!!

biosから、ubuntuが見えたので、解決。

俺の十数時間を返せぇぇーー

今日勉強したこと

『2TBの壁』

主に32bitパソコンで起きるフォーマットすらできない空間ができてしまう現象。
最近の64bitパソコンにはほとんど起きない。

『UEFIとLegacy』

UEFIはほぼ64bit用のbootセクタの書き込み方法の一つ bootセクタの大きさの制限がない 普通、512MB確保する。

Legacyは旧式のbootセクタの書き込み方法の一つ MBRというbootセクタが512Bしかなく、ここにgrub等がある場所が書いてあり、bootのパーティションに飛ぶシステムになっていた。32bitの御用達。64bitがLegacyを使うためにcompatibility support module(CSM)を使用する。

『RAIDとAHCI』

RAIDは複数ディスクを扱って一つのディスクとして扱う方法。続く番号によって、振る舞いが大きく異なる。 が RAID構成されたディスクを読み込む際のSATAの伝送方式の一つでもある。

AHCIはSATAの伝送方式の一つ。IDEより早い。あとhddをusbみたいにパソコン起動中に取り外せる(ホットプラグ)

firefox40.0に更新されたら、disableSelection()につけた、delegate()が動かなくなった件について

とりあえずよくわからないので、検索すると以下のようなものがでてきた。

jQuery UI の.disableSelection()がdeprecated(非推奨)になってる件 - kamegu's memo

version1.6で追加されて、1.9からDeprecated。
http://api.jqueryui.com/disableSelection/
そもそも今使っているバージョン()に限っていえば、
$(".sortable").sortable();
だけでもテキストの選択はできない。
Deprecatedになる前のjQuery UI 1.8.1(+jQuery 1.7.1)でもテキストの選択はできません。
文字列を選択できなくするならCSSでやれ、って話も。

現在動いているjsの環境が1.11.1なのでそれっぽいかも??

jQuery UIでリストのソート機能を実装したときにFirefoxとかでinputのフォーカスがおかしくなる件 | Bamboo lath 日々の記録

結局以下↓の箇所を
el.disableSelection().delegate('input,textarea','click',function(ev){
ev.target.focus();
});

「【jQuery】sortable()を設定したタグ内のtextarea, inputタグに入力出来ない」このページの内容通りに以下↓のように変更。
el.bind('click.sortable mousedown.sortable',function(ev){
ev.target.focus();
});

うん、これだ。
ということで治ったみたい。

どのような環境で、inputが動かなくなったのか?

ところで、sortableの後ろを変更させてみるとinputの動作はどうなるのだろうか?

というわけで以下の3つのものについて検証。

sortable({...}).bind('click.sortable mousedown.sortable',function(){...});
sortable({...}).disableSelection().delegate('input,textarea,select',function(){...});
sortable({...});

検証環境

jQuery UI: Sortableウィジェットで並べ替え可能なリストを生成するには? - Build Insider を参考にして動くコードを書いてみた。

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>Sortableウィジェット</title>
    <style type="text/css">
        <!--
        table, th, td { border-collapse: collapse; border: solid 1px #000; }
        -->
    </style>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
    <link type="text/css" rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/cupertino/jquery-ui.min.css" />
    <script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.min.js"></script>
    <script type="text/javascript">
        <!--
        $(function() {
            $('#list').sortable({
                update: function(ev, ui) {
                    var Array = $("#list").sortable("toArray");
                    alert(Array)
                }
            }).bind('click.sortable mousedown.sortable',function(ev){//この辺を変更する
                ev.target.focus();
            });
        });
        -->
    </script>
</head>
<body>
<table>
    <thead>
    <th>ID番号</th><th>input</th>
    </thead>
    <tbody id="list">
    <tr id="1">
        <th>1</th>
        <td>あ<input type="text" placeholder="aaa"></td>
    </tr>
    <tr id="2">
        <th>2</th>
        <td>い<input type="checkbox" value="checked"></td>
    </tr>
    <tr id="3">
        <th>3</th>
        <td>う<input type="button" value="button" onclick="alert('button clicked')"></td>
    </tr>
    <tr id="4">
        <th>4</th>
        <td>え
            <input type="radio" name="t" value="1">aaa
            <input type="radio" name="t" value="2">bbb
        </td>
    </tr>
    <tr id="5">
        <th>5</th>
        <td>お
            <textarea name="cat" id="" cols="30" rows="10">test</textarea>
        </td>
    </tr>
    <tr id="6">
        <th>6</th>
        <td>か
            <select name="test">
                <option value="1">aaa</option>
                <option value="2">bbb</option>
                <option value="3">ccc</option>
                <option value="4">ddd</option>
                <option value="5">eee</option>
            </select>
        </td>
    </tr>
    </tbody>
</table>
</body>
</html>

結果

関数 入力方法判定
bind 入力部分以外は選択できないO
input textO
input checkboxO
input buttonO
input radioO
textareaO
selectO
disableSelection().delegate 入力部分以外は選択できないO
input textX
input checkboxO
input button△
input radioO
textareaX
selectX
sortable単体 入力部分以外は選択できないO
input textO
input checkboxO
input buttonO
input radioO
textareaO
selectO

※△はonclickは動いたが、フォーカスされなかったため(jsでは動くが、htmlとしては動かない)

うむ・・・。
つまり、前のバージョンでは、firefoxのsortable単体だと不具合が出ていたが、
新バージョンのfirefoxではsortable単体で動かせるようにもなったって言うことなのかな。。。

とりあえず、互換性のためにも
sortable({...}).bind('click.sortable mousedown.sortable',function(){...});
がいいみたい。