mozyのかきおき

mozyの読書感想文や思考置き場

Laravel EOF; error

起きたこと

Laravelの開発中に、
syntax error, unexpected end of file, expecting variable (T_VARIABLE) or heredoc end (T_END_HEREDOC) or ${ (T_DOLLAR_OPEN_CURLY_BRACES) or {$ (T_CURLY_OPEN)
ってなエラーがでた。

解決方法

EOF; の後にあったスペースを削除したらエラーが消えた。

Cassandraを最速で試す【MacOSX】

やること

NoSQLなデータベースの勉強をし始めようと思って手始めにCassandraを最速で試してみた。

やったこと

まずはインストール
brew install cassandra
インストール後起動
cassandra
別ウィンドウを開いてクライアントからアクセスする。
とりあえず、CQLを使ってみる。
pipでインストールする。
pip install cql
アクセスしてKEYSPACEを確認してみる。

$cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh> DESCRIBE KEYSPACES;

system_traces  system_schema  system_auth  system  system_distributed

いい感じだ。サクッと使えるところまでセットアップできた。

一瞬ハマったところ

pipでインストールする際に、ローカル環境をpyenvで3.5.2として作ったのだがcqlshを立ち上げるときに

$ cqlsh
pyenv: python2.7: command not found

The `python2.7' command exists in these Python versions:
  2.7.12
  2.7.12/envs/test_2.7.12

みたいなエラーが出たので
pyenv local 2.7.12 として一旦解決した。

iOS開発 podfileを複数まとめるとき

起きたこと

iOSアプリ開発で、Podfileを書くときに、冗長になる部分があったのでいい感じにまとめたかった。

解決方法

以下のようにインストールしたいpodライブラリをinstall_podsみたいな変数にまとめてインストールすれば良い。

def install_pods
    pod 'AAA'
    pod 'BBB'
end

target :Test do
    install_pods
end

参考

Podfileの書き方変わったし、Podfileをきれいにまとめて書く。 - 思い立ったが吉日!

【解決】GitHubで依存packageの脆弱性警告がでた

起きたこと

GitHubリポジトリを眺めたら、以下の画像のように、依存パッケージの脆弱性情報を通知してくれた。ありがたい。
We found a potential security vulnerability in one of your dependencies.
f:id:mozy_ok:20180518000621p:plain

f:id:mozy_ok:20180518001047p:plain

対応方法

この際だし、各packageをアップデートするのが良いと思ったため、 npm-check-updatesを使ってncu -uでアップデートをかけてビルドした。
npm-check-updates - npm

だがしかし、エラーは消えない。
なるほどと思い、直接hoekのpackageをnpm install hoek@4.2.1ってな感じにupdateして解決した。

Docker上でイーサリアムのプライベートネットワークを構築してみる その1

何をするか

イーサリアムのスマートコントラクトに興味が湧いてきたため、色々と遊んでみたい。

やること

Docker上にイーサリアムのプライベートネットワークを構築して、まずは、動作テストをしてみる。

作業記録

公式が出しているイメージがあったため、とりあえず、Dockerのimageをpullする。

https://hub.docker.com/r/ethereum/client-go/

クライアントの実装は複数あるが、今回は一番メジャーらしきgo製のものを選択した。

Docker-test ❯ docker pull ethereum/client-go
Using default tag: latest
latest: Pulling from ethereum/client-go
ff3a5c916c92: Already exists 
621caa86389d: Pull complete 
bd6d857b7542: Pull complete 
Digest: sha256:2ff3324b43093b5edff3d0ce5260768a91d11182c1fce8fc0115d1eb71616ff9
Status: Downloaded newer image for ethereum/client-go:latest

そうしたらこんな感じになった。

docker images
REPOSITORY              TAG                 IMAGE ID            CREATED             SIZE
ethereum/client-go      latest              0cd307c2f2f4        25 minutes ago      42.3MB

とりあえず、-d オプションをつけて、バックグラウンドプロセスとして、runしてみる。

docker run -d --name ethereum-node -v $HOME/ethereum-data:/root \
            -p 8545:8545 -p 30303:30303 \
            ethereum/client-go --fast --cache=512

logを見てみると、

Docker-test ❯ docker logs -f ethereum-node
INFO [05-09|13:35:55] Maximum peer count                       ETH=25 LES=0 total=25
INFO [05-09|13:35:56] Starting peer-to-peer node               instance=Geth/v1.8.8-unstable-7beccb29/linux-amd64/go1.10.2
INFO [05-09|13:35:56] Allocated cache and file handles         database=/root/.ethereum/geth/chaindata cache=384 handles=1024
INFO [05-09|13:35:56] Writing default main-net genesis block 
INFO [05-09|13:35:57] Persisted trie from memory database      nodes=12356 size=2.34mB time=231.1108ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B
INFO [05-09|13:35:57] Initialised chain configuration          config="{ChainID: 1 Homestead: 1150000 DAO: 1920000 DAOSupport: true EIP150: 2463000 EIP155: 2675000 EIP158: 2675000 Byzantium: 4370000 Constantinople: <nil> Engine: ethash}"
INFO [05-09|13:35:57] Disk storage enabled for ethash caches   dir=/root/.ethereum/geth/ethash count=3
INFO [05-09|13:35:57] Disk storage enabled for ethash DAGs     dir=/root/.ethash               count=2
INFO [05-09|13:35:57] Initialising Ethereum protocol           versions="[63 62]" network=1
INFO [05-09|13:35:57] Loaded most recent local header          number=0 hash=d4e567…cb8fa3 td=17179869184
INFO [05-09|13:35:57] Loaded most recent local full block      number=0 hash=d4e567…cb8fa3 td=17179869184
INFO [05-09|13:35:57] Loaded most recent local fast block      number=0 hash=d4e567…cb8fa3 td=17179869184
INFO [05-09|13:35:57] Regenerated local transaction journal    transactions=0 accounts=0
INFO [05-09|13:35:57] Starting P2P networking 
INFO [05-09|13:35:59] UDP listener up                          self=enode://591157ed0651158beeff8b4e79252ab83e00a12118f5308bdd4125f3a9e9b6150c781f667ccf715a4a4e42e0f66d2daed14672758036ff60b12358d5ffe53716@[::]:30303
INFO [05-09|13:35:59] RLPx listener up                         self=enode://591157ed0651158beeff8b4e79252ab83e00a12118f5308bdd4125f3a9e9b6150c781f667ccf715a4a4e42e0f66d2daed14672758036ff60b12358d5ffe53716@[::]:30303
INFO [05-09|13:35:59] IPC endpoint opened                      url=/root/.ethereum/geth.ipc
INFO [05-09|13:36:19] Block synchronisation started 
WARN [05-09|13:36:20] Node data write error                    err="state node 45a7a6…90e5b7 failed with all peers (1 tries, 1 peers)"
WARN [05-09|13:36:20] Synchronisation failed, retrying         err="state node 45a7a6…90e5b7 failed with all peers (1 tries, 1 peers)"
WARN [05-09|13:36:30] Node data write error                    err="state node 45a7a6…90e5b7 failed with all peers (1 tries, 1 peers)"
WARN [05-09|13:36:30] Synchronisation failed, retrying         err="state node 45a7a6…90e5b7 failed with all peers (1 tries, 1 peers)"
WARN [05-09|13:36:40] Node data write error                    err="state node 45a7a6…90e5b7 failed with all peers (1 tries, 1 peers)"
WARN [05-09|13:36:40] Synchronisation failed, retrying         err="state node 45a7a6…90e5b7 failed with all peers (1 tries, 1 peers)"
WARN [05-09|13:36:54] Node data write error                    err="state node 45a7a6…90e5b7 failed with all peers (1 tries, 1 peers)"
WARN [05-09|13:36:54] Synchronisation failed, retrying         err="state node 45a7a6…90e5b7 failed with all peers (1 tries, 1 peers)"
INFO [05-09|13:37:05] Imported new block headers               count=192 elapsed=3.832s number=192 hash=723899…123390 ignored=0
INFO [05-09|13:37:05] Imported new block receipts              count=2   elapsed=2.177ms number=2   hash=b495a1…4698c9 size=8.00B  ignored=0
INFO [05-09|13:37:06] Imported new block receipts              count=4   elapsed=2.038ms number=6   hash=1f1aed…6b326e size=1.10kB ignored=0
INFO [05-09|13:37:15] Imported new block receipts              count=186 elapsed=8.338ms number=192 hash=723899…123390 size=23.40kB ignored=0
INFO [05-09|13:37:26] Imported new state entries               count=439 elapsed=20.453ms processed=439 pending=6377 retry=0 duplicate=0 unexpected=0
INFO [05-09|13:37:30] Imported new state entries               count=945 elapsed=5.209ms  processed=1384 pending=7265 retry=0 duplicate=0 unexpected=0
INFO [05-09|13:37:31] Imported new state entries               count=762 elapsed=9.751ms  processed=2146 pending=6584 retry=3 duplicate=0 unexpected=0
INFO [05-09|13:37:33] Imported new state entries               count=1135 elapsed=20.362ms processed=3281 pending=6484 retry=7 duplicate=0 unexpected=0
INFO [05-09|13:37:34] Imported new state entries               count=1138 elapsed=9.992ms  processed=4419 pending=7552 retry=7 duplicate=0 unexpected=0
INFO [05-09|13:37:36] Imported new state entries               count=1515 elapsed=19.731ms processed=5934 pending=7202 retry=0 duplicate=0 unexpected=0
INFO [05-09|13:37:39] Imported new state entries               count=1515 elapsed=14.048ms processed=7449 pending=5943 retry=0 duplicate=0 unexpected=0
INFO [05-09|13:37:41] Imported new state entries               count=1131 elapsed=12.412ms processed=8580 pending=5545 retry=7 duplicate=0 unexpected=0
INFO [05-09|13:37:43] Imported new state entries               count=1136 elapsed=11.578ms processed=9716 pending=5263 retry=0 duplicate=0 unexpected=0
INFO [05-09|13:37:45] Imported new state entries               count=1128 elapsed=14.792ms processed=10844 pending=5164 retry=8 duplicate=0 unexpected=0
INFO [05-09|13:37:47] Imported new state entries               count=1135 elapsed=11.881ms processed=11979 pending=4555 retry=9 duplicate=0 unexpected=0
INFO [05-09|13:37:51] Imported new state entries               count=1136 elapsed=9.862ms  processed=13115 pending=4687 retry=8 duplicate=0 unexpected=0
INFO [05-09|13:37:52] Imported new state entries               count=1136 elapsed=26.089ms processed=14251 pending=3651 retry=8 duplicate=0 unexpected=0
INFO [05-09|13:37:53] Imported new state entries               count=362  elapsed=4.607ms  processed=14613 pending=5899 retry=22 duplicate=0 unexpected=0
INFO [05-09|13:37:56] Imported new state entries               count=1087 elapsed=7.865ms  processed=15700 pending=5996 retry=21 duplicate=0 unexpected=0
INFO [05-09|13:37:56] Imported new state entries               count=384  elapsed=2.582ms  processed=16084 pending=9501 retry=0  duplicate=0 unexpected=0
INFO [05-09|13:37:58] Imported new state entries               count=1087 elapsed=23.781ms processed=17171 pending=9113 retry=22 duplicate=0 unexpected=0
INFO [05-09|13:37:59] Imported new state entries               count=1108 elapsed=23.035ms processed=18279 pending=9275 retry=22 duplicate=0 unexpected=0
INFO [05-09|13:38:02] Imported new state entries               count=1086 elapsed=21.992ms processed=19365 pending=8924 retry=22 duplicate=0 unexpected=0

お、なんかいい感じに構築できているっぽい。
一旦ここまで。

参考

qiita.com

【解決済】geth でバックグラウンド実行したプロセスがkillできない時

おきたこと

イーサリアムの勉強中に、採掘等のためにGethをバックグラウンドで常時起動して置くために & を使って以下のようなプロセスを走らせた。
geth --networkid "15" --nodiscover --datadir "eth_private_net/" console 2> eth_private_net/geth_err.log &

その後、ターミナルで普通にプロセスを普通に killしようと思ったらできないことがあった。

解決策

kill -SIGKILL {pid}のように-SIGKILLオプションをつけることで解決した。
ps aux | grep geth なりで該当のpidを確認してkillすると良いと思う。