oinume journal

Scratchpad of what I learned

最近のインプット

最近読んで面白かったブログとかYouTubeとかPodcastの紹介。

Talk Python To Me

talkpython.fm

Pythonpodcast。SQLAlchemyやrequestsなどめっちゃ使われているライブラリの作者が登場していて面白い。「SQLAlchemyはHibernateの影響を受けている」とか作者が言っていてなるほど確かにと思ったり。最初は英語の勉強目的で聴き始めたんだけど、普通にPythonの勉強になって一石二鳥な感じ。

地獄のサンフランシスコ by @chibicode

www.youtube.com

サンフランシスコの家賃がなぜあんなに高いのか、過去に成立してしまった謎の法律などとともに説明している。アメリカってもっと合理的な国だと思ったけど意外とそうでもないのかも...

わたしが1年間に送ったメールのうち40件を公開しました

chibicode.com

上でも紹介した地獄のサンフランシスコ在住のShu Uesugiさんがメンティーに送った「ちゃんとした技術者になるための心得」のメールを公開していた。どれもはっとさせられる内容が多くて「これもっと早く呼んでおきたかったわー」という内容だった。

特に

上達したいくせに、量をこなすことの大切さをナメてる人に読んでもらいたいです。

という言葉にははっとさせられた。最近は技術系の雑誌や本を読んでわかった気になってしまっていて、写経したり自分で手を動かす努力を怠ってしまっていたので。

What I read, watched, listened recently

dotGo 2014 - Andrew Gerrand - 5 things I love

Andrew Gerrand is a Googler and worked for Go. I watched this video just to learn English but it was good that he was describing Go's feature very well.

www.youtube.com

Golang UK Conference 2015 - Andrew Gerrand - Stupid Gopher Tricks

Another Andrew's talk. Slide

www.youtube.com

Twelve Go Best Practices - Francesc Campoy

Francesc Campoy is also a Googler and worked for Go. Best practices from Googler is worth to read. Slide

www.youtube.com

#163: Go in the Modern Enterprise Using gokit with Peter Bourgon - The Changelog

Go kit is a framework for microservices, Gokit has features to help microservices such as circuit breakers, rate limiter, request tracing, etc... The guest Peter Bourgon used to work for Soundcloud which uses Go so much.

changelog.com

Ansible Meetup in TokyoでLTしてきた

Vagrant環境のAnsibleを速くしたいというタイトル」でAnsible MeetupでLTしてきました。資料はこちら。

もともとは、「Ansible Meetup 行きたいなー。でももう埋まってるなー」から「LT枠に空きがあるからLTすればいいな」というノリでした。結果的にキャンセルがいっぱい出ていて、会場の4分の1ぐらいは席が空いていたという事態w (もったいない

LTは初めてかつ雰囲気がわからないイベントだったので、ネタ路線で攻めるべきなのかマジメに行くべきなのかわからなかったけど、ネタはそこそこウケていたみたいなので良かったです。あと、Ansible 2.0の話が聞けたのが嬉しかった。block機能が良さそうなのと、Playbook自体は1.x系と2系で互換性があるらしいのでリリースされたら使ってみたい。あと日経さんがAnsibleを使いこなしていて、かつSIerにも使ってもらうというすごいサイクルを生み出していたのが印象的だった。伊藤直也さんが技術顧問やっている影響なのか、最近情報発信がさかんでかなりイメージが上がっている気がします。

Ansibleは今後もどんどん使っていきたいので、また何かイベントがあったら出たいなぁと思います。

Detecting duplicated code in Golang with CPD and Jenkins

CPD (Copy Paste Detecor)

Detecting duplicated code is a good way to make source code clean. Since I couldn't find how to detect duplicated code in Golang, I sent a pull request that CPD(Copy Paste Detector) is able to accept Golang. CPD is a software included in PMD.

And there is a useful Jenkins plugin, DRY. It visualizes how much duplicated code exist. I'll show you how to make it visible with Jenkins.

Setting up Jenkins

Use docker-toolbox to shortcut installing jenkins. After installing docker-toolbox, you just type following command.

$ docker run -p 8080:8080 jenkins

And then web can access to http://192.168.99.100:8080/ and you'll see first Jenkins page.

Installing PMD Plugin

  • Click "Manage Jenkins" on a top page
  • Click "Manage Plugins"
  • Click "Available" Tab
  • Select "Duplicate Code Scanner Plug-in"
  • Click "Download now and install after restart"
  • Jenkins will be restarted after plugin installed

Create a job to detect duplicated code

We'll use terraform repository as an example.

  • Click "create new jobs" on a top page
  • Select "Freestyle project" and type name for your job.
  • Click Add build step and select "Execute shell" and paste following shell commands
export PMD=pmd-bin-5.3.3
if [ ! -d $PMD ]; then
  curl -o $PMD.zip -L -O http://downloads.sourceforge.net/project/pmd/pmd/5.3.3/pmd-bin-5.3.3.zip\?r\=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fpmd%2Ffiles%2Fpmd%2F5.3.3%2F\&ts\=1440850447\&use_mirror\=jaist
  [ -e $PMD.zip ] && unzip $PMD.zip
fi

[ ! -d terraform ] && git clone https://github.com/hashicorp/terraform.git
   
$PMD/bin/run.sh cpd --minimum-tokens 100 --files terraform --language go --format xml > cpd.xml || echo
  • Click "Add post-build action" on "Post-build Actions" and select "Publish duplicate code analysis results"
    • Duplicate code results: cpd.xml
    • High priority threshold: 50 (default)
    • Normal priority threshold: 25 (default)
  • Save the job and run it.
  • We can see a link "Duplicate Code" on the job page

Duplicate Code View Jenkins DRY Plugin

Duplicated code of terraform Duplicated code of terraform

Options of CPD

  • --minimum-tokens: The minimum token length which should be reported as a duplicate. I recommend 70 - 100.
  • --files: a directory to check duplication.
  • --language: a programming language.
  • --format: xml or plain

For further information, type following.

pmd-bin-5.3.3/bin/run.sh cpd -h

Finally

We can detect duplicated code with CPD and Jenkins.