<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[tkt989 🍵  ブログ]]></title><description><![CDATA[日々のメモ]]></description><link>https://blog.tkt989.info</link><generator>GatsbyJS</generator><lastBuildDate>Sun, 10 Apr 2022 12:35:07 GMT</lastBuildDate><item><title><![CDATA[バイクに乗りはじめた]]></title><description><![CDATA[1年以上ぶりの投稿。 2020/09くらいからふつふつとバイクに興味がでて教習所に通い始めて、2ヶ月くらいで免許取得できた。
良いバイクなんて分からないし、とりあえずコスパでジクサー150を購入。]]></description><link>https://blog.tkt989.info/2021/06/02/バイクに乗りはじめた</link><guid isPermaLink="false">https://blog.tkt989.info/2021/06/02/バイクに乗りはじめた</guid><pubDate>Wed, 02 Jun 2021 14:31:54 GMT</pubDate><content:encoded>&lt;p&gt;1年以上ぶりの投稿。&lt;/p&gt;
&lt;p&gt;2020/09くらいからふつふつとバイクに興味がでて教習所に通い始めて、2ヶ月くらいで免許取得できた。
良いバイクなんて分からないし、とりあえずコスパでジクサー150を購入。&lt;/p&gt;
&lt;img src=&quot;/2021/06/bike.jpg&quot;/&gt;</content:encoded></item><item><title><![CDATA[Android build on GitHub Actions でdebug keystoreを設定]]></title><description><![CDATA[Android Studioで開発しているときには、デバッグ用の証明書ファイルで署名されています。
このファイルはにあります。
証明書が違うとインストールするときに、エラーが起きていったん入ってるアプリのアンインストールが必要になります。
SQLiteなどのApp…]]></description><link>https://blog.tkt989.info/2020/05/27/Android-build-on-GitHub-Actions-でdebug-keystoreを設定</link><guid isPermaLink="false">https://blog.tkt989.info/2020/05/27/Android-build-on-GitHub-Actions-でdebug-keystoreを設定</guid><pubDate>Tue, 26 May 2020 15:43:00 GMT</pubDate><content:encoded>&lt;p&gt;Android Studioで開発しているときには、デバッグ用の証明書ファイルで署名されています。
このファイルは&lt;code class=&quot;language-text&quot;&gt;~/.android/debug.keystore&lt;/code&gt;にあります。
証明書が違うとインストールするときに、エラーが起きていったん入ってるアプリのアンインストールが必要になります。
SQLiteなどのApp内で使うデータが消えてしまうので、同じ証明書で署名したいところです。&lt;/p&gt;
&lt;p&gt;GitHubのsecretsにkeystoreをbase64に変換して保存します。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;shell&quot;&gt;&lt;pre class=&quot;language-shell&quot;&gt;&lt;code class=&quot;language-shell&quot;&gt;$ base64 ~/.android/debug.keystore&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;上の内容をsecretsに貼り付けましょう。&lt;/p&gt;
&lt;p&gt;そしてworkflowで&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;yaml&quot;&gt;&lt;pre class=&quot;language-yaml&quot;&gt;&lt;code class=&quot;language-yaml&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;token key atrule&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; echo $&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; secrets.KEYSTORE &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;|&lt;/span&gt; base64 &lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;-&lt;/span&gt;decode &lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt; ~/.android/debug.keystore&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;を実行して、keystoreを&lt;code class=&quot;language-text&quot;&gt;~/.android/debug.keystore&lt;/code&gt;に保存する。&lt;/p&gt;
&lt;h1&gt;参考にしたサイト&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://blog.spacemarket.com/code/circleci-android/&quot;&gt;https://blog.spacemarket.com/code/circleci-android/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[Kindle Unlimited で読める、AWS VPC をざっくり知れる本]]></title><description><![CDATA[AWS は VPS 感覚で EC2 インスタンスを作ったことしかなかった。
そんな感じなので、体系的な知識を勉強中です。 とりあえず、以下の本を読んだのですがなかなか良かったです。
AWS 内でネットワークを構築できる VPC…]]></description><link>https://blog.tkt989.info/2020/02/16/Kindle-Unlimited-で読める、AWS-VPC-をざっくり知れる本</link><guid isPermaLink="false">https://blog.tkt989.info/2020/02/16/Kindle-Unlimited-で読める、AWS-VPC-をざっくり知れる本</guid><pubDate>Sun, 16 Feb 2020 14:45:46 GMT</pubDate><content:encoded>&lt;p&gt;AWS は VPS 感覚で EC2 インスタンスを作ったことしかなかった。
そんな感じなので、体系的な知識を勉強中です。&lt;/p&gt;
&lt;p&gt;とりあえず、以下の本を読んだのですがなかなか良かったです。
AWS 内でネットワークを構築できる VPC や サブネットなど説明されています。&lt;/p&gt;
&lt;p&gt;数年前の本だけど、内容はほぼ今でも通じます。
一部UIの文言が違うだけで、AWS の設定の仕方は変わっていないです。&lt;/p&gt;
&lt;p&gt;Kindle Unlimited 会員なので無料で読めた。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://amzn.to/39IgXaj&quot;&gt;Amazon Web Services ネットワーク入門&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Python Boot Camp in 長崎 に TA として参加した記録]]></title><description><![CDATA[2月8日に開催された Python Boot Camp in 長崎 に参加してきました。
Python Boot Camp はPythonを広めるために、PyConJPというコミュニティが日本各地で開催している入門者向けの勉強会です。 開催される一月前くらいにconnpass…]]></description><link>https://blog.tkt989.info/2020/02/11/Python-Boot-Camp-in-長崎-に-TA-として参加した記録</link><guid isPermaLink="false">https://blog.tkt989.info/2020/02/11/Python-Boot-Camp-in-長崎-に-TA-として参加した記録</guid><pubDate>Tue, 11 Feb 2020 07:54:20 GMT</pubDate><content:encoded>&lt;p&gt;2月8日に開催された &lt;a href=&quot;https://pyconjp.connpass.com/event/158803/&quot;&gt;Python Boot Camp in 長崎&lt;/a&gt; に参加してきました。
Python Boot Camp はPythonを広めるために、PyConJPというコミュニティが日本各地で開催している入門者向けの勉強会です。&lt;/p&gt;
&lt;p&gt;開催される一月前くらいにconnpassで知り、最初は一般参加者として参加してみようかなっと思っていました。しかしTA枠もあって、TAというのはティーチングアシスタントで講義中に困っている人を助ける係の人ですね。
講義では、コードを書いて実行したりもするのですがしエラーが出たり環境設定がうまくいってなかったりで詰まってしまう人もいるので、そういう人に声をかけてサポートするのです。&lt;/p&gt;
&lt;p&gt;Pythonは趣味でツールとかWebサービスとか作ったりしたことがあるし、講義で使うテキストを読んでみたら自分でも教えられそうな内容だったので、思い切ってTAとして参加してみました。&lt;/p&gt;
&lt;p&gt;応募するとSlackに招待されてもらい、当日は開始時間前にランチミーティングを行いました。
自己紹介やTA経験者の方から、参加者の方がどういうところで詰まりやすいかなどを教えてもらえた。
いやーやっぱり初めてだったので、経験者がいたのは心強かったです。&lt;/p&gt;
&lt;p&gt;会場はできたばっかりの&lt;a href=&quot;https://miraionlibrary.jp/&quot;&gt;ミライon図書館&lt;/a&gt;。初めて行ったけど、広くてオシャレだった。また行ってみたい。でも利用券作るの忘れちゃった。また来たときに作ろうと思う。&lt;/p&gt;
&lt;img src=&quot;https://paper-attachments.dropbox.com/s_1B91B0CFFFBAD933A6664A04B7143EA46F12E2D923A8684FBDFB51B432A69547_1581401835475_MVIMG_20200208_122159+1.jpg&quot; style=&quot;width: 300px;&quot;&gt;
&lt;p&gt;会場の準備が終わると、参加者の方も集まってきた。人数は20人くらいほぼ満員です。私がconnpassで参加申請したときは、まだ数人くらいだった。
こんなに集まるとは思わなくて少し意外。
長崎でもPythonをやってみたい人が多いんですね。&lt;/p&gt;
&lt;p&gt;イベントルームも広くて過ごしやすく、途中でおやつ休憩に入ったときは、隣同士になった人と自己紹介して雑談しあったりいい雰囲気でした
また、イベントスタッフに &lt;a href=&quot;https://pyladiestokyo.github.io/&quot;&gt;Pyladies&lt;/a&gt; のスタッフの方もいて活動内容を紹介していました。
勉強会には女性の方も参加していました。&lt;/p&gt;
&lt;p&gt;基本的には、テキストを読みながら講師の方が進めていきます。講師が話している最中は邪魔なので後ろにいて、コードを書くステップに入ったら教室をウロウロしながら困っている人に声をかけたりしながら過ごします。&lt;/p&gt;
&lt;p&gt;参加者の方は、最初の環境構築などで詰まってしまうことが多いみたいで、最初の1時間が大変とのこと。TA経験者の方がいたので心強かったです。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://pycamp.pycon.jp/textbook/index.html&quot;&gt;テキスト&lt;/a&gt;の内容は、環境構築からFizzBuzzを解いたり、リストや辞書などのデータ型の解説、最後にはスクレイピングを行うのですが、&lt;code class=&quot;language-text&quot;&gt;venv&lt;/code&gt;を使って仮想環境を作りパッケージをインストールします。
そう、&lt;code class=&quot;language-text&quot;&gt;venv&lt;/code&gt;まで使うのです。事前にテキストを読んだときは、初心者には仮想環境と説明しても理解してもらえるのかなぁと感じたり、プログラミング経験者でも&lt;code class=&quot;language-text&quot;&gt;ruby&lt;/code&gt;や&lt;code class=&quot;language-text&quot;&gt;nodejs&lt;/code&gt;をやったことないと、&lt;code class=&quot;language-text&quot;&gt;venv&lt;/code&gt;を使う意味がわからないんじゃないと思ったりしましたが。
でも講師の方が覚えておくと絶対便利だと言っていたので、ただ単にPythonの入門ではなく、実践的な内容になっているなぁと感じた。&lt;/p&gt;
&lt;p&gt;TAで参加した感想としては、こういうサポート役で勉強会に入ったのは初めてだったので、いい経験になったなと思う。
画面をみながら回っていると、「あっ、ここ間違えてるな」って思うわけですが、自分が書いたコードが間違っている認識を持つ前に、こっちから「ここ間違ってますよ！」って言うのもどうなのかな、鬱陶しがられそうかなと考えたりしてた。
基本的には、エラーを解決できなさそうだったな声をかけにいくって感じでやりました。&lt;/p&gt;
&lt;p&gt;質問にもいくつか答えて、&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;venv&lt;/code&gt; で仮想環境にちゃんと入っているかよくわからない&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;ターミナルのプロンプトに&lt;code class=&quot;language-text&quot;&gt;(env)&lt;/code&gt;みたいな仮想環境の名前が入ってるならOKだよみたい答えた&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;（詳しい人から）&lt;code class=&quot;language-text&quot;&gt;venv&lt;/code&gt;でPythonのバージョンを切り替えたい場合はどうすればいいの&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://github.com/rbenv/rbenv&quot;&gt;rbenv&lt;/a&gt; や &lt;a href=&quot;https://github.com/nvm-sh/nvm&quot;&gt;nvm&lt;/a&gt; みたいにインタプリタのバージョンも仮想化したい場合&lt;br&gt;
&lt;code class=&quot;language-text&quot;&gt;venv&lt;/code&gt; ではインストールされてるPythonバージョンしか使えないはずなので別バージョンのPythonをインストールして、仮想環境を作らないとダメ&lt;br&gt;
これはあんまり自分も自信がなかったので、ちゃんと答えられたか不安&lt;br&gt;
&lt;a href=&quot;https://qiita.com/KRiver1/items/c1788e616b77a9bad4dd&quot;&gt;pyenv&lt;/a&gt; というのを使えばできるみたいです&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;TAはPython経験者なら誰でもウェルカムで、PyConJPの関係者や現地スタッフじゃなくても自由に参加できます。むしろPythonコミュニティを盛り上げるためにも、現地の人に積極的に参加してほしいみたいです。&lt;/p&gt;
&lt;p&gt;勉強会が終わったあとに、懇親会にも参加しました。
話すのが本気で苦手なので、周りの人の話を聞きながら過ごしてました。&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;https://paper-attachments.dropbox.com/s_1B91B0CFFFBAD933A6664A04B7143EA46F12E2D923A8684FBDFB51B432A69547_1581405558471_MVIMG_20200211_161110.jpg&quot;&gt;
&lt;figcaption&gt;Python Boot Camp &amp;#x3068; Connpass &amp;#x306E;&amp;#x30B9;&amp;#x30C6;&amp;#x30C3;&amp;#x30AB;&amp;#x30FC;&amp;#x3092;&amp;#x3082;&amp;#x3089;&amp;#x3063;&amp;#x305F;&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;参加して改めて、Pythonのコミュニティってすごいなって思った。そもそも全国的なコミュニティが長崎まで来て勉強会を開催するっていうのが、コミュニティの強さを表してますね。&lt;/p&gt;
&lt;p&gt;改めて、TAとして参加できたのはいい経験になったなぁと思う！
おつかれさまでした！&lt;/p&gt;</content:encoded></item><item><title><![CDATA[他人と比べても意味がない]]></title><description><![CDATA[…]]></description><link>https://blog.tkt989.info/2020/01/13/他人と比べても意味がない</link><guid isPermaLink="false">https://blog.tkt989.info/2020/01/13/他人と比べても意味がない</guid><pubDate>Sun, 12 Jan 2020 16:48:18 GMT</pubDate><content:encoded>&lt;p&gt;私は他人と比べて自分はダメだなぁとよく思いがちです。
「あんなことは自分にはできないなぁ」「自分はダメ人間だ、、、」みたいなことを考えてしまいます。
そういうことを考えても仕方ないとは思っているのですが、どうしてもやめられないです。
逆にプライドが高すぎるたり、自分自身を受け入れられていないということもあるのでしょう。
でも最近は本を読んだり、経験したりして少し考え方が変わってきたかなぁと思っています。&lt;/p&gt;
&lt;p&gt;確かに世の中には、信じられないくらいすごい人はゴロゴロいる。
世の中には、面白いWebサービスを作ってQiitaに投稿してバズっている人もいるし、中学生でRubyのコミッターになった人もいる。
私はプログラミングができるが、これも全体で見れば下から数えた方が速いくらいのレベルだと思う。
日本中で使われるようなアプリ、Webサービスを作ったこともないし、コンピューターの基礎技術も持っていない。
OSなんて作れないし、プログラミング言語も作れない、作ったことない。
そんな人たちと比べたら自分なんて、大したことない。&lt;/p&gt;
&lt;p&gt;私はカメラも少しかじっているが、それも趣味以下のレベルだろう。
プログラミングほど熱心な訳ではないので、当然だろう。&lt;/p&gt;
&lt;p&gt;囲碁や将棋もやったことはあるが、初心者に毛が生えた程度。
初段なんて持っていない、せいぜい級だ。&lt;/p&gt;
&lt;p&gt;人よりも何か優れていることなんて自分にはないのです。
やっぱり自分なんて大したことないんだ。&lt;/p&gt;
&lt;p&gt;でもこれって当たり前。
何故って、自分（1人）vs世界（ 約70億人）で戦っているから。
1人vs70億人なんだから負けて当たり前なんだ。&lt;/p&gt;
&lt;p&gt;そりゃぁ世の中にはすごい人はいっぱいいる。
発想力、創造力がずば抜けて高い人はいて、その人と私が戦ったらもちろん私が負ける。
信じられないくらいの知識、技術力を持っている人もいて、その人と私が戦ったらもちろん私が負ける。&lt;/p&gt;
&lt;p&gt;これは設定の仕方が間違っている。
人それぞれ得意な武器は違う
創造力という武器では勝てないけど、別の武器なら勝てるかもしれないのだ。&lt;/p&gt;
&lt;p&gt;他人と比べるときは、自分の得意な武器で比べた方がいいんだと思う。
プログラミングで戦うならば、私は世界ランクでは下から数えた方が早いだろう。
でもそこにカメラがそこそこ好きっていうのをプラスする。
「プログラミングができる＆カメラがそこそこ好き」という武器で戦うなら、私は少し上位にいきそうだ。
今度は、初心者程度の囲碁、将棋ができるをプラスしてみる。
「プログラミングができる＆カメラがそこそこ好き＆初心者程度の囲碁、将棋」が武器だったら、もっと戦えそうだ。&lt;/p&gt;
&lt;p&gt;要するに、一本の軸じゃなくて複数の軸で考えることが大切なんだろう
そう考えると少し楽になったかな&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Flutterの自作ライブラリを作って公開する方法]]></title><description><![CDATA[loading_textなるライブラリを公開したので、そのときに得た知識を残しておきます。 Flutterライブラリの作成 でFlutterライブラリのプロジェクトを作ることができます。
このコマンドで作られるプロジェクトはのみで、、などプラットフォーム非依存のdart…]]></description><link>https://blog.tkt989.info/2019/10/30/Flutterの自作ライブラリを作って公開する方法</link><guid isPermaLink="false">https://blog.tkt989.info/2019/10/30/Flutterの自作ライブラリを作って公開する方法</guid><pubDate>Wed, 30 Oct 2019 14:39:10 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://pub.dev/packages/loading_text&quot;&gt;loading_text&lt;/a&gt;なるライブラリを公開したので、そのときに得た知識を残しておきます。&lt;/p&gt;
&lt;h1&gt;Flutterライブラリの作成&lt;/h1&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;$ flutter create --template=package &amp;lt;name&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;でFlutterライブラリのプロジェクトを作ることができます。
このコマンドで作られるプロジェクトは&lt;code class=&quot;language-text&quot;&gt;lib&lt;/code&gt;のみで、&lt;code class=&quot;language-text&quot;&gt;android&lt;/code&gt;、&lt;code class=&quot;language-text&quot;&gt;ios&lt;/code&gt;などプラットフォーム非依存のdartコードだけ書けます。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;$ flutter create --template=plugin &amp;lt;name&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;でプラットフォームのコードも書けるようですが、今回は試していません。&lt;/p&gt;
&lt;h1&gt;公開の手順&lt;/h1&gt;
&lt;p&gt;まずは以下のコマンドでプロジェクトに不備がないかチェックします。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;$ pub publish --dry-run&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;私の環境では、&lt;code class=&quot;language-text&quot;&gt;pubspec.yml&lt;/code&gt;にhomepageとauthorの項目が足りないことで、
怒られました。&lt;/p&gt;
&lt;p&gt;修正したら、以下のコマンドで公開です。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;$ pub publish&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;途中、Googleアカウントでログインが求められるので、URLにアクセスしてログインしましょう。
しばらくすると、公開が完了します。&lt;/p&gt;
&lt;h1&gt;注意点&lt;/h1&gt;
&lt;p&gt;公開したパッケージは削除することはできないみたいです。&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Publishing is forever
Keep in mind that publishing is forever. As soon as you publish your package, users can depend on it. Once they start doing that, removing the package would break theirs. To avoid that, pub strongly discourages deleting packages. You can always upload new versions of your package, but old ones will continue to be available for users that aren’t ready to upgrade yet.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;適当翻訳では、「削除できてしまうとそのパッケージを使っているユーザーが困っちゃうから、させないようにしているよ。」です。
バージョンを上げて、上記コマンドを打ち直せば、新しいバージョンをアップロードできますが、古いものも残り続けるようです。&lt;/p&gt;
&lt;p&gt;非公開にすべき情報を上げないように注意しましょう。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[シェル芸勉強会に参加してきた]]></title><description><![CDATA[第44回シェル芸勉強会 福岡サテライト長崎分室に参加してきました。 参加者は私を含めて3人で、Youtubeでライブ配信されている東京の勉強会を見ながら参加します。
Twitterで各地サテライトのみなさんが実況したり、シェル芸Bot…]]></description><link>https://blog.tkt989.info/2019/10/27/シェル芸勉強会に参加してきた</link><guid isPermaLink="false">https://blog.tkt989.info/2019/10/27/シェル芸勉強会に参加してきた</guid><pubDate>Sun, 27 Oct 2019 07:54:53 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://shell-nagasaki.connpass.com/event/145800/&quot;&gt;第44回シェル芸勉強会 福岡サテライト長崎分室&lt;/a&gt;に参加してきました。&lt;/p&gt;
&lt;p&gt;参加者は私を含めて3人で、Youtubeでライブ配信されている東京の勉強会を見ながら参加します。
Twitterで各地サテライトのみなさんが実況したり、シェル芸Botにツイートしたりで、にぎやかな感じです。&lt;/p&gt;
&lt;p&gt;共有スペースでの開催。途中、他イベントの参加者の方がマイクを使いはじめて、Youtubeの音声が聞こえないので、全員イヤホン装着。
周りからは、3人集まって置きながらイヤホンつけて黙々とパソコンと向き合い、何をやってるんだろう、と思われただろうなぁ。&lt;/p&gt;
&lt;p&gt;とにかくシェル芸ははじまり、集中して問題に取り組みました&lt;/p&gt;
&lt;p&gt;問題一覧のページは&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://b.ueda.tech/?post=20191026_shellgei_44_q&quot;&gt;https://b.ueda.tech/?post=20191026_shellgei_44_q&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Q1&lt;/h2&gt;
&lt;p&gt;9x9の数独を列、行、ブロックに分けて表にする。
解けた。&lt;/p&gt;
&lt;blockquote class=&quot;twitter-tweet&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;cat sudoku | ruby -e &amp;#39;a=[];9.times{a&amp;lt;&amp;lt;gets.chomp};a.each.with_index{|v,i|v.chars.each_with_index{|w,j|puts &amp;quot;#{i} #{j} #{j/3} #{w}&amp;quot;}}&amp;#39; &lt;a href=&quot;https://twitter.com/hashtag/%E3%82%B7%E3%82%A7%E3%83%AB%E8%8A%B8?src=hash&amp;amp;ref_src=twsrc%5Etfw&quot;&gt;#シェル芸&lt;/a&gt;&lt;/p&gt;&amp;mdash; tkt989 (@tkt989_dev) &lt;a href=&quot;https://twitter.com/tkt989_dev/status/1187949184134959105?ref_src=twsrc%5Etfw&quot;&gt;October 26, 2019&lt;/a&gt;&lt;/blockquote&gt; &lt;script async src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;p&gt;各行、各文字ごとにループを回すだけでOKです。&lt;/p&gt;
&lt;h2&gt;Q2&lt;/h2&gt;
&lt;p&gt;Q1で作った表に加えて、数字が埋まっていないマスに入らない数字を列挙する。
解けず、、、&lt;/p&gt;
&lt;p&gt;惜しいところまでいった気はする。&lt;/p&gt;
&lt;h2&gt;Q3&lt;/h2&gt;
&lt;p&gt;逆にマスに入る可能性がある数字を列挙します。&lt;/p&gt;
&lt;blockquote class=&quot;twitter-tweet&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;cat b | ruby -e &amp;#39;a=[];81.times{a&amp;lt;&amp;lt;gets.chomp};a.each{|v|if v[6]!=&amp;quot;*&amp;quot; then puts v;else;puts &amp;quot;#{v[0..6]} #{((1..9).to_a-v[8..].split(&amp;quot; &amp;quot;).map(&amp;amp;:to_i)).join(&amp;quot; &amp;quot;)}&amp;quot;;end}&amp;#39;&lt;br&gt; &lt;a href=&quot;https://twitter.com/hashtag/%E3%82%B7%E3%82%A7%E3%83%AB%E8%8A%B8?src=hash&amp;amp;ref_src=twsrc%5Etfw&quot;&gt;#シェル芸&lt;/a&gt;&lt;/p&gt;&amp;mdash; tkt989 (@tkt989_dev) &lt;a href=&quot;https://twitter.com/tkt989_dev/status/1187959129995800581?ref_src=twsrc%5Etfw&quot;&gt;October 26, 2019&lt;/a&gt;&lt;/blockquote&gt; &lt;script async src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;p&gt;値が”*”の行に対して、行の8文字名以降をsplit(“ “)した配列を[1..9]から引くことで、
マスに入る数字を求めています。
if ~ then の thenは省略できるので必要ないですね。。。&lt;/p&gt;
&lt;h2&gt;Q4&lt;/h2&gt;
&lt;p&gt;Q3の答えから数独を解くという問題。
解けた？&lt;/p&gt;
&lt;blockquote class=&quot;twitter-tweet&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;Q4&lt;br&gt;cat c | ruby -e &amp;#39;a=[];81.times{a&amp;lt;&amp;lt;gets.chomp};s=&amp;quot;&amp;quot;;a.each_slice(3).each{|v|v.each{|w|if w[6]==&amp;quot;*&amp;quot; &amp;amp;&amp;amp; (w[8..]||[]).size==1;s+=w[8];else;s+=w[6];end};s+=&amp;quot;\n&amp;quot;};out=&amp;quot;&amp;quot;;s.split(&amp;quot;\n&amp;quot;).each_with_index{|v,i|out+=v;if i%3==2;out+=&amp;quot;\n&amp;quot;;end};puts out&amp;#39;&lt;/p&gt;&amp;mdash; tkt989 (@tkt989_dev) &lt;a href=&quot;https://twitter.com/tkt989_dev/status/1187970603531137025?ref_src=twsrc%5Etfw&quot;&gt;October 26, 2019&lt;/a&gt;&lt;/blockquote&gt; &lt;script async src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;p&gt;時間内では解けず、休憩中も書いてたのですが、次の問題が差し迫っていたのでコードがぐちゃぐちゃですね、、、&lt;/p&gt;
&lt;h2&gt;Q5&lt;/h2&gt;
&lt;p&gt;なぜか突然数独から積分の問題へ。
見た目で怖気づいて、解くのを最初から諦めてたのですが解説を聞くと、区画内の分割して関数の結果を足し合わせればいいだけなのでした。&lt;/p&gt;
&lt;h2&gt;Q6&lt;/h2&gt;
&lt;p&gt;解けた。&lt;/p&gt;
&lt;blockquote class=&quot;twitter-tweet&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;cat speech | ruby -e &amp;#39;s=[];15.times{s&amp;lt;&amp;lt;gets.chomp};f=open(&amp;quot;speech2&amp;quot;);puts &lt;a href=&quot;https://t.co/s4LQnQHr2E&quot;&gt;https://t.co/s4LQnQHr2E&lt;/a&gt;{|v|if v.empty?;f.gets.chomp;else;v;end}.join(&amp;quot;\n&amp;quot;)&amp;#39;&lt;br&gt; &lt;a href=&quot;https://twitter.com/hashtag/%E3%82%B7%E3%82%A7%E3%83%AB%E8%8A%B8?src=hash&amp;amp;ref_src=twsrc%5Etfw&quot;&gt;#シェル芸&lt;/a&gt;&lt;/p&gt;&amp;mdash; tkt989 (@tkt989_dev) &lt;a href=&quot;https://twitter.com/tkt989_dev/status/1187976736660606976?ref_src=twsrc%5Etfw&quot;&gt;October 26, 2019&lt;/a&gt;&lt;/blockquote&gt; &lt;script async src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;h2&gt;Q7&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;小問1&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote class=&quot;twitter-tweet&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;cat message | ruby -e &amp;#39;a=gets.chomp.split(&amp;quot; &amp;quot;).map(&amp;amp;:to_i);puts &lt;a href=&quot;https://t.co/3sU0Vq5iiE&quot;&gt;https://t.co/3sU0Vq5iiE&lt;/a&gt;{|n|n**200}.map{|n|n%437}.join(&amp;quot; &amp;quot;)&amp;#39;&lt;br&gt; &lt;a href=&quot;https://twitter.com/hashtag/%E3%82%B7%E3%82%A7%E3%83%AB%E8%8A%B8?src=hash&amp;amp;ref_src=twsrc%5Etfw&quot;&gt;#シェル芸&lt;/a&gt;&lt;/p&gt;&amp;mdash; tkt989 (@tkt989_dev) &lt;a href=&quot;https://twitter.com/tkt989_dev/status/1187980663179268096?ref_src=twsrc%5Etfw&quot;&gt;October 26, 2019&lt;/a&gt;&lt;/blockquote&gt; &lt;script async src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;p&gt;awkの場合では200乗でオーバーフローしてしまうみたいですが、rubyでは大丈夫ですね。
アホみたいに直球のやり方で解けました&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;小問2&lt;/strong&gt;&lt;/p&gt;
&lt;blockquote class=&quot;twitter-tweet&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;cat message | ruby -e &amp;#39;a=gets.chomp.split(&amp;quot; &amp;quot;).map(&amp;amp;:to_i);(0..200).each{|i|puts &lt;a href=&quot;https://t.co/3sU0Vq5iiE&quot;&gt;https://t.co/3sU0Vq5iiE&lt;/a&gt;{|n|n**i}.map{|n|n%437}.map{|n|n.chr(&amp;quot;UTF-8&amp;quot;)}.join(&amp;quot;&amp;quot;)}&amp;#39; | grep -E &amp;quot;^[A-Za-z_?]+$&amp;quot;&lt;br&gt; &lt;a href=&quot;https://twitter.com/hashtag/%E3%82%B7%E3%82%A7%E3%83%AB%E8%8A%B8?src=hash&amp;amp;ref_src=twsrc%5Etfw&quot;&gt;#シェル芸&lt;/a&gt;&lt;/p&gt;&amp;mdash; tkt989 (@tkt989_dev) &lt;a href=&quot;https://twitter.com/tkt989_dev/status/1187986171420217344?ref_src=twsrc%5Etfw&quot;&gt;October 26, 2019&lt;/a&gt;&lt;/blockquote&gt; &lt;script async src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;p&gt;rubyでは&lt;code class=&quot;language-text&quot;&gt;chr&lt;/code&gt;で数値を文字に変換できる。
引数に何もしてしないと、ASCII範囲外の数値のとき例外が発生したので、ASCIIと互換性のあるUTF-8にしました。
結果はASCIIなので、grepでそれっぽい文字だけの行だけ抽出。&lt;/p&gt;
&lt;p&gt;答えは&lt;code class=&quot;language-text&quot;&gt;unko_jyanai&lt;/code&gt;になりました💩&lt;/p&gt;
&lt;p&gt;この問題はRSA暗号が関係しているみたいです。
あとでYoutubeの録画を見よう。&lt;/p&gt;
&lt;h1&gt;感想&lt;/h1&gt;
&lt;p&gt;awkわからないので、rubyばっかり使っています。
すみません！
でも、主催者の方から、perlでもpythonでもシェルで動けば、シェル芸だよーとありがたい言葉をもらいました。&lt;/p&gt;
&lt;p&gt;今回で参加するのは3回目、問題も解けるようになって楽しかった。
やっぱり解けると気持ちいいですね。&lt;/p&gt;
&lt;p&gt;ひたすらシェルと向かい合うという濃密な数時間。
終わったあとは疲れる。
でも、凄い人に会えるのは刺激になる。
これからも機会があったら、参加しよう。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[スマホをガラスコーティングしてきた]]></title><description><![CDATA[使ってた保護ガラスが近接センサに干渉して、通話中に耳に当てなくても画面が真っ黒にになるのがイライラして、気になってたガラスコーティングをやってみた。 料金は300…]]></description><link>https://blog.tkt989.info/2019/08/25/スマホをガラスコーティングしてきた</link><guid isPermaLink="false">https://blog.tkt989.info/2019/08/25/スマホをガラスコーティングしてきた</guid><pubDate>Sun, 25 Aug 2019 13:24:04 GMT</pubDate><content:encoded>&lt;p&gt;使ってた保護ガラスが近接センサに干渉して、通話中に耳に当てなくても画面が真っ黒にになるのがイライラして、気になってたガラスコーティングをやってみた。&lt;/p&gt;
&lt;p&gt;料金は3000円。安いガラスフィルムを数枚分なら許せる納得できる値段ですね。&lt;/p&gt;
&lt;p&gt;結果ですが、何もしてない状態よりもツルツルしてる気がする？&lt;/p&gt;
&lt;p&gt;裸でもいいんですけど、裸で使うのはなんだかスマホに対して愛着が少ないんじゃないかと感じてくるじゃないですか。
やっぱりお金を払ったほうが、自分の生き血が入ったような気がします。
数千円でその気持ちが手に入るのならいいと思います。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Gitlabのスニペットを別のプロジェクトにコピーするツールを作った]]></title><description><![CDATA[gitlab-snippet-cloner - npm Gitlabのスニペットってチームで情報を共有するのに、すごく便利です。
ある日、Gitlab…]]></description><link>https://blog.tkt989.info/2019/08/13/Gitlabのスニペットを別のプロジェクトにコピーするツールを作った</link><guid isPermaLink="false">https://blog.tkt989.info/2019/08/13/Gitlabのスニペットを別のプロジェクトにコピーするツールを作った</guid><pubDate>Mon, 12 Aug 2019 15:05:50 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://www.npmjs.com/package/gitlab-snippet-cloner&quot;&gt;gitlab-snippet-cloner - npm&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Gitlabのスニペットってチームで情報を共有するのに、すごく便利です。
ある日、Gitlabのプロジェクトに溜まったスニペットを、別のプロジェクトに移したくなりました。&lt;/p&gt;
&lt;p&gt;プロジェクトのエクスポートを使って、スニペットはコピーできるみたいです。
が、これってたとえばクラウド版のGitlabからオンプレミスに移すときに使うものなのかなって思って、なんか違うなーと感じました。
なのでツールを作ってみました。&lt;/p&gt;
&lt;p&gt;インストールはnpmからどうぞ。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;$ &lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; -g gitlab-snippet-cloner&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;gitlab-snippet-cloner&lt;/code&gt;を実行して、
GitlabのURL、アクセストークン、コピー元プロジェクト名、コピー先プロジェクト名を
入力する。
するとまるっとスニペットがコピーされます。&lt;/p&gt;
&lt;p&gt;コピー先スニペットのAuthorがアクセストークンを生成したユーザーになってしまうので、そこは注意してください。
APIを操作して作っているので、仕方ない。。。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Admobを使っているFlutterアプリをiOSで起動するとFirebase Automatic Screen Reporting Is Enabled]]></title><description><![CDATA[みたいなエラーが発生して、アプリを起動するとすぐに終了してしまう。 にを追加して、を設定すると解決。]]></description><link>https://blog.tkt989.info/2019/07/21/Admobを使っているFlutterアプリをiOSで起動するとFirebase-Automatic-Screen-Reporting-Is-Enabled</link><guid isPermaLink="false">https://blog.tkt989.info/2019/07/21/Admobを使っているFlutterアプリをiOSで起動するとFirebase-Automatic-Screen-Reporting-Is-Enabled</guid><pubDate>Sun, 21 Jul 2019 07:07:45 GMT</pubDate><content:encoded>&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;Firebase automatic screen reporting is enabled.
Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable automatic screen reporting, set the flag &lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;みたいなエラーが発生して、アプリを起動するとすぐに終了してしまう。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;info.plist&lt;/code&gt;に&lt;code class=&quot;language-text&quot;&gt;FirebaseAutomaticScreenReportingEnabled&lt;/code&gt;を追加して、&lt;code class=&quot;language-text&quot;&gt;false&lt;/code&gt;を設定すると解決。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[invalid json payload received. unknown name のエラー解決]]></title><description><![CDATA[SwiftでGoogle Vision APIにリクエストを送ったら、タイトルのようなエラーが返ってきた。
エラーメッセージにはjsonの形式がおかしいみたいだけど、送っているjson…]]></description><link>https://blog.tkt989.info/2019/04/16/invalid-json-payload-received.-unknown-name-のエラー解決</link><guid isPermaLink="false">https://blog.tkt989.info/2019/04/16/invalid-json-payload-received.-unknown-name-のエラー解決</guid><pubDate>Tue, 16 Apr 2019 13:54:46 GMT</pubDate><content:encoded>&lt;p&gt;SwiftでGoogle Vision APIにリクエストを送ったら、タイトルのようなエラーが返ってきた。
エラーメッセージにはjsonの形式がおかしいみたいだけど、送っているjsonには特に変なところは見受けられなくて、試行錯誤してみたが長い時間詰まってしまった。&lt;/p&gt;
&lt;p&gt;改めてリクエスト処理を見直してみると、もしかして、、、な部分があってそこを直してみるとあっさり解決。&lt;/p&gt;
&lt;p&gt;ヘッダーに&lt;code class=&quot;language-text&quot;&gt;Content-Type: application/json&lt;/code&gt;を付けていなかったことが原因でした。&lt;/p&gt;
&lt;p&gt;普段はAndroidではRetrofit、iOSではAlamofireを使っていて、jsonを送るときはライブラリ側がヘッダーを追加してくれていたのですが、今回は&lt;code class=&quot;language-text&quot;&gt;URLSession&lt;/code&gt;を使っていて自分で追加しないといけないのでした。&lt;/p&gt;
&lt;p&gt;ライブラリを頼りすぎを実感。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[AiMeshに対応したルーターを試してみました]]></title><description><![CDATA[ASUS…]]></description><link>https://blog.tkt989.info/2019/02/09/AiMeshに対応したルーターを試してみました</link><guid isPermaLink="false">https://blog.tkt989.info/2019/02/09/AiMeshに対応したルーターを試してみました</guid><pubDate>Fri, 08 Feb 2019 15:58:49 GMT</pubDate><content:encoded>&lt;p&gt;ASUSさんが募集していたルーターのレンタルキャンペーンに当選したため、一ヶ月ほど貸し出していただけることができました。&lt;/p&gt;
&lt;p&gt;早速感想を書いていきます。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://d2mxuefqeaa7sj.cloudfront.net/s_50382A146B3462C34E3712812BEFA68CEA93D5C867276EFC6E77017BAF31B422_1549644922912_DSC_0157.JPG&quot;&gt;&lt;/p&gt;
&lt;p&gt;ゲーミングと聞いてゴッツイのを想像していたのですが、意外とコンパクトで今あるルーターと入れ替えても邪魔になりませんでした。デザインもそんなに派手じゃなくていい感じです。&lt;/p&gt;
&lt;p&gt;電源をつけたらルーターのSSIDが表示される。
初期設定はブラウザ上でもできますが、スマホアプリがあったので私はこちらでやりました。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://play.google.com/store/apps/details?id=com.asus.aihome&amp;#x26;hl=ja&quot;&gt;ASUS Router - Google Play のアプリ&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;2台の貸出だったので、初めてのメッシュWiFiを構築してみました。
今までもアクセスポイントは1階と2階で2台置いていて、SSIDを同じにすることで擬似的？にメッシュというかお互いの届いていないところを補間し合うようにしていたのですが、1階にいるのに2階のアクセスポイントにつながったりして、いまいち良くないなと思っていました。
しかし、メッシュWiFiだと補間が賢いようで、家の中すべてで快適にインターネットが使えました。&lt;/p&gt;
&lt;p&gt;PS4もリモートプレイをやってみたらサクサク動いている気がします。
スマホでYoutubeを見たときも、前のルーターではワンテンポ待つ感じだったのですが、これだすぐに再生される。ゲーミングだからレスポンスがいいのでしょうか。&lt;/p&gt;
&lt;p&gt;回線品質をアプリで計ってみました。&lt;/p&gt;
&lt;p&gt;こちらがASUSのルーターです。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://d2mxuefqeaa7sj.cloudfront.net/s_50382A146B3462C34E3712812BEFA68CEA93D5C867276EFC6E77017BAF31B422_1549644770577_Screenshot_20190209-014448.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;一方こちらが前に使っていたルーター。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://d2mxuefqeaa7sj.cloudfront.net/s_50382A146B3462C34E3712812BEFA68CEA93D5C867276EFC6E77017BAF31B422_1549644778508_Screenshot_20190209-014424.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;下のグラフでは最初に増えたあと、急激に下がっていますがASUSのはルーターの処理が安定しているのか、グラフの変動が少ないように思います。&lt;/p&gt;
&lt;p&gt;一ヶ月のレンタルでしたが、やっぱり高いルーターは高いなりにいいものなんだなと感じました。
ネット環境に妥協したくない方におすすめです。&lt;/p&gt;
&lt;p&gt;ASUS AiMesh対応ルーターにメッシュWi-Fiルーター ASUS Lyraシリーズが加わったそうです。
こちらは小さくて見た目が可愛いですね。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[CocoaPodsの使い方をメモ]]></title><description><![CDATA[cocoapods cocoapodsの使い方をメモ。 まずはでを生成します。
使うライブラリはこのの中に書きます。 次に使いたいライブラリをに記載する。
書く場所は の次に書く。
ユニットテストやUI…]]></description><link>https://blog.tkt989.info/2019/01/14/CocoaPodsの使い方をメモ</link><guid isPermaLink="false">https://blog.tkt989.info/2019/01/14/CocoaPodsの使い方をメモ</guid><pubDate>Mon, 14 Jan 2019 10:19:16 GMT</pubDate><content:encoded>&lt;h1&gt;cocoapods&lt;/h1&gt;
&lt;p&gt;cocoapodsの使い方をメモ。&lt;/p&gt;
&lt;p&gt;まずは&lt;code class=&quot;language-text&quot;&gt;init&lt;/code&gt;で&lt;code class=&quot;language-text&quot;&gt;Podfile&lt;/code&gt;を生成します。
使うライブラリはこの&lt;code class=&quot;language-text&quot;&gt;Podfile&lt;/code&gt;の中に書きます。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ pod init&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;次に使いたいライブラリを&lt;code class=&quot;language-text&quot;&gt;Podfile&lt;/code&gt;に記載する。
書く場所は&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;ruby&quot;&gt;&lt;pre class=&quot;language-ruby&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;target &lt;span class=&quot;token string&quot;&gt;&apos;&amp;lt;アプリ名&gt;&apos;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;do&lt;/span&gt;
   use_frameworks&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;
   &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;の次に書く。
ユニットテストやUIテストのみ使用するライブラリは別の場所に書くのですが、まぁたいていの場合はアプリ全体で使用すると思うのでここに書きます。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;pod&lt;/code&gt;に続けてライブラリ名やバージョンを指定します。ライブラリのページを見ればわかると思います。
例えばRxSwiftを使いたい場合は&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;ruby&quot;&gt;&lt;pre class=&quot;language-ruby&quot;&gt;&lt;code class=&quot;language-ruby&quot;&gt;target &lt;span class=&quot;token string&quot;&gt;&apos;MoneyCalculator&apos;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;do&lt;/span&gt;
    use_frameworks&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;
    
    pod &lt;span class=&quot;token string&quot;&gt;&apos;RxSwift&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;~&gt; 4.0&apos;&lt;/span&gt;
    pod &lt;span class=&quot;token string&quot;&gt;&apos;RxCocoa&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;~&gt; 4.0&apos;&lt;/span&gt;
      
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;な感じです。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Dartのnull演算子]]></title><description><![CDATA[dartを使ってたら見慣れないものを見つけたのでメモ。 とかは知っていたのですが、これは初めてみたので調べると、がのときだけ代入を行う演算子でした。 kotlinには無かったよね。
でもおんなじことを書けるから使いどきが難しそうだけど知っておこう。]]></description><link>https://blog.tkt989.info/2019/01/06/Dartのnull演算子</link><guid isPermaLink="false">https://blog.tkt989.info/2019/01/06/Dartのnull演算子</guid><pubDate>Sun, 06 Jan 2019 14:03:54 GMT</pubDate><content:encoded>&lt;p&gt;dartを使ってたら見慣れないものを見つけたのでメモ。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;x ??= &amp;quot;Hello&amp;quot;;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;??&lt;/code&gt;とか&lt;code class=&quot;language-text&quot;&gt;?.&lt;/code&gt;は知っていたのですが、これは初めてみたので調べると、&lt;code class=&quot;language-text&quot;&gt;x&lt;/code&gt;が&lt;code class=&quot;language-text&quot;&gt;null&lt;/code&gt;のときだけ代入を行う演算子でした。&lt;/p&gt;
&lt;p&gt;kotlinには無かったよね。
&lt;code class=&quot;language-text&quot;&gt;??&lt;/code&gt;でもおんなじことを書けるから使いどきが難しそうだけど知っておこう。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[2018年]]></title><description><![CDATA[…]]></description><link>https://blog.tkt989.info/2018/12/31/2018年</link><guid isPermaLink="false">https://blog.tkt989.info/2018/12/31/2018年</guid><pubDate>Mon, 31 Dec 2018 12:19:36 GMT</pubDate><content:encoded>&lt;p&gt;もういつの間にか今年も終わりそうです。
今年のこととか。。。&lt;/p&gt;
&lt;h1&gt;初めてライブに行けた&lt;/h1&gt;
&lt;p&gt;神聖かまってちゃんのライブに神戸まで行きました。
名前は知ってた。今年になってから曲を聞くようになってハマってしまいライブで生歌、メンバーを見てみたいなぁって思いが出てきて一日だけだったんですが、Net Generationフェスに行ってきました。
全く知らない土地を歩いたの良い経験になったよ。
似てるところもあれば違うところもあって（一番違うのは方言）歩くのが楽しかったです。
精神的に余裕がなかったため観光したりはあんまりできなかったので、次はもっと色々見て回りたいなぁって思いました。&lt;/p&gt;
&lt;h1&gt;仕事のこと&lt;/h1&gt;
&lt;p&gt;仕事はまだまだだけど、去年よりかは少し良くなってると思う。
いろいろ迷惑をかけてしまいましたが。。。
来年はもっと自立して周りの方々から信頼してもらえるようになりたいです。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[星を撮りにいきました]]></title><description><![CDATA[先日、近くの河原に写真を撮りにいきました。
1時間30分かけて星の軌跡が映るように撮影。 インターネットでいくつか記事を読むと、15〜3…]]></description><link>https://blog.tkt989.info/2018/11/23/星を撮りにいきました</link><guid isPermaLink="false">https://blog.tkt989.info/2018/11/23/星を撮りにいきました</guid><pubDate>Fri, 23 Nov 2018 13:35:15 GMT</pubDate><content:encoded>&lt;p&gt;先日、近くの河原に写真を撮りにいきました。
1時間30分かけて星の軌跡が映るように撮影。&lt;/p&gt;
&lt;p&gt;インターネットでいくつか記事を読むと、15〜30秒にシャッタースピードをあわせて数百枚くらい撮影、
その後撮った写真を比較明合成して作るようです。
連続撮影するには通常レリーズという道具を使うのですが、私は持っていなかったので、代わりに &lt;a href=&quot;https://play.google.com/store/apps/details?id=eu.chainfire.dslrcontroller&amp;#x26;hl=ja&quot;&gt;DSLR Controller&lt;/a&gt; というアプリで撮影しました。
カメラを接続すると、Androidデバイスが液晶付きのリモコンになります。接続するのにUSBホストケーブルが必要なので、持っていない場合は購入しましょう。
といっても100均で売ってあるので安いものです。アプリではライブビューが映るので星にピントを合わせるのも簡単でした。&lt;/p&gt;
&lt;iframe style=&quot;width:120px;height:240px;&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; src=&quot;//rcm-fe.amazon-adsystem.com/e/cm?lt1=_blank&amp;bc1=000000&amp;IS2=1&amp;bg1=FFFFFF&amp;fc1=000000&amp;lc1=0000FF&amp;t=blogtkt989inf-22&amp;language=ja_JP&amp;o=9&amp;p=8&amp;l=as4&amp;m=amazon&amp;f=ifr&amp;ref=as_ss_li_til&amp;asins=B005WNBLN0&amp;linkId=80dd3d6b314a0c3fd000769705265075&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;こういうのです、Amazonで買うより100均のほうがいいです。&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;夜8時前くらい家を出て車で、撮影場所の河原まで行きました。
河原の上には交通量多めの橋があるのですが、河原まで降りたらほとんど車は通らないのでヘッドライトが画面に入ってしまうこともありません。
なにより電信柱が無く空を見渡せるので星を見るには良い場所です。
20分くらい撮影ポジションを調整、最初は橋の街灯と共に星を写そうと思ったのですが、街灯を画面内に入れるとレンズフレアが発生してうまく撮れなかったので、
仕方なく堤防越しに写すように。&lt;/p&gt;
&lt;p&gt;そしていざ撮影開始。
最初はカメラのそばで待っていたのですが、寒くて我慢できなくなったので車の中に移動。
Kindleでマンガを読んでいました。
1時間以上待ち、マンガを読むのも飽きてきてカーナビでテレビ番組を見ながら時間を潰す。
どんな感じに写るのかな、楽しみ！&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;やっと撮影が終わりカメラを回収しにいき、寒いのですばやく車に戻り、写り具合を確認。&lt;br&gt;
しかし、カメラに表示されたのは星なんて写ってない、草むらはぼやけてしまって。
なにが起こったのか、よくよく見るとなんとレンズが結露しているではないですか。
そういえば撮り方をサイトで調べたときに結露に注意しましょうなんて書いてあったなぁ。
失敗したぁ。うぅ、気をつければよかった。&lt;/p&gt;
&lt;p&gt;幸運にも、結露しはじめたのは撮影にかけた時間のうち後のほうみたいで、ほとんどの写真はきれいに写ってくれていました。
下の画像はそれらの画像を合成して作った星の軌跡の写真です。&lt;/p&gt;
&lt;p&gt;&lt;a href=&apos;http://photohito.com/photo/8279791/&apos;&gt;&lt;img src=&quot;https://photohito.com/imageaid/?url=http%3A//photohito.k-img.com/uploads/photo131/user130889/3/6/36f4d502e9819e73269992abed061105/36f4d502e9819e73269992abed061105_m.jpg&quot; width=&quot;640&quot; height=&quot;427&quot; border=&quot;0&quot; alt=&quot;&amp;#x661F;&amp;#x7A7A;&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;1時間以上かけても軌跡は短いですね。2〜3時間だったらもっと線が長くなって豪華になるのだと思います。&lt;/p&gt;
&lt;p&gt;ちゃんと準備しておけばよかったなぁ。
次に挑戦するときは事前にしっかり準備しておこう。
インターネットで調べるとレンズを温めるヒーターもあるみたいです。
もしくは、予めしばらくカメラを寒い場所に置いてから、撮影すると結露が起きにくいみたいです。
ヒーター買いたいなぁ？買おうかな！&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Kotlin Coroutineをすこしかじってみた]]></title><description><![CDATA[簡単な使い方 のブロックがコルーチンとして実行されます。
コルーチンの中で使える関数はdelayなどがあります。 suspend function コルーチンの中でのみ実行できるメソッドをsuspend functionといいます。 のような標準ライブラリのsuspend…]]></description><link>https://blog.tkt989.info/2018/10/21/Kotlin-Coroutineをすこしかじってみた</link><guid isPermaLink="false">https://blog.tkt989.info/2018/10/21/Kotlin-Coroutineをすこしかじってみた</guid><pubDate>Sun, 21 Oct 2018 11:37:09 GMT</pubDate><content:encoded>&lt;h2&gt;簡単な使い方&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;fun task() {
  GlobalScope.launch {
    print(&amp;quot;World&amp;quot;)
  }
  print(&amp;quot;Hello&amp;quot;)
}

task() // =&amp;gt; &amp;quot;HelloWorld&amp;quot;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;GlobalScope.launch&lt;/code&gt;のブロックがコルーチンとして実行されます。
コルーチンの中で使える関数はdelayなどがあります。&lt;/p&gt;
&lt;h2&gt;suspend function&lt;/h2&gt;
&lt;p&gt;コルーチンの中でのみ実行できるメソッドをsuspend functionといいます。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;fun task() {
  GlobalScope.launch {
    delay(1000L)
  }
  delay(1000L) // コルーチン外なのでコンパイルエラー
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;delay&lt;/code&gt;のような標準ライブラリのsuspend functionもありますが、&lt;code class=&quot;language-text&quot;&gt;suspend&lt;/code&gt;を付けることで定義することもできます。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;suspend fun doReturnStatus(): Int {
  delay(1000L)
  return 200
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;suspend functionはコルーチンの中でしか呼べない、言い換えればsuspend functionの処理は常にコルーチン上で行われるのでsuspend functionの中で別のsuspend function(ここでは&lt;code class=&quot;language-text&quot;&gt;delay&lt;/code&gt;)を呼ぶことができます。&lt;/p&gt;
&lt;h2&gt;async&lt;/h2&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;GlobalScope.launch&lt;/code&gt;と似ているが&lt;code class=&quot;language-text&quot;&gt;async&lt;/code&gt;は&lt;code class=&quot;language-text&quot;&gt;Deferred&lt;/code&gt;を返す。
&lt;code class=&quot;language-text&quot;&gt;Deferred.await()&lt;/code&gt;で結果を待つ。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;GlobalScope.launch {
    val task3 = async {
        delay(1000L)
        return@async &amp;quot;3&amp;quot;
    }
    val task2 = async {
        delay(2000L)
        return@async &amp;quot;2&amp;quot;
    }

    println(&amp;quot;${task2.await()}&amp;quot;)
    println(&amp;quot;${task3.await()}&amp;quot;)
}
println(&amp;quot;1&amp;quot;)

// Output:
// 1
// 2
// 3&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;最初は&lt;code class=&quot;language-text&quot;&gt;launch&lt;/code&gt;によってコルーチンが始まります。
しかし、メインスレッドは止まらないので直後の&lt;code class=&quot;language-text&quot;&gt;println(``&amp;quot;``1``&amp;quot;``)&lt;/code&gt;が実行されます。
その後、コルーチンのブロックが実行されます。
&lt;code class=&quot;language-text&quot;&gt;delay&lt;/code&gt;秒数により、task3のほうが早く終わりますが、task2の&lt;code class=&quot;language-text&quot;&gt;await()&lt;/code&gt;を呼んでいるので、task2の終了を待ちます。
その結果、出力は1,2,3になります。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[ClosedXMLの簡単な使い方]]></title><description><![CDATA[…]]></description><link>https://blog.tkt989.info/2018/10/08/ClosedXMLの簡単な使い方</link><guid isPermaLink="false">https://blog.tkt989.info/2018/10/08/ClosedXMLの簡単な使い方</guid><pubDate>Sun, 07 Oct 2018 16:23:40 GMT</pubDate><content:encoded>&lt;h2&gt;ワークブック読み込み&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;    &lt;span class=&quot;token class-name&quot;&gt;IXLWorkbook&lt;/span&gt; workbook &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;XLWorkbook&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;@&quot;&amp;lt;ファイルパス&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;これでワークブックが読み込めます。
セルもワークシートもワークブックを使って取得します。&lt;/p&gt;
&lt;h2&gt;シート読み込み&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;    &lt;span class=&quot;token keyword&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;IXLWorkbook&lt;/span&gt; workbook &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;XLWorkbook&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;@&quot;&amp;lt;ファイルパス&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;IXLWorksheet&lt;/span&gt; sheetIndex &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; workbook&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Worksheet&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// インデックスで取得&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;IXLWorksheet&lt;/span&gt; sheetName  &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; workbook&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Worksheet&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;シート1&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// シート名で取得&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;セルを取得&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;charp&quot;&gt;&lt;pre class=&quot;language-charp&quot;&gt;&lt;code class=&quot;language-charp&quot;&gt;    sheet.Sheet(1, 1); // 座標から取得。1始まりに注意
    sheet.Sheet(&amp;quot;A1&amp;quot;); // 文字列から取得

ワークシートのオブジェクトからセルを取得できます。&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;行を取得&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;    &lt;span class=&quot;token class-name&quot;&gt;IXLRow&lt;/span&gt; row &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; sheet&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Row&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// 行番号から取得&lt;/span&gt;
    row&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Cell&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Rowからセルを取得することもできる&lt;/span&gt;
    
    &lt;span class=&quot;token comment&quot;&gt;// Rows()で行一覧を取得できる&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;IXLRow&lt;/span&gt; row &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; sheet&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Rows&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;/* ... */&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;列を取得&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;    &lt;span class=&quot;token class-name&quot;&gt;IXLColumn&lt;/span&gt; column &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; sheet&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Column&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// 列番号から取得&lt;/span&gt;
    column&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Cell&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// Columnからセルを取得することもできる&lt;/span&gt;
    
    &lt;span class=&quot;token comment&quot;&gt;// Column()で行一覧を取得できる&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;IXLColumn&lt;/span&gt; column &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; sheet&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Columns&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;/* ... */&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;使用しているセル一覧を取得&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;    &lt;span class=&quot;token keyword&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;IXLCell&lt;/span&gt; cell &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; sheet&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;CellsUsed&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;/* ... */&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;CellsUsed()&lt;/code&gt;で使用しているセル（値が入っているなど）を取得することができます。&lt;/p&gt;
&lt;h2&gt;文字列を含んだセルを探す&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;    &lt;span class=&quot;token comment&quot;&gt;// &quot;abc&quot;を含んだセルを探す&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;IXLCell&lt;/span&gt; cell &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; sheet&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Search&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;abc&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;/* ... */&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;セルの背景色を変える&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;chsarp&quot;&gt;&lt;pre class=&quot;language-chsarp&quot;&gt;&lt;code class=&quot;language-chsarp&quot;&gt;    cell.Style.Fill.BackgroundColor = XLColor.FromArgb(255, 0, 0);&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;保存&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;    workbook&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Save&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;別名で保存&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;    workbook&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;SaveAs&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;@&quot;&amp;lt;保存先&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content:encoded></item><item><title><![CDATA[楽器未経験なのにDTMをやりはじめた]]></title><description><![CDATA[今まで作曲をやってみたいとおもっていました。
音楽できる人ってかっこいいし、いろいろ表現できたりするのもおもしろそうです。
そんなせいで音楽理論とかGaragebandの使い方を勉強しておりました。
今までほとんど楽器を弾いたことなんてない、音楽とは無縁の人生なんですけどね。…]]></description><link>https://blog.tkt989.info/2018/09/17/楽器未経験なのにDTMをやりはじめた</link><guid isPermaLink="false">https://blog.tkt989.info/2018/09/17/楽器未経験なのにDTMをやりはじめた</guid><pubDate>Mon, 17 Sep 2018 13:31:15 GMT</pubDate><content:encoded>&lt;div class=&quot;gatsby-resp-iframe-wrapper&quot; style=&quot;padding-bottom: 56.25%; position: relative; height: 0; overflow: hidden; margin-bottom: 1.0725rem&quot; &gt; &lt;iframe src=&quot;https://www.youtube.com/embed/5MHWlSitD6E&quot; frameborder=&quot;0&quot; allow=&quot;autoplay; encrypted-media&quot; allowfullscreen style=&quot; position: absolute; top: 0; left: 0; width: 100%; height: 100%; &quot;&gt;&lt;/iframe&gt; &lt;/div&gt;
&lt;p&gt;今まで作曲をやってみたいとおもっていました。
音楽できる人ってかっこいいし、いろいろ表現できたりするのもおもしろそうです。
そんなせいで音楽理論とかGaragebandの使い方を勉強しておりました。
今までほとんど楽器を弾いたことなんてない、音楽とは無縁の人生なんですけどね。&lt;/p&gt;
&lt;p&gt;2週間くらいかけて、なんとか聞けるというか、わずかながらでも楽曲といえそうなレベルのものができた（と思っている）ので公開してみようと思う。&lt;/p&gt;
&lt;p&gt;テーマなんて特にない！
作曲理論だけで作った曲だ！&lt;/p&gt;</content:encoded></item><item><title><![CDATA[グラバー園に行ってきた]]></title><description><![CDATA[8月1…]]></description><link>https://blog.tkt989.info/2018/08/19/グラバー園に行ってきた</link><guid isPermaLink="false">https://blog.tkt989.info/2018/08/19/グラバー園に行ってきた</guid><pubDate>Sun, 19 Aug 2018 08:20:11 GMT</pubDate><content:encoded>&lt;p&gt;8月14日にグラバー園に行ってきた。
長崎県に住んでいるのに一回も行ったことがなかったのでカメラ持ってパシャパシャしてきました。
暑かったけど、園内にクーラーが効いてる建物があったり、木陰が多かったりで意外と過ごしやすかったです。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://d2mxuefqeaa7sj.cloudfront.net/s_57DC8A8EFD9A7E9BC4B029C0F765CBB6D85195C46392C17130937CEEA6246E04_1534666512191_IMG_7144.jpg&quot;&gt;&lt;/p&gt;
&lt;p&gt;天主堂&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://d2mxuefqeaa7sj.cloudfront.net/s_57DC8A8EFD9A7E9BC4B029C0F765CBB6D85195C46392C17130937CEEA6246E04_1534666584313_IMG_7168.jpg&quot;&gt;&lt;/p&gt;
&lt;p&gt;港を一望できました。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://d2mxuefqeaa7sj.cloudfront.net/s_57DC8A8EFD9A7E9BC4B029C0F765CBB6D85195C46392C17130937CEEA6246E04_1534666592510_IMG_7170.jpg&quot;&gt;&lt;/p&gt;
&lt;p&gt;お屋敷&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://d2mxuefqeaa7sj.cloudfront.net/s_57DC8A8EFD9A7E9BC4B029C0F765CBB6D85195C46392C17130937CEEA6246E04_1534666596281_IMG_7198.jpg&quot;&gt;&lt;/p&gt;
&lt;p&gt;大砲&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://d2mxuefqeaa7sj.cloudfront.net/s_57DC8A8EFD9A7E9BC4B029C0F765CBB6D85195C46392C17130937CEEA6246E04_1534666632816_IMG_7229.jpg&quot;&gt;&lt;/p&gt;
&lt;p&gt;グラバーさん&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://d2mxuefqeaa7sj.cloudfront.net/s_57DC8A8EFD9A7E9BC4B029C0F765CBB6D85195C46392C17130937CEEA6246E04_1534666639150_IMG_7222.jpg&quot;&gt;&lt;/p&gt;
&lt;p&gt;有名&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://d2mxuefqeaa7sj.cloudfront.net/s_57DC8A8EFD9A7E9BC4B029C0F765CBB6D85195C46392C17130937CEEA6246E04_1534666644394_IMG_7277.jpg&quot;&gt;&lt;/p&gt;
&lt;p&gt;帰り道&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://d2mxuefqeaa7sj.cloudfront.net/s_57DC8A8EFD9A7E9BC4B029C0F765CBB6D85195C46392C17130937CEEA6246E04_1534666648008_IMG_7280.jpg&quot;&gt;&lt;/p&gt;
&lt;p&gt;駅から&lt;/p&gt;
&lt;p&gt;最近カメラ熱が出てきたのでまた写真撮りにいきたい。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rust入門 2 基本的な文法]]></title><description><![CDATA[本当は数当てゲームなどを作る章が続いているのですが、順番が前後させて文法を先に学んでおきます。 変数 変数の宣言は以下のようにする。 型を示すこともできる。 Rust…]]></description><link>https://blog.tkt989.info/2018/08/04/Rust入門-2-基本的な文法</link><guid isPermaLink="false">https://blog.tkt989.info/2018/08/04/Rust入門-2-基本的な文法</guid><pubDate>Sat, 04 Aug 2018 12:03:52 GMT</pubDate><content:encoded>&lt;p&gt;本当は数当てゲームなどを作る章が続いているのですが、順番が前後させて文法を先に学んでおきます。&lt;/p&gt;
&lt;h1&gt;変数&lt;/h1&gt;
&lt;p&gt;変数の宣言は以下のようにする。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;let num = 10;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;型を示すこともできる。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;let num: i32 = 100;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Rustでは変数はデフォルトでイミュータブルになっていて、書き換えることはできない。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;let x = 5;
x = 10; // コンパイルエラー&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;ミュータブルにしたいときは&lt;code class=&quot;language-text&quot;&gt;mut&lt;/code&gt;を付ける&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;let mut x = 5;
x = 10;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;また、未初期化の変数を宣言することはできるが、使用しようとするとコンパイルエラーになる。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;let x: i32;

println!(&amp;quot;{}&amp;quot;, x); // コンパイルエラー&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;プリミティブ型&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;bool&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;おなじみの真偽値。true or false&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;let changed: bool = true;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;char&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;文字を表す。ユニコードに対応している。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;let ch: char = &amp;#39;a&amp;#39;;
let poop: char = &amp;#39;💩&amp;#39;;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;i8&lt;/li&gt;
&lt;li&gt;i16&lt;/li&gt;
&lt;li&gt;i32&lt;/li&gt;
&lt;li&gt;i64&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;符号あり整数型。数値はビット数を表す。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;let x: i32 = 1234;
let y: i16 = -100;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;u8&lt;/li&gt;
&lt;li&gt;u16&lt;/li&gt;
&lt;li&gt;u32&lt;/li&gt;
&lt;li&gt;u64&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;符号なし整数型。こちらも数値はビット数を表す。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;let x: u32 = 1234;
let y: u16 = -100; // コンパイルエラー&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;isize&lt;/li&gt;
&lt;li&gt;usize&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;実行環境のポインタサイズで変わる型。32bitではi32 or u32、64bitではi64 or u64になるということかな。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;f32&lt;/li&gt;
&lt;li&gt;f64&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;浮動小数点数型。数値は単精度か倍精度かを表す。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;let pi: f32 = 3.1415926535;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;配列&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;おなじみの配列。要素の型はすべて同じにしないといけない。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;let a: [i32; 3] = [1, 2, 3];
let x = a[0] + a[1]; // x = 3&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;タプル&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;固定サイズのリスト。要素の型は異なっても良い。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;let t: (i32, f32) = (3 0.141592);
let x = t.0 + 3;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;t.0&lt;/code&gt;のようにタプルのインデックスを指定することで要素にアクセスすることができる。&lt;/p&gt;
&lt;h1&gt;関数&lt;/h1&gt;
&lt;p&gt;関数は以下のように書く。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;fn square(x: i32) -&amp;gt; i32 {
    return x * x;
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;戻り値がない場合は以下のようになにも指定しない。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;fn greet() {
    println!(&amp;quot;hello&amp;quot;);
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;セミコロンが付いていない行を最後に書いた場合、式の結果が関数の戻り値になる。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;fn square(x: i32) -&amp;gt; i32 {
    x * x
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;関数を変数に代入する関数ポインタを使うこともできる。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;fn cube(x: i32) -&amp;gt; i32 {
    x * x * x
}

fn main() {
    let f: fn(i32) -&amp;gt; i32 = cube;
    println!(&amp;quot;{}&amp;quot;, f(3)); // =&amp;gt; 27&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;コメント&lt;/h1&gt;
&lt;p&gt;C言語系のコメントの書き方がそのまま使える。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;// 一行コメント
let x = 10; // 一行コメント
/*
複数行コメント
abc
def
*/&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;これらに加えてドキュメント用のコメントを書くことができる。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;/// 二乗した値を返す
/// 
/// # 実行例
/// ```
/// square(5); // 25
/// ```
fn square(x: i32) -&amp;gt; i32 {
    x * x
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;///&lt;/code&gt;を使って関数などのドキュメントコメントを書ける。
このコメントの中ではMarkdownを使うことができる。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;///&lt;/code&gt;はドキュメントのあとに続く要素にコメントがつけられるが、&lt;code class=&quot;language-text&quot;&gt;//!&lt;/code&gt;を使えばファイル全体やモジュールなどにコメントをつけられる。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;//! # 計算用ライブラリ
//!
//! 数値計算の関数を提供します。
//! ...&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;if&lt;/h1&gt;
&lt;p&gt;他の言語と比べてほとんど違いはない。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;let x = 3;
let valid = true;

if x == 3 {
    println!(&amp;quot;x is 3&amp;quot;);
}

if !valid {
    println!(&amp;quot;valid is false&amp;quot;);
} else {
    println!(&amp;quot;valid is true&amp;quot;);
}

// x is 3
// valid is true&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;加えて、rustではifは文ではなく式になるので以下のようにifの結果を代入したりすることができる。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;let x = 5;

let y = if x == 5 { 10 } else { 15 }; // y = 10&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;ループ&lt;/h1&gt;
&lt;p&gt;ループの構文には以下の3つがある。&lt;/p&gt;
&lt;h2&gt;loop&lt;/h2&gt;
&lt;p&gt;無限ループを実行する。&lt;code class=&quot;language-text&quot;&gt;break&lt;/code&gt;で途中で抜けることができる。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;let mut i = 0;
loop {
    i += 1;
    println!(&amp;quot;i is {}&amp;quot;, i);
    if i == 10 {
        break;
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;while&lt;/h2&gt;
&lt;p&gt;こちらはC言語系とほぼ同じです。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;let mut i = 0;
while i != 9 {
    i += 1;
    println!(&amp;quot;i is {}&amp;quot;, i);
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;無限ループを書くときは&lt;code class=&quot;language-text&quot;&gt;while true { … }&lt;/code&gt;ではなく、&lt;code class=&quot;language-text&quot;&gt;loop { … }&lt;/code&gt;を使うが推奨されている。&lt;/p&gt;
&lt;h2&gt;for&lt;/h2&gt;
&lt;p&gt;以下のように開始値と終了値を指定して書く。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;for i in 0..10 {
    println!(&amp;quot;i is {}&amp;quot;, i);
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;0から9までの数字を表示します。&lt;/p&gt;
&lt;p&gt;ループの中では&lt;code class=&quot;language-text&quot;&gt;break&lt;/code&gt;で抜けたり、&lt;code class=&quot;language-text&quot;&gt;continue&lt;/code&gt;で次のループに移ることができる。
これはC言語系と同じですね。&lt;/p&gt;
&lt;p&gt;その他にループにラベルをつけることができる。
これは二重ループから一気に抜けるときに便利です。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;&amp;#39;outer: for y in 0..10 {
    for x in 0..10 {
        if x % 5 == 0 {
            break &amp;#39;outer;
        }
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;break &amp;#39;outer&lt;/code&gt;で一気に外側の&lt;code class=&quot;language-text&quot;&gt;for&lt;/code&gt;から抜けられます。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[なんかあっという間にQiitaのContributionが100を超えてた]]></title><description><![CDATA[数日前に書いたicrawlerの記事がヒットして「いいね」がたくさんついていた。
以前はせいぜい一桁くらいしかついていない記事がばっかりなのに、なんとこれは100を超えている。
しかもトレンドにも載っている。 そのおかげで、Contributionが急上昇。半年くらい掛けて5…]]></description><link>https://blog.tkt989.info/2018/07/17/なんかあっという間にQiitaのContributionが100を超えてた</link><guid isPermaLink="false">https://blog.tkt989.info/2018/07/17/なんかあっという間にQiitaのContributionが100を超えてた</guid><pubDate>Tue, 17 Jul 2018 13:22:25 GMT</pubDate><content:encoded>&lt;p&gt;数日前に書いた&lt;a href=&quot;https://qiita.com/tkt989/items/84c6581dfa1d9a42dc2d&quot;&gt;icrawlerの記事&lt;/a&gt;がヒットして「いいね」がたくさんついていた。
以前はせいぜい一桁くらいしかついていない記事がばっかりなのに、なんとこれは100を超えている。
しかもトレンドにも載っている。&lt;/p&gt;
&lt;p&gt;そのおかげで、Contributionが急上昇。半年くらい掛けて50程度というスローペースで増えていたのだが、たった一日で180まで増えました。
なんだがすごくドキドキしてしまいました。&lt;/p&gt;
&lt;p&gt;Qiitaを使ってるのはアウトプットやメモのためで、増やすために書いてるわけではないのだが、この光景を見るとやっぱり嬉しい。&lt;/p&gt;
&lt;p&gt;紹介しただけの記事でここまで反応を貰えるとは思わず、自分が作ったわけでもないものでこんなふうになって少し申し訳ないというかそんな気持ちです。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Rust入門 1]]></title><description><![CDATA[下のサイトを見ながら勉強。
http://rust-lang-ja.github.io/the-rust-programming-language-ja/1.6/book/README.html Cloud9のマシンで実行しています。 インストール HelloWorld…]]></description><link>https://blog.tkt989.info/2018/07/07/Rust入門-1</link><guid isPermaLink="false">https://blog.tkt989.info/2018/07/07/Rust入門-1</guid><pubDate>Sat, 07 Jul 2018 03:00:33 GMT</pubDate><content:encoded>&lt;p&gt;下のサイトを見ながら勉強。
&lt;a href=&quot;http://rust-lang-ja.github.io/the-rust-programming-language-ja/1.6/book/README.html&quot;&gt;http://rust-lang-ja.github.io/the-rust-programming-language-ja/1.6/book/README.html&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Cloud9のマシンで実行しています。&lt;/p&gt;
&lt;h1&gt;インストール&lt;/h1&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;$ curl https://sh.rustup.rs -sSf | sh
info: downloading installer

Welcome to Rust!

This will download and install the official compiler for the Rust programming 
language, and its package manager, Cargo.

It will add the cargo, rustc, rustup and other commands to Cargo&amp;#39;s bin 
directory, located at:

  /home/ubuntu/.cargo/bin

This path will then be added to your PATH environment variable by modifying the
profile file located at:

  /home/ubuntu/.profile

You can uninstall at any time with rustup self uninstall and these changes will
be reverted.

Current installation options:

   default host triple: x86_64-unknown-linux-gnu
     default toolchain: stable
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation


info: syncing channel updates for &amp;#39;stable-x86_64-unknown-linux-gnu&amp;#39;
info: latest update on 2018-06-21, rust version 1.27.0 (3eda71b00 2018-06-19)
info: downloading component &amp;#39;rustc&amp;#39;
info: downloading component &amp;#39;rust-std&amp;#39;
info: downloading component &amp;#39;cargo&amp;#39;
info: downloading component &amp;#39;rust-docs&amp;#39;
info: installing component &amp;#39;rustc&amp;#39;
info: installing component &amp;#39;rust-std&amp;#39;
info: installing component &amp;#39;cargo&amp;#39;
info: installing component &amp;#39;rust-docs&amp;#39;
info: default toolchain set to &amp;#39;stable&amp;#39;

  stable installed - rustc 1.27.0 (3eda71b00 2018-06-19)


Rust is installed now. Great!

To get started you need Cargo&amp;#39;s bin directory ($HOME/.cargo/bin) in your PATH 
environment variable. Next time you log in this will be done automatically.

To configure your current shell run source $HOME/.cargo/env&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;HelloWorld&lt;/h1&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;main.rs&lt;/code&gt;を作成&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;fn main() {
    println!(&amp;quot;Hello,world!&amp;quot;);
}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;rustc&lt;/code&gt;コマンドでコンパイル&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;$ rustc main.rs&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;そしたら実行ファイルの&lt;code class=&quot;language-text&quot;&gt;main&lt;/code&gt;が生成されるので実行&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;$ ./main
Hello,world!&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Cargo&lt;/h1&gt;
&lt;p&gt;CargoはRustのビルドツールです。
作ったソースをcargoに対応させるには以下のような構成にする必要がある。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;$ tree
.
├── Cargo.toml
└── src
    └── main.rs&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;ソースはすべて&lt;code class=&quot;language-text&quot;&gt;src&lt;/code&gt;ディレクトリに入れる必要がある。
&lt;code class=&quot;language-text&quot;&gt;Cargo.toml&lt;/code&gt;は以下のようなないようにする。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;[package]

name = &amp;quot;プロジェクト名&amp;quot;
version = &amp;quot;バージョン&amp;quot;
authors = [&amp;quot;ユーザー名 &amp;lt;メールアドレス&amp;gt;&amp;quot;]&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;cargo build&lt;/code&gt;を実行すればビルドされて&lt;code class=&quot;language-text&quot;&gt;target/debug&lt;/code&gt;に実行ファイルが生成されます。
&lt;code class=&quot;language-text&quot;&gt;cargo run&lt;/code&gt;でも実行することができます。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/hello_world`
Hello,world!&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;ちなみにこのプロジェクト構成は自分で作らなくても&lt;code class=&quot;language-text&quot;&gt;cargo new&lt;/code&gt;コマンドで作成することができる。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;$ cargo new hello_world --bin&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;--bin&lt;/code&gt;はプロジェクトがライブラリではなく実行ファイルであることを示している。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[LaravelをHerokuにデプロイする]]></title><description><![CDATA[前提 以下のサイトでコマンドをインストールしてでログインを行い、使えるようにしておきましょう。
https://devcenter.heroku.com/articles/heroku-cli#download-and-install DBはPostgreSQL…]]></description><link>https://blog.tkt989.info/2018/06/27/LaravelをHerokuにデプロイする</link><guid isPermaLink="false">https://blog.tkt989.info/2018/06/27/LaravelをHerokuにデプロイする</guid><pubDate>Wed, 27 Jun 2018 12:52:20 GMT</pubDate><content:encoded>&lt;h1&gt;前提&lt;/h1&gt;
&lt;p&gt;以下のサイトで&lt;code class=&quot;language-text&quot;&gt;heroku&lt;/code&gt;コマンドをインストールして&lt;code class=&quot;language-text&quot;&gt;heroku login&lt;/code&gt;でログインを行い、使えるようにしておきましょう。
&lt;a href=&quot;https://devcenter.heroku.com/articles/heroku-cli#download-and-install&quot;&gt;https://devcenter.heroku.com/articles/heroku-cli#download-and-install&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;DBはPostgreSQLを使います。&lt;/p&gt;
&lt;h1&gt;Procfileを作る&lt;/h1&gt;
&lt;p&gt;Procfileはheroku上にデプロイされたときに実行するコマンドを指定するものです。
これを使っておかないとデプロイしてもエラーになってアプリを起動できません。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;# Procfile
web: vendor/bin/heroku-php-apache2 public/&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;アプリを登録&lt;/h1&gt;
&lt;h2&gt;herokuコマンドから&lt;/h2&gt;
&lt;p&gt;まずは&lt;code class=&quot;language-text&quot;&gt;heroku&lt;/code&gt;コマンドでアプリを登録する必要があるので、Laravelのプロジェクトディレクトリに移動して&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;$ heroku create &amp;lt;アプリの名前&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;を実行して作りましょう。
&lt;code class=&quot;language-text&quot;&gt;git init&lt;/code&gt;からremoteの登録までやってくれます。&lt;/p&gt;
&lt;h2&gt;Webから&lt;/h2&gt;
&lt;p&gt;Webのダッシュボードから登録することもできますが、gitの設定を自分でやらないといけません。
Laravelのプロジェクトディレクトリから&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;$ git init
$ heroku git:remote -a &amp;lt;アプリの名前&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;を実行します。
もしすでにgitを使っているなら最後のコマンドだけで十分です。&lt;/p&gt;
&lt;h1&gt;PostgreSQLを設定&lt;/h1&gt;
&lt;p&gt;herokuでPostgreSQLやMySQLなどを使うにはaddonとして追加する必要があります。ほかにもいろいろ便利なアドオンがあるそうなのですが、今回はPostgreSQLのみを追加します。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;$ heroku addons:create heroku-postgresql:hobby-dev&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Web上のアプリ管理画面にいくとAddonが追加されています。&lt;/p&gt;
&lt;p&gt;次はLaravelでPostgreSQLを使うように設定します。
開発時には&lt;code class=&quot;language-text&quot;&gt;.env&lt;/code&gt;を書き換えてDBを変えていたかもしれませんが、このファイルは&lt;code class=&quot;language-text&quot;&gt;.gitignore&lt;/code&gt;に載っていてpushされませんので、herokuのサーバーに環境変数を設定します。&lt;/p&gt;
&lt;p&gt;上記の画面のHeroku Postgresをクリックして以下の画面を開き、&lt;code class=&quot;language-text&quot;&gt;Settings&lt;/code&gt;  → &lt;code class=&quot;language-text&quot;&gt;View Credentials&lt;/code&gt; を開いてDBの設定情報を表示しましょう。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://d2mxuefqeaa7sj.cloudfront.net/s_76B38BB7F01D58DEEAFB302A5EFEB5ACD0F38F6113786E76A8D460B05B8F35C7_1530102887087_heroku-ss1.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;また、Laravelプロジェクトでは&lt;code class=&quot;language-text&quot;&gt;APP_KEY&lt;/code&gt;を環境変数として登録する必要があるのでそれも追加。&lt;/p&gt;
&lt;p&gt;それぞれの情報を&lt;code class=&quot;language-text&quot;&gt;heroku&lt;/code&gt;コマンドから登録します。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;$ heroku config:set DB_CONNECTION=pgsql \
                    DB_HOST=&amp;lt;Host&amp;gt; \
                    DB_PORT=&amp;lt;Port&amp;gt; \
                    DB_DATABASE=&amp;lt;Database&amp;gt; \
                    DB_USERNAME=&amp;lt;User&amp;gt; \
                    DB_PASSWORD=&amp;lt;Password&amp;gt; \
                    APP_KEY=$(php artisan key:generate --show)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;デプロイする&lt;/h1&gt;
&lt;p&gt;herokuへのデプロイの方法はgitでpushするだけです。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;$ git add .
$ git commit -m &amp;quot;update&amp;quot;
$ git push heroku master&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;するといつものgitのログとは違いずらずらと出てくるので終わるまで見つめましょう。
見つめ終わったらデプロイ完了です。&lt;/p&gt;
&lt;p&gt;herokuアプリの管理画面から&lt;code class=&quot;language-text&quot;&gt;Open App&lt;/code&gt;を開けばLaravelアプリが迎えてくれるでしょう、簡単。&lt;/p&gt;
&lt;h1&gt;マイグレート、その他初期設定&lt;/h1&gt;
&lt;p&gt;herokuアプリは生成されてばかり、まっしろの状態です。
もちろんDBも空っぽなので&lt;code class=&quot;language-text&quot;&gt;migrate&lt;/code&gt;を実行しましょう。
初期設定が必要なライブラリを使っている場合もコマンドを実行しておいてください。
シェルに入って走らせておきましょう。リージョンがアメリカなので少しレスポンスが悪いけどイライラしないように。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;$ heroku run &amp;quot;php artisan migrate&amp;quot;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;確認&lt;/h1&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;heroku&lt;/code&gt;の管理画面から&lt;code class=&quot;language-text&quot;&gt;Open app&lt;/code&gt;をクリックしてみましょう。
以下の画面が出たら成功です。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://d2mxuefqeaa7sj.cloudfront.net/s_76B38BB7F01D58DEEAFB302A5EFEB5ACD0F38F6113786E76A8D460B05B8F35C7_1530103132796_heroku-ss2.png&quot;&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[JSON.NETのCustom Converterを書く]]></title><description><![CDATA[JSON.NETはConverterを書かなくてもプロパティを読んでくれてjsonに変換してくれるのですが、変換された形式が望んでいるものとは違うこともあります。 このjsonを以下のようなクラスに変換する。 JsonConverter…]]></description><link>https://blog.tkt989.info/2018/06/24/JSON.NETのCustom-Converterを書く</link><guid isPermaLink="false">https://blog.tkt989.info/2018/06/24/JSON.NETのCustom-Converterを書く</guid><pubDate>Sun, 24 Jun 2018 07:27:16 GMT</pubDate><content:encoded>&lt;p&gt;JSON.NETはConverterを書かなくてもプロパティを読んでくれてjsonに変換してくれるのですが、変換された形式が望んでいるものとは違うこともあります。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;json&quot;&gt;&lt;pre class=&quot;language-json&quot;&gt;&lt;code class=&quot;language-json&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;&quot;title&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;HelloWorld!&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;&quot;tags&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Diary&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Programming&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;C#&quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;&quot;content&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;...&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token property&quot;&gt;&quot;comments&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token property&quot;&gt;&quot;author&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Alice&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token property&quot;&gt;&quot;content&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;hogehoge!&quot;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token property&quot;&gt;&quot;author&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Bob&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      &lt;span class=&quot;token property&quot;&gt;&quot;content&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;piyopiyo!&quot;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;このjsonを以下のようなクラスに変換する。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Post&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt; Title &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt; Content &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; IList&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Tag&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; Tags &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token generic-method&quot;&gt;&lt;span class=&quot;token function&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Tag&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; IList&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Comment&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; Comments &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token generic-method&quot;&gt;&lt;span class=&quot;token function&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Comment&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Tag&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt; Name &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Comment&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt; Author &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt; Content &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;set&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;JsonConverterを継承したクラスを作ることで特定のクラスのCustom Converterを作ることができます。
継承したクラスでオーバーライドするメソッドは以下。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;JsonConverter&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CanConvert&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Type&lt;/span&gt; objectType&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;ReadJson&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;JsonReader&lt;/span&gt; reader&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Type&lt;/span&gt; objectType&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt; existingValue&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;JsonSerializer&lt;/span&gt; serializer&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;WriteJson&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;JsonWriter&lt;/span&gt; writer&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;JsonSerializer&lt;/span&gt; serializer&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;そしてこんなふうに実際のConverterは以下のようになる。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;    &lt;span class=&quot;token comment&quot;&gt;/// &amp;lt;summary&gt;&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;/// Postをjsonに変換&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;/// &amp;lt;/summary&gt;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;PostConverter&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;JsonConverter&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CanConvert&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Type&lt;/span&gt; objectType&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; objectType &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;typeof&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Post&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;ReadJson&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;JsonReader&lt;/span&gt; reader&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Type&lt;/span&gt; objectType&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt; existingValue&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;JsonSerializer&lt;/span&gt; serializer&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; post &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

            &lt;span class=&quot;token keyword&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;reader&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Read&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;reader&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;TokenType &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; JsonToken&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;EndObject&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
                &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;reader&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;TokenType &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; JsonToken&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;PropertyName&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
                    &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; prop &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; reader&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Value&lt;span class=&quot;token punctuation&quot;&gt;?.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;ToString&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
                    reader&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Read&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

                    &lt;span class=&quot;token keyword&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;prop&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
                        &lt;span class=&quot;token keyword&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;tags&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
                            post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Tags &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;JsonSerializer&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Deserialize&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;IList&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Tag&lt;span class=&quot;token operator&quot;&gt;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;reader&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
                            &lt;span class=&quot;token keyword&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
                        &lt;span class=&quot;token keyword&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;comments&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
                            post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Comments &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;JsonSerializer&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Deserialize&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;IList&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;Comment&lt;span class=&quot;token operator&quot;&gt;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;reader&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
                            &lt;span class=&quot;token keyword&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
                        &lt;span class=&quot;token keyword&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;title&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
                            post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Title &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; reader&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Value&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;ToString&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
                            &lt;span class=&quot;token keyword&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
                        &lt;span class=&quot;token keyword&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;content&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
                            post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Content &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; reader&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Value&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;ToString&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
                            &lt;span class=&quot;token keyword&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
                    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
                &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

            &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; post&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;WriteJson&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;JsonWriter&lt;/span&gt; writer&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;JsonSerializer&lt;/span&gt; serializer&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; post &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; Post&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;post &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

            writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteStartObject&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

            writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WritePropertyName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;title&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
            writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteValue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Title&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
            writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WritePropertyName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;content&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
            writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteValue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Content&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
            writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WritePropertyName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;tags&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
            JToken&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;FromObject&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Tags&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteTo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;writer&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
            writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WritePropertyName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;comments&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
            JToken&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;FromObject&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;post&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Comments&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteTo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;writer&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

            writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteEndObject&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token comment&quot;&gt;/// &amp;lt;summary&gt;&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;/// Tagをjsonに変換&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;/// &amp;lt;/summary&gt;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;TagConverter&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;JsonConverter&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CanConvert&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Type&lt;/span&gt; objectType&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; objectType &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;typeof&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Tag&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;ReadJson&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;JsonReader&lt;/span&gt; reader&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Type&lt;/span&gt; objectType&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt; existingValue&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;JsonSerializer&lt;/span&gt; serializer&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; tag &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Tag&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

            tag&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; reader&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Value&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;ToString&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

            &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; tag&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;WriteJson&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;JsonWriter&lt;/span&gt; writer&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;JsonSerializer&lt;/span&gt; serializer&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; tag &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; Tag&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;tag &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

            writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteValue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;tag&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Name&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token comment&quot;&gt;/// &amp;lt;summary&gt;&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;/// Commentをjsonに変換&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;/// &amp;lt;/summary&gt;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;CommentConverter&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;JsonConverter&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CanConvert&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Type&lt;/span&gt; objectType&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; objectType &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;typeof&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;Comment&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;ReadJson&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;JsonReader&lt;/span&gt; reader&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Type&lt;/span&gt; objectType&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt; existingValue&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;JsonSerializer&lt;/span&gt; serializer&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; props &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;author&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;content&quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; comment &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Comment&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

            &lt;span class=&quot;token keyword&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;reader&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Read&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;reader&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;TokenType &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; JsonToken&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;EndObject&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
                &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;reader&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;TokenType &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; JsonToken&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;PropertyName&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
                    &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; prop &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; reader&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Value&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;ToString&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
                    reader&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Read&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

                    &lt;span class=&quot;token keyword&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;prop&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
                        &lt;span class=&quot;token keyword&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;author&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
                            comment&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Author &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; reader&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Value&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;ToString&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
                            &lt;span class=&quot;token keyword&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
                        &lt;span class=&quot;token keyword&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;content&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;
                            comment&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Content &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; reader&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Value&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;ToString&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
                            &lt;span class=&quot;token keyword&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
                    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
                &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

            &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; comment&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;WriteJson&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;JsonWriter&lt;/span&gt; writer&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;JsonSerializer&lt;/span&gt; serializer&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; comment &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; Comment&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;comment &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

            writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteStartObject&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

            writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WritePropertyName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;author&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
            writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteValue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;comment&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Author&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
            writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WritePropertyName&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;content&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
            writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteValue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;comment&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Content&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

            writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;WriteEndObject&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;ちょっと長いけど、それぞれでやってることは
&lt;code class=&quot;language-text&quot;&gt;CanConvert&lt;/code&gt;で変換できるクラスを指定する。
&lt;code class=&quot;language-text&quot;&gt;ReadJson&lt;/code&gt;では&lt;code class=&quot;language-text&quot;&gt;reader&lt;/code&gt;から一つずつトークンを読み込み、インスタンスに値を次々設定していく。
&lt;code class=&quot;language-text&quot;&gt;WriteJson&lt;/code&gt;は引数で変換するインスタンスが渡されるので、&lt;code class=&quot;language-text&quot;&gt;writer&lt;/code&gt;に書き込む。&lt;/p&gt;
&lt;p&gt;各クラスに&lt;code class=&quot;language-text&quot;&gt;JsonConverter&lt;/code&gt;属性を指定します。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;    &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;JsonConverter&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;typeof&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;PostConverter&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Post&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;JsonConverter&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;typeof&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;TagConverter&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Tag&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;JsonConverter&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;typeof&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;CommentConverter&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Comment&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;これだけ書いたら&lt;code class=&quot;language-text&quot;&gt;DeserializeObject&lt;/code&gt;で変換できる。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; post &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; JsonConvert&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token generic-method&quot;&gt;&lt;span class=&quot;token function&quot;&gt;DeserializeObject&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;jsonText&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content:encoded></item><item><title><![CDATA[ChromebookでLinuxアプリを動かせるようになるという]]></title><description><![CDATA[「Chrome OS」がLinuxをサポート　「Android Studio」でのアプリ開発が可能に - ITmedia NEWS Chromebookは当初はブラウザしか動かせなかった。
オフィスなどの機能はWebアプリでなんとかするコンセプトで、時代を先取りしまくっていたOS…]]></description><link>https://blog.tkt989.info/2018/05/17/ChromebookでLinuxアプリを動かせるようになるという</link><guid isPermaLink="false">https://blog.tkt989.info/2018/05/17/ChromebookでLinuxアプリを動かせるようになるという</guid><pubDate>Thu, 17 May 2018 14:13:10 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;http://www.itmedia.co.jp/news/articles/1805/09/news086.html&quot;&gt;「Chrome OS」がLinuxをサポート　「Android Studio」でのアプリ開発が可能に - ITmedia NEWS&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Chromebookは当初はブラウザしか動かせなかった。
オフィスなどの機能はWebアプリでなんとかするコンセプトで、時代を先取りしまくっていたOSです。
今ではブラウザだけでなくAndroidアプリも使えるようになり、なかなか実用的になっています。&lt;/p&gt;
&lt;p&gt;そして、Google IO 2018でLinuxアプリも起動できるようなることが発表されました。&lt;/p&gt;
&lt;p&gt;そもそもChrome OSはLinuxがベースに作られていて、GUIも&lt;a href=&quot;https://ja.wikipedia.org/wiki/Wayland&quot;&gt;Wayland&lt;/a&gt;というLinuxディストリビューションで使われているもので動いている。
なので、Linuxアプリが動くのは意外ではないし、その証拠に既存のChromebookデバイスでも開発者モードにして&lt;a href=&quot;https://github.com/dnschneid/crouton&quot;&gt;Crouton&lt;/a&gt;というソフトを使えばLinuxアプリを起動できていた。&lt;/p&gt;
&lt;p&gt;今回の発表はその機能を公式に対応することになる。
どのくらい安定しているかとか気になることはたくさんあるけど、やっぱりLinuxのソフトが動かせるっていうのは大きいです。
動画ではAndroid Studioが使えてましたが、それだけでなくLinuxにはデベロッパー向けのソフトが揃っていますから、Chromebookはプログラマにとっても魅力的なデバイスになりそう。&lt;/p&gt;
&lt;p&gt;Pixelbookが発表されたときにChromebookにi5とかi7のCPUなんてオーバースペックなんじゃないのと思ったのですが、Googleはこういう構想も見据えていたのでしょうね。&lt;/p&gt;
&lt;p&gt;Chromebookは日本ではいまいちですが、アメリカでは特に教育現場でかなり普及しているようです。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.itmedia.co.jp/news/articles/1703/04/news022.html&quot;&gt;Chrome OS、米K-12教育市場でシェア58％に（iOSは14％） - ITmedia NEWS&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;ついにLinux系OSを開発者だけでなく一般ユーザーにも広めるという野望?が達成されることになるのかな。&lt;/p&gt;
&lt;p&gt;Chromebookといえば低価格で最低限度のスペックみたいな印象だったけど、これからハイスペックの機種が登場してほしいな。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[「エリック・ホッファー自伝―構想された真実」を読んだ]]></title><description><![CDATA[…]]></description><link>https://blog.tkt989.info/2018/05/08/「エリック・ホッファー自伝―構想された真実」を読んだ</link><guid isPermaLink="false">https://blog.tkt989.info/2018/05/08/「エリック・ホッファー自伝―構想された真実」を読んだ</guid><pubDate>Tue, 08 May 2018 14:15:49 GMT</pubDate><content:encoded>&lt;iframe style=&quot;width:120px;height:240px;&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; src=&quot;//rcm-fe.amazon-adsystem.com/e/cm?lt1=_blank&amp;bc1=000000&amp;IS2=1&amp;bg1=FFFFFF&amp;fc1=000000&amp;lc1=0000FF&amp;t=blogtkt989inf-22&amp;o=9&amp;p=8&amp;l=as4&amp;m=amazon&amp;f=ifr&amp;ref=as_ss_li_til&amp;asins=4878934735&amp;linkId=9c29927f1f36cb54812c0c390ce8a9c1&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;根っからの放浪者。
独学で化学、物理学、数学をマスター
大学教授から働き口を紹介されるも断って放浪を続ける&lt;/p&gt;
&lt;p&gt;本を愛して、ふらふらと季節労働者として居場所を定めずに働いている&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;どんな問題であれ、つねに答えを知っている人間がそばにいたら、自分自身で深く考えることをやめてしまうだろう。
そうすれば私は本来の思索者でない。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;われわれは、仕事が意義あるものであるという考えを捨てなければなりません。この世界に、万人に対して、充実感を与えられるような意義のある職業は存在していないのです。
(中略)
有意義な人生とは学習する人生のことです。人間は、自分が誇りに思えるような技術の取得に身を捧げるべきです。&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;勉強ではなくて、学習していきたい
勉強は少し卑しく感じる。学習のほうが本能に近いというか純粋だ&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Courseraの機械学習を修了した]]></title><description><![CDATA[Courseraの機械学習の講義を修了しました。
ネットで高評価されているのを見ていて、気になってはいたんですよね。
機械学習関係の本を読んでると基礎知識が不足しているを感じていたので、これは基礎固めをしておきたいなと受講してみることにしました。 期間は1月くらいから始めて…]]></description><link>https://blog.tkt989.info/2018/05/05/Courseraの機械学習を修了した</link><guid isPermaLink="false">https://blog.tkt989.info/2018/05/05/Courseraの機械学習を修了した</guid><pubDate>Sat, 05 May 2018 02:48:17 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;/2018/05/coursera.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;Courseraの機械学習の講義を修了しました。
ネットで高評価されているのを見ていて、気になってはいたんですよね。
機械学習関係の本を読んでると基礎知識が不足しているを感じていたので、これは基礎固めをしておきたいなと受講してみることにしました。&lt;/p&gt;
&lt;p&gt;期間は1月くらいから始めて3月の終わり、4月のはじめくらいまで。
振り返ると短いけどなかなか密度の濃い内容でした。&lt;/p&gt;
&lt;p&gt;結構むずかしく、一週間ごとに提出が必要な期限付きの課題がありました。
実は8週目くらいのときに課題の提出が期限まで間に合わなくて、途中で終了させられちゃうのかなーと思っていたんですが、
あとですべての課題を最終週の期限までに終わればいいことを知ったので、なんとか奮起して終わらせることができました。&lt;/p&gt;
&lt;h2&gt;評価が良い理由がわかる&lt;/h2&gt;
&lt;p&gt;受講して思ったのは数式などの理論の部分と、それを使ってどういうことができるのかの実践の部分のバランスが良かったです。&lt;/p&gt;
&lt;p&gt;プログラミングの課題では実際のデータセットを使うのですが、数字の手書認識とか不良製品を見つけたりだとか、「あーこういうふうに使うのか」と、
知ることができます。&lt;/p&gt;
&lt;p&gt;読んでた機械学習の本は理論だけとか、あるいはフレームワークを使って「どういうことができるか」だけが載ってるのだったので、バランス良く学習できたのは良かった。&lt;/p&gt;
&lt;h2&gt;英語力はどれくらい必要か&lt;/h2&gt;
&lt;p&gt;課題は選択肢の中から選ぶものとプログラミングして提出するものがあるのですが、どちらとも英語で出題されます。
プログラミング課題はpdfを読んで答えるようになっていて、大体15ページくらいあります。
最初は怖気づいていたのですが、たいていの課題は数式をoctaveに変換するだけだったので、問題文を完全に理解していなくても、
「この数式を実装すればいいんだな」みたいな感じで乗り切りました。&lt;/p&gt;
&lt;p&gt;数式は世界共通語なんだなと実感。&lt;/p&gt;
&lt;h2&gt;途中で提出できなくても諦めないほうがいい&lt;/h2&gt;
&lt;p&gt;中盤が覚えることも数式も複雑になるので辛かったです。
でも、そこを乗り越えたらあっさりゴールまでたどり着きました。&lt;/p&gt;
&lt;p&gt;今受講中の人が読んでいるのなら、途中で挫けそうになっても諦めないがいいです。
提出期限が遅れても最後で巻き返せます。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[RoomのTypeConverterを使う]]></title><description><![CDATA[こんな感じのEntityを作成したとする。 このままだとJoda-TimeのクラスがRoomに対応していないのでエラーが発生します。
Roomが対応しているのは、StringやInt…]]></description><link>https://blog.tkt989.info/2018/05/04/RoomのTypeConverterを使う</link><guid isPermaLink="false">https://blog.tkt989.info/2018/05/04/RoomのTypeConverterを使う</guid><pubDate>Fri, 04 May 2018 05:22:04 GMT</pubDate><content:encoded>&lt;p&gt;こんな感じのEntityを作成したとする。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;kotlin&quot;&gt;&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token annotation builtin&quot;&gt;@Entity&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Post&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token annotation builtin&quot;&gt;@PrimaryKey&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; id&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Long&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
           &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; title&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; String&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
           &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; content&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; String&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
           &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; date&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; org&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;joda&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;time&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;DateTime&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;このままだとJoda-Timeの&lt;code class=&quot;language-text&quot;&gt;DateTime&lt;/code&gt;クラスがRoomに対応していないのでエラーが発生します。
Roomが対応しているのは、StringやIntなどの型のみなので保存することができないのです。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;text&quot;&gt;&lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;Cannot figure out how to save this field into database. You can consider adding a type converter for it.&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;こういうときは、&lt;code class=&quot;language-text&quot;&gt;TypeConverter&lt;/code&gt;を使いましょう。&lt;/p&gt;
&lt;p&gt;対応していない型をStringやIntなどの型に変換して保存し、読み出すときは逆にString、Intから元の型に変換することで、Roomで扱えるようにします。&lt;/p&gt;
&lt;p&gt;以下のように変換用のメソッドを書いておいて、&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;kotlin&quot;&gt;&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; DateTimeConverter &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token annotation builtin&quot;&gt;@TypeConverter&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;fromTimestamp&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Long&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; DateTime&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;DateTime&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token annotation builtin&quot;&gt;@TypeConverter&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;toTimestamp&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;date&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; DateTime&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Long&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; date&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toInstant&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;millis
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;Database&lt;/code&gt;の宣言に&lt;code class=&quot;language-text&quot;&gt;TypeConverter&lt;/code&gt;を指定するアノテーションを追加する。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;kotlin&quot;&gt;&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token annotation builtin&quot;&gt;@Database&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;version &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; entities &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token annotation builtin&quot;&gt;@TypeConverters&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;DateTimeConverter&lt;span class=&quot;token operator&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; AppDatabase &lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;RoomDatabase&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;token operator&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;これで、自作クラスなどもRoomで扱えるようになる。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[「通じない日本語」を読んだ]]></title><description><![CDATA[…]]></description><link>https://blog.tkt989.info/2018/04/29/「通じない日本語」を読んだ</link><guid isPermaLink="false">https://blog.tkt989.info/2018/04/29/「通じない日本語」を読んだ</guid><pubDate>Sun, 29 Apr 2018 14:12:50 GMT</pubDate><content:encoded>&lt;iframe style=&quot;width:120px;height:240px;&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; src=&quot;//rcm-fe.amazon-adsystem.com/e/cm?lt1=_blank&amp;bc1=000000&amp;IS2=1&amp;bg1=FFFFFF&amp;fc1=000000&amp;lc1=0000FF&amp;t=blogtkt989inf-22&amp;o=9&amp;p=8&amp;l=as4&amp;m=amazon&amp;f=ifr&amp;ref=as_ss_li_til&amp;asins=4582858619&amp;linkId=1f6509aaacb0abe28d0d3615d22ad42e&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;ヤバイのような意味が広くなったものや、ググるのような新しい単語が出てきている。
はたからみると新語は粗製乱造されているように見えるけど、裏にはしっかりとして言語学的に見て理由がある。&lt;/p&gt;
&lt;p&gt;たとえば雰囲気を「ふんいき」ではなく「ふいんき」と言うことがあるが、なぜこのようになるのか。
「ふん」「いん」は長音節と呼ばれ、「い」「き」などは短音節と呼ばれる。
この長音節と短音節の関係により発音のしやすさが変わるのだそうだ。&lt;/p&gt;
&lt;p&gt;具体的には、長音節の後に短音節が来るのが発音しやすい。
これは最近の若者だけの傾向ではなく過去から続いているものだ。&lt;/p&gt;
&lt;p&gt;たとえば「山茶花」はそのまま漢字だけを読めば「さんざか」となる。
しかし、これは「長短短」という音節になる。
これよりも「短長短」になる「さざんか」のほうが発音しやすい。&lt;/p&gt;
&lt;p&gt;また「短長」の発音も嫌わるようで「女房」は「にょぼう」と呼ばれていたが、しだいに「長長」の「にょうぼう」になったり、「長短」の「にょーぼ」のように発音するようになった。&lt;/p&gt;
&lt;p&gt;発音だけでなく言葉の意味も世代によって変わる。&lt;/p&gt;
&lt;p&gt;たとえば「全然」は、全然ダメ、全然書けないなど否定的な言葉が後に続くが、最近では全然おもしろい、全然良いなどの肯定的な単語が続くことが多くなった。&lt;/p&gt;
&lt;p&gt;地域ごとに方言があるし、世代によって知らない言葉があったり、意味が違っているものもある。
知らないのだったら教えてもらえば良いが、同じ単語でも意味が違う場合は会話に違和感を感じて、相手を理解できなかったり不可解に思うかもしれない。
母語が違ったら、思いを完全に相手に伝えるのはもちろん難しいけど、同じ日本語を母語にしていても自分の言っていることと相手が認識していることは、実は思っているよりずれがあるのかもしれない。&lt;/p&gt;
&lt;p&gt;「日本語」は一つではないと感じた。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Chrome.identity を使ってChrome拡張でもOAuthのAPIを使う]]></title><description><![CDATA[例としてQiitaのAPIを使う。 まずはOAuthのリダイレクト先のURLの項目をで登録しておく。
IDは拡張機能の画面で確認することができる。 
 画像はWebStoreからダウンロードしたアプリだが、まだ配布していない開発中のアプリにもID…]]></description><link>https://blog.tkt989.info/2018/04/22/Chrome.identity-を使ってChrome拡張でもOAuthのAPIを使う</link><guid isPermaLink="false">https://blog.tkt989.info/2018/04/22/Chrome.identity-を使ってChrome拡張でもOAuthのAPIを使う</guid><pubDate>Sun, 22 Apr 2018 14:11:58 GMT</pubDate><content:encoded>&lt;p&gt;例としてQiitaのAPIを使う。&lt;/p&gt;
&lt;p&gt;まずはOAuthのリダイレクト先のURLの項目を&lt;code class=&quot;language-text&quot;&gt;https://{拡張機能のID}.chromiumapp.org&lt;/code&gt;で登録しておく。
IDは拡張機能の画面で確認することができる。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/04/extension.png&quot;&gt;
&lt;img src=&quot;/2018/04/extension_qiita.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;画像はWebStoreからダウンロードしたアプリだが、まだ配布していない開発中のアプリにもIDは割り振られるのでそれを指定する。&lt;/p&gt;
&lt;p&gt;次にOAuthの認可画面を表示するコードを書く。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;chrome&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;launchWebAuthFlow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  url&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;https://qiita.com/api/v2/oauth/authorize?client_id=&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;clientId&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;amp;scopes=read_qiita&amp;amp;state=&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;適当な文字列&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  interactive&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;responseUrl&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// 後述&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;chrome.launchWebAuthFlow&lt;/code&gt;でユーザーを認可用のページにアクセスさせることができる。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;interactive&lt;/code&gt;を&lt;code class=&quot;language-text&quot;&gt;true&lt;/code&gt;にするとユーザーから認可を取得していない場合は認可用のページを表示、取得済みの場合はなにもせずコールバックを呼ぶという処理になる。&lt;/p&gt;
&lt;p&gt;次にコールバック内の処理。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;chrome&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;identity&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;launchWebAuthFlow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;// 省略&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token parameter&quot;&gt;responseUrl&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; url &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;responseUrl&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; code &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; url&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;searchParams&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;code&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;token function&quot;&gt;fetch&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;https://qiita.com/api/v2/access_tokens&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    method&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;post&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    headers&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token string&quot;&gt;&quot;Content-Type&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;application/json&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    body&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;JSON&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;stringify&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      client_id&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; clientId&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      client_secret&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; clientSecret&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
      code&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; code
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;res&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; res&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;json&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; token &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; json&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;token&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// アクセストークン取得&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;responseURL&lt;/code&gt;のGETパラメーターに&lt;code class=&quot;language-text&quot;&gt;code&lt;/code&gt;が入っている。&lt;/p&gt;
&lt;p&gt;それをアクセストークン取得のAPIにClientIdとClientSecretと一緒に送るとアクセストークンが取得できる。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[アドレスバーからTodoistにtodoを追加できるChrome拡張を作った]]></title><description><![CDATA[アドレスバーに’todo’の後、タブを押しtodoを書いてEnterで追加できます。 Omni Todoist 付けたい機能 @明日 #ブログ のように日時やプロジェクトを指定]]></description><link>https://blog.tkt989.info/2018/04/20/アドレスバーからTodoistにtodoを追加できるChrome拡張を作った</link><guid isPermaLink="false">https://blog.tkt989.info/2018/04/20/アドレスバーからTodoistにtodoを追加できるChrome拡張を作った</guid><pubDate>Fri, 20 Apr 2018 14:47:53 GMT</pubDate><content:encoded>&lt;p&gt;アドレスバーに’todo’の後、タブを押しtodoを書いてEnterで追加できます。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://chrome.google.com/webstore/detail/omni-todoist/jegdmcdffgddhaehahgeoiohknchldmj&quot;&gt;Omni Todoist&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;付けたい機能&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;@明日 #ブログ のように日時やプロジェクトを指定&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[気になった記事]]></title><description><![CDATA[気づいたら「後で読む」のPocketに数十個くらい読みたいページが溜まっていた。
このままでは溜まる一方なので、読んで一言感想を書いておく。 最初なので結構古い記事が多いです。 Nintendo Switchの中ではReactが動いてる！Nintendo eShop…]]></description><link>https://blog.tkt989.info/2018/04/17/気になった記事</link><guid isPermaLink="false">https://blog.tkt989.info/2018/04/17/気になった記事</guid><pubDate>Tue, 17 Apr 2018 13:58:52 GMT</pubDate><content:encoded>&lt;p&gt;気づいたら「後で読む」のPocketに数十個くらい読みたいページが溜まっていた。
このままでは溜まる一方なので、読んで一言感想を書いておく。&lt;/p&gt;
&lt;p&gt;最初なので結構古い記事が多いです。&lt;/p&gt;
&lt;h1&gt;&lt;a href=&quot;https://html5experts.jp/shumpei-shiraishi/24538/&quot;&gt;Nintendo Switchの中ではReactが動いてる！Nintendo eShop開発秘話を聞いてきた | HTML5Experts.jp&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;SwtichのストアはReactで動いてる。&lt;/p&gt;
&lt;p&gt;多言語対応や素早い更新のために採用されたとのこと。&lt;/p&gt;
&lt;h1&gt;&lt;a href=&quot;https://techacademy.jp/magazine/11863&quot;&gt;【今すぐ使える！】Android開発で役立つ25のライブラリ | TechAcademyマガジン&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;流行っているデザインもライブラリを使えば簡単に実装できそう。&lt;/p&gt;
&lt;h1&gt;&lt;a href=&quot;https://developers-jp.googleblog.com/2017/08/shut-hal-up.html?m=1&quot;&gt;Google Developers Japan: HAL の分離によるセキュリティ向上の仕組み&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;ハードウェアとの橋渡しになるHALを分離させたというお話。
これによりセキュリティが向上。&lt;/p&gt;
&lt;h1&gt;&lt;a href=&quot;https://tech.recruit-mp.co.jp/mobile/android-architecture/&quot;&gt;[ Android ] – これからの「設計」の話をしよう – PSYENCE:MEDIA&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;レイヤーアーキテクチャ。
こういうガチッとした設計って理解しやすいのもいいけど、完成したときの理路整然さにうっとりしちゃう。&lt;/p&gt;
&lt;h1&gt;&lt;a href=&quot;https://qiita.com/Sekky0905/items/9db448b31aeee9863917&quot;&gt;難しいと感じる技術本を読む時に自分がやっていること - Qiita&lt;/a&gt;&lt;/h1&gt;
&lt;p&gt;一読で完璧に理解しようって思ってしまうけど、難しいよね。
分からない箇所があっても後で読み直せば良いやと考えて、最後まで進む。
すると漠然とだけど全体像が見えて理解しやすくなる。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Macbook Proで外付けBluetoothアダプタを使う方法]]></title><description><![CDATA[最近安いBluetoothマウスを購入したのですが、これが安いだけあってMacbook Proで使うと接続が定期的に切れます。
その度にマウスの電源を入れ直して復帰させていたが面倒くさい、どうにかならないかと思案しているうちに、デスクトップPCにつけていたUSB…]]></description><link>https://blog.tkt989.info/2018/04/14/Macbook-Proで外付けBluetoothアダプタを使う方法</link><guid isPermaLink="false">https://blog.tkt989.info/2018/04/14/Macbook-Proで外付けBluetoothアダプタを使う方法</guid><pubDate>Fri, 13 Apr 2018 15:01:33 GMT</pubDate><content:encoded>&lt;p&gt;最近安いBluetoothマウスを購入したのですが、これが安いだけあってMacbook Proで使うと接続が定期的に切れます。
その度にマウスの電源を入れ直して復帰させていたが面倒くさい、どうにかならないかと思案しているうちに、デスクトップPCにつけていたUSBのBluetoothアダプタが目についた。&lt;/p&gt;
&lt;p&gt;もしかしたらBluetoothのアンテナを変えたら安定したりしないだろうか。
Bluetoothって相性みたいなものがあるってよく聞くし、Macbook Proに入っているアンテナよりもUSBで接続されているアダプタのほうが外界に広く接しているぶん接続も安定しやすそう。&lt;/p&gt;
&lt;p&gt;それでアダプタをMacのほうに付けてみたけど認識されず。
内蔵のほうが優先されてしまいます。&lt;/p&gt;
&lt;p&gt;結果、検索したらすぐに方法を見つけられた。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://apple.stackexchange.com/questions/94402/force-os-x-to-use-bluetooth-dongle-instead-of-built-in-controller?utm_medium=organic&amp;#x26;utm_source=google_rich_qa&amp;#x26;utm_campaign=google_rich_qa&quot;&gt;macos - Force OS X to use Bluetooth dongle instead of built in controller - Ask Different&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;メニューバーにあるBluetoothのアイコンを&lt;code class=&quot;language-text&quot;&gt;Option&lt;/code&gt;を押しながらクリックするとアドレスが表示される。これが内蔵のBluetoothアドレスである。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/04/mac_bt.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;アドレスを確認したら、一旦Bluetoothをオフにして数秒待つ。
次にUSBのBluetoothアダプタを接続して、また数秒待つ。
Bluetoothをオンにしてアドレスを確認。前に表示されていたのと違っていたら、外付けのアダプタで起動できている証である。&lt;/p&gt;
&lt;p&gt;実際に変えてみたらこれが効果ありでした。
前は10分も使っていたらマウスとの接続が切れていたのですが、今はぜんぜん問題ありません。&lt;/p&gt;
&lt;p&gt;MacのBluetoothに不満がある人は試す価値はあると思います。&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;問題のマウス。&lt;/p&gt;
&lt;iframe style=&quot;width:120px;height:240px;&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; src=&quot;//rcm-fe.amazon-adsystem.com/e/cm?lt1=_blank&amp;bc1=000000&amp;IS2=1&amp;bg1=FFFFFF&amp;fc1=000000&amp;lc1=0000FF&amp;t=blogtkt989inf-22&amp;o=9&amp;p=8&amp;l=as4&amp;m=amazon&amp;f=ifr&amp;ref=as_ss_li_til&amp;asins=B01M2X96R9&amp;linkId=2910ed1362d3f02531310481b4e7f0fa&quot;&gt;&lt;/iframe&gt;</content:encoded></item><item><title><![CDATA[WindowsフォームのMDIでモーダルなフォームを表示する方法]]></title><description><![CDATA[まず結論から言うと通常のやり方では出来ません。
MDI…]]></description><link>https://blog.tkt989.info/2018/04/11/WindowsフォームのMDIでモーダルなフォームを表示する方法</link><guid isPermaLink="false">https://blog.tkt989.info/2018/04/11/WindowsフォームのMDIでモーダルなフォームを表示する方法</guid><pubDate>Wed, 11 Apr 2018 14:26:01 GMT</pubDate><content:encoded>&lt;p&gt;まず結論から言うと通常のやり方では出来ません。
MDIで&lt;code class=&quot;language-text&quot;&gt;ShowDialog&lt;/code&gt;を呼び出すと例外が発生します。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/04/mdi_exception.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;なので以下のやり方でやってみました。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; form &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Form2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
form&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;MdiParent &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; MdiParent&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

Enabled &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
form&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;FormClosed &lt;span class=&quot;token operator&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;_s&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; _e&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; Enabled &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

form&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Show&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;/2018/04/mdi.gif&quot;&gt;&lt;/p&gt;
&lt;p&gt;フォームを開くときに現在のフォームを無効状態にしておきます。
そして開いたフォームが閉じるときに再び有効にする。&lt;/p&gt;
&lt;p&gt;これで擬似的にモーダルにすることができました。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Xamarin.iOS でNSCalendarsUsageDescriptionの説明を書けと注意されちゃう]]></title><description><![CDATA[Xamarinで書いたiOSアプリをAppleに提出してみたら以下の理由で審査に落ち
てた。 Missing Info.plist key - This app attempts to access privacy-sensitive data without a usage…]]></description><link>https://blog.tkt989.info/2018/04/04/Xamarin.iOS-でNSCalendarsUsageDescriptionの説明を書けと注意されちゃう</link><guid isPermaLink="false">https://blog.tkt989.info/2018/04/04/Xamarin.iOS-でNSCalendarsUsageDescriptionの説明を書けと注意されちゃう</guid><pubDate>Wed, 04 Apr 2018 12:47:49 GMT</pubDate><content:encoded>&lt;p&gt;Xamarinで書いたiOSアプリをAppleに提出してみたら以下の理由で審査に落ち
てた。&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Missing Info.plist key - This app attempts to access privacy-sensitive data without a usage description. The app’s Info.plist must contain an NSCalendarsUsageDescription key with a string value explaining to the user how the app uses this data.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;NSCalendarsUsageDescription&lt;/code&gt;を書けといっている。&lt;/p&gt;
&lt;p&gt;でもこのアプリはカレンダーの情報なんてアクセスしないんだけど？&lt;/p&gt;
&lt;p&gt;なんでだろうといろいろググってみたら、&lt;code class=&quot;language-text&quot;&gt;Xamarin&lt;/code&gt;の&lt;a href=&quot;https://github.com/jamesmontemagno/PermissionsPlugin&quot;&gt;PermissionsPlugin&lt;/a&gt;の設定を正しく行っていなかったことが判明。&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Due to API usage it is required to add the Calendar permission :(&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;&amp;lt;key&amp;gt;NSCalendarsUsageDescription&amp;lt;/key&amp;gt;&lt;/code&gt;
&lt;code class=&quot;language-text&quot;&gt;&amp;lt;string&amp;gt;Needs Calendar Permission&amp;lt;/string&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;Even though your app may not use calendar at all. I am looking into a workaround for this in the future.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;たとえカレンダーにアクセスしなくても&lt;code class=&quot;language-text&quot;&gt;NSCalendarsUsageDescription&lt;/code&gt;が必要とのこと。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[シェイプ・オブ・ウォーターを見た]]></title><description><![CDATA[…]]></description><link>https://blog.tkt989.info/2018/04/03/シェイプ・オブ・ウォーターを見た</link><guid isPermaLink="false">https://blog.tkt989.info/2018/04/03/シェイプ・オブ・ウォーターを見た</guid><pubDate>Tue, 03 Apr 2018 13:26:57 GMT</pubDate><content:encoded>&lt;iframe style=&quot;width:120px;height:240px;&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; src=&quot;//rcm-fe.amazon-adsystem.com/e/cm?lt1=_blank&amp;bc1=000000&amp;IS2=1&amp;bg1=FFFFFF&amp;fc1=000000&amp;lc1=0000FF&amp;t=blogtkt989inf-22&amp;o=9&amp;p=8&amp;l=as4&amp;m=amazon&amp;f=ifr&amp;ref=as_ss_li_til&amp;asins=B07895V83N&amp;linkId=d83b6290d3b95a3a83250381db8ab389&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;公開最終日に見に行ったけど、意外と客は多かった。
アカデミー賞とったから？&lt;/p&gt;
&lt;p&gt;どこかの奥地で発見され研究所に研究対象として連れてこられた半魚人と、掃除婦として働く女性イライザが、惹かれあう。
その後、イライザは同居人とともに半魚人の解剖を阻止するために脱走させる計画をたて、ソ連のスパイ研究者の協力もあって、自宅に匿うことに成功。
増水して水門が開く日に半魚人を海に帰そうとするが、、、&lt;/p&gt;
&lt;p&gt;みたいな。&lt;/p&gt;
&lt;p&gt;半魚人はなかなか不気味な見た目なのだけど、イライザはそれを全く拒否しない。
彼女自身も捨て子、発話障害と生きてきたので、世俗的な価値観を受け入れず理想主義的な価値観を持っていたのだと思う。&lt;/p&gt;
&lt;p&gt;途中半魚人と一緒にダンスをするシーンがある。
半魚人が舞台で踊るのは見てたらちょっと笑いそうになるのだけど、これも彼らの愛の表現であることを考えると、「人の真剣な姿を笑うのか？」と突きつけられている気がする。&lt;/p&gt;
&lt;p&gt;半魚人に味方する人物は、障害、黒人、同性愛、外国人など社会でマイノリティな人たちである。
彼らは人間扱いされない半魚人に同情のような気持ちを感じる。 &lt;/p&gt;
&lt;p&gt;最近の多様性を重視する社会にとても合う映画だと思った。
「マイノリティがんばれ!」な映画。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Andoid P の ImageDecoder を触ってみる]]></title><description><![CDATA[Android P Previewからが使えるように。 Android Developers Blog: Previewing Android P ImageDecoder | Android Developers Android P gives you an easier…]]></description><link>https://blog.tkt989.info/2018/04/01/Andoid-P-の-ImageDecoder-を触ってみる</link><guid isPermaLink="false">https://blog.tkt989.info/2018/04/01/Andoid-P-の-ImageDecoder-を触ってみる</guid><pubDate>Sun, 01 Apr 2018 05:37:18 GMT</pubDate><content:encoded>&lt;p&gt;Android P Previewから&lt;code class=&quot;language-text&quot;&gt;ImageDecoder&lt;/code&gt;が使えるように。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://android-developers.googleblog.com/2018/03/previewing-android-p.html&quot;&gt;Android Developers Blog: Previewing Android P&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://developer.android.com/reference/android/graphics/ImageDecoder.html&quot;&gt;ImageDecoder | Android Developers&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;
&lt;p&gt;Android P gives you an easier way to decode images to bitmaps or drawables — ImageDecoder, which deprecates BitmapFactory.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h1&gt;画像の表示&lt;/h1&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;kotlin&quot;&gt;&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; uri &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Uri&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;android.resource://&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token delimiter variable&quot;&gt;${&lt;/span&gt;packageName&lt;span class=&quot;token delimiter variable&quot;&gt;}&lt;/span&gt;&lt;/span&gt;/drawable/image&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; source &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; ImageDecoder&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;createSource&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;contentResolver&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; uri&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; bitmap &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; ImageDecoder&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;decodeBitmap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;source&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
imageView&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setImageBitmap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;bitmap&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;/2018/04/normal.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;drawable&lt;/code&gt;をURIにして読み込む。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/19566840/get-uri-from-drawable-image?utm_medium=organic&amp;#x26;utm_source=google_rich_qa&amp;#x26;utm_campaign=google_rich_qa&quot;&gt;android - Get URI from drawable image - Stack Overflow&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;リサイズ&lt;/h1&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;kotlin&quot;&gt;&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; uri &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Uri&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;android.resource://&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token delimiter variable&quot;&gt;${&lt;/span&gt;packageName&lt;span class=&quot;token delimiter variable&quot;&gt;}&lt;/span&gt;&lt;/span&gt;/drawable/image&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; source &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; ImageDecoder&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;createSource&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;contentResolver&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; uri&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; bitmap &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; ImageDecoder&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;decodeBitmap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;source&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; decoder&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; info&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; source &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt;
    decoder&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setResize&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;300&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;300&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
imageView&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setImageBitmap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;bitmap&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;decode...&lt;/code&gt;にコールバックを指定すれば、decoderからリサイズなどができる。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/04/resize.png&quot;&gt;&lt;/p&gt;
&lt;h1&gt;加工&lt;/h1&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;kotlin&quot;&gt;&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; uri &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Uri&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;android.resource://&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token delimiter variable&quot;&gt;${&lt;/span&gt;packageName&lt;span class=&quot;token delimiter variable&quot;&gt;}&lt;/span&gt;&lt;/span&gt;/drawable/image&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; source &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; ImageDecoder&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;createSource&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;contentResolver&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; uri&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; bitmap &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; ImageDecoder&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;decodeBitmap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;source&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; decoder&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; info&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; source &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt;
    decoder&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setResize&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;300&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;300&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    decoder&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setPostProcessor&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; canvas &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; path &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Path&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;fillType &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;FillType&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;INVERSE_EVEN_ODD
        path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addCircle&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;canvas&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;width&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toFloat&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;canvas&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;height&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toFloat&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;canvas&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;width&lt;span class=&quot;token operator&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toFloat&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Path&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Direction&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;CW&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; paint &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Paint&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        paint&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;isAntiAlias &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;
        paint&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;color &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Color&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;TRANSPARENT
        paint&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;xfermode &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;PorterDuffXfermode&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;PorterDuff&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Mode&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;SRC&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

        canvas&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;drawPath&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; paint&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token label symbol&quot;&gt;@setPostProcessor&lt;/span&gt; PixelFormat&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;TRANSLUCENT
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
imageView&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setImageBitmap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;bitmap&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;setPreProcessor&lt;/code&gt;で読み込んだ画像の加工ができる。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/04/preprocess.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;こんな感じに円形にクリッピングなど。&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;使用した画像&lt;/p&gt;
&lt;p&gt;Charlesjsharp / Cassius blue (Leptotes cassius theonus), Cuba / CC BY-SA 4.0
&lt;a href=&quot;https://commons.wikimedia.org/wiki/File:Cassius_blue_(Leptotes_cassius_theonus)_underside.JPG&quot;&gt;File:Cassius blue (Leptotes cassius theonus) underside.JPG - Wikimedia Commons&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Laravel + Jwt Auth で認証付きWebAPIを作る]]></title><description><![CDATA[環境 PHP7.2 Laravel5.5 目標 /api/login ユーザーとパスワードを送るとトークンが発行される。 /api/me ユーザーの情報を返す。トークンが無いとアクセスできない。 認証機能を導入 まずはLaravel…]]></description><link>https://blog.tkt989.info/2018/03/27/Laravel-+-Jwt-Auth-で認証付きWebAPIを作る</link><guid isPermaLink="false">https://blog.tkt989.info/2018/03/27/Laravel-+-Jwt-Auth-で認証付きWebAPIを作る</guid><pubDate>Tue, 27 Mar 2018 14:20:29 GMT</pubDate><content:encoded>&lt;h1&gt;環境&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;PHP7.2&lt;/li&gt;
&lt;li&gt;Laravel5.5&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;目標&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;/api/login ユーザーとパスワードを送るとトークンが発行される。&lt;/li&gt;
&lt;li&gt;/api/me ユーザーの情報を返す。トークンが無いとアクセスできない。&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;認証機能を導入&lt;/h1&gt;
&lt;p&gt;まずはLaravelに備わっている認証機能を有効にしておきます。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;php artisan make:auth
php artisan migrate&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;これだけでログイン機能ができる。
WebAPIのときに使うのでユーザーを登録しておきましょう。&lt;/p&gt;
&lt;h1&gt;composerでjwt-authをインストール&lt;/h1&gt;
&lt;p&gt;jwt-authをLaravelプロジェクトにインストールします。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;composer require tymon/jwt-auth 1.0.0-rc2&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Laravel5.5&gt;= には1.0以上のjwt-authが必要なのでバージョンを指定します。&lt;/p&gt;
&lt;p&gt;次にjwt-authの初期設定を行います。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;php artisan vendor:publish --provider=&amp;quot;Tymon\JWTAuth\Providers\LaravelServiceProvider&amp;quot;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;config/jwt.php&lt;/code&gt;が生成されます。&lt;/p&gt;
&lt;p&gt;最後に秘密鍵を生成。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;php artisan jwt:secret&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Userモデルを修正&lt;/h1&gt;
&lt;p&gt;Userモデルをjwt-authに対応させるため、編集します。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;&lt;span class=&quot;token unchanged&quot;&gt; &amp;lt;?php
&lt;/span&gt;
&lt;span class=&quot;token unchanged&quot;&gt; namespace App;
&lt;/span&gt;
&lt;span class=&quot;token inserted-sign inserted&quot;&gt;+use Tymon\JWTAuth\Contracts\JWTSubject;
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt; use Illuminate\Notifications\Notifiable;
 use Illuminate\Foundation\Auth\User as Authenticatable;
 
&lt;/span&gt;&lt;span class=&quot;token deleted-sign deleted&quot;&gt;-class User extends Authenticatable
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;+class User extends Authenticatable implements JWTSubject
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt; {
    ...
    
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;+    public function getJWTIdentifier()
+    {
+        return $this-&gt;getKey();
+    }
+    public function getJWTCustomClaims()
+    {
+        return [];
+    }
&lt;/span&gt;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;guardを修正&lt;/h1&gt;
&lt;p&gt;guardは認証を管理する仕組みで、デフォルトでは&lt;code class=&quot;language-text&quot;&gt;web&lt;/code&gt;と&lt;code class=&quot;language-text&quot;&gt;api&lt;/code&gt;があります。
&lt;code class=&quot;language-text&quot;&gt;web&lt;/code&gt;は普通にhtmlからのログインを管理しています。
一方&lt;code class=&quot;language-text&quot;&gt;api&lt;/code&gt;は名前の通り、WebAPIのログインです。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;jwt-auth&lt;/code&gt;を使うので&lt;code class=&quot;language-text&quot;&gt;api&lt;/code&gt;を&lt;code class=&quot;language-text&quot;&gt;jwt&lt;/code&gt;に変えます。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;config/auth.php&lt;/code&gt;を編集&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;diff&quot;&gt;&lt;pre class=&quot;language-diff&quot;&gt;&lt;code class=&quot;language-diff&quot;&gt;&lt;span class=&quot;token unchanged&quot;&gt;    &apos;guards&apos; =&gt; [
        &apos;web&apos; =&gt; [
            &apos;driver&apos; =&gt; &apos;session&apos;,
            &apos;provider&apos; =&gt; &apos;users&apos;,
        ],
&lt;/span&gt;
&lt;span class=&quot;token unchanged&quot;&gt;        &apos;api&apos; =&gt; [
&lt;/span&gt;&lt;span class=&quot;token deleted-sign deleted&quot;&gt;-            &apos;driver&apos; =&gt; &apos;api&apos;,
&lt;/span&gt;&lt;span class=&quot;token inserted-sign inserted&quot;&gt;+            &apos;driver&apos; =&gt; &apos;jwt&apos;,
&lt;/span&gt;&lt;span class=&quot;token unchanged&quot;&gt;            &apos;provider&apos; =&gt; &apos;users&apos;,
        ],
    ],&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;ApiControllerを生成&lt;/h1&gt;
&lt;p&gt;次にAPIのコントローラーを作成します。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;php artisan make:controller ApiController&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;app/Http/Controllers/ApiController.php&lt;/code&gt;が生成されます。&lt;/p&gt;
&lt;p&gt;以下のように変更しましょう。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;php&quot;&gt;&lt;pre class=&quot;language-php&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;token php language-php&quot;&gt;&lt;span class=&quot;token delimiter important&quot;&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;token package&quot;&gt;App&lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;Http&lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;Controllers&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;token package&quot;&gt;Illuminate&lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;Support&lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;Facades&lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;Auth&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;token package&quot;&gt;Illuminate&lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;Http&lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;Request&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;ApiController&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Controller&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;login&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token variable&quot;&gt;$credentials&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token single-quoted-string string&quot;&gt;&apos;email&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token single-quoted-string string&quot;&gt;&apos;password&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$token&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;auth&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token double-quoted-string string&quot;&gt;&quot;api&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;attempt&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$credentials&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token single-quoted-string string&quot;&gt;&apos;error&apos;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token single-quoted-string string&quot;&gt;&apos;Unauthorized&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;401&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;respondWithToken&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$token&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;me&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;auth&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    
    &lt;span class=&quot;token keyword&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;respondWithToken&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token variable&quot;&gt;$token&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;json&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
            &lt;span class=&quot;token single-quoted-string string&quot;&gt;&apos;access_token&apos;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$token&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;token single-quoted-string string&quot;&gt;&apos;token_type&apos;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token single-quoted-string string&quot;&gt;&apos;bearer&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;token single-quoted-string string&quot;&gt;&apos;expires_in&apos;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;auth&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token double-quoted-string string&quot;&gt;&quot;api&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;factory&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getTTL&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;60&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;ログインとユーザー情報を取得するメソッドを作成しました。&lt;/p&gt;
&lt;h1&gt;routes/api.phpを編集&lt;/h1&gt;
&lt;p&gt;routesファイルを編集。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;php&quot;&gt;&lt;pre class=&quot;language-php&quot;&gt;&lt;code class=&quot;language-php&quot;&gt;&lt;span class=&quot;token php language-php&quot;&gt;&lt;span class=&quot;token delimiter important&quot;&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;token package&quot;&gt;Illuminate&lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;Http&lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;Request&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

Route&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token double-quoted-string string&quot;&gt;&quot;middleware&quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token double-quoted-string string&quot;&gt;&quot;guest:api&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    Route&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token double-quoted-string string&quot;&gt;&quot;/login&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token double-quoted-string string&quot;&gt;&quot;ApiController@login&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

Route&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token double-quoted-string string&quot;&gt;&quot;middleware&quot;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token double-quoted-string string&quot;&gt;&quot;auth:api&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    Route&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token double-quoted-string string&quot;&gt;&quot;/me&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token double-quoted-string string&quot;&gt;&quot;ApiController@me&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;/login&lt;/code&gt;は&lt;code class=&quot;language-text&quot;&gt;guest&lt;/code&gt;を指定して認証がなくてもアクセスできるように、&lt;code class=&quot;language-text&quot;&gt;/me&lt;/code&gt;はログインしてトークンを送らないとアクセスできないようにしました。&lt;/p&gt;
&lt;h1&gt;試す&lt;/h1&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;curl&lt;/code&gt;で試してみます。
&lt;code class=&quot;language-text&quot;&gt;email&lt;/code&gt;と&lt;code class=&quot;language-text&quot;&gt;password&lt;/code&gt;は上のユーザーを登録したときのを指定します。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;curl http://&amp;lt;laravel-host&amp;gt;/api/login -d email=hoge@example.com -d password=hoge12345&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;すると以下のようにトークンを含んだjsonが返ってきます。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;{&amp;quot;access_token&amp;quot;:&amp;quot;eyJ0eXAiOiJKV2QiLC2hbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9sYXJhdmVsLXRha2FzYW45ODkuYzl1c2Vygy5pb1wvYXBpXC9sb2dpbiIsImlhdCI6MTUyMjE1NTY1OSwiZXhwIjoxNTIyMTU5MjU5xCJuYmYiOjE1MxIxNTU2NTksImp0aSI6Inh6MHRsQ1hHNmgwQ1g3V0UiLCJzdWIiOjEsInBydiI6Ijg3bTBhZjFlZjlmZDE1ODEyZmorYzk3MTUzYTE0ZTBJfDQ3NTQ2YWEifQ.BdoHaKFy8XLOSaTKBOhA1D3i5NPUGzG9E1lsBQefEhs&amp;quot;,&amp;quot;token_type&amp;quot;:&amp;quot;bearer&amp;quot;,&amp;quot;expires_in&amp;quot;:3600}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;そしてトークンを使って認証が必要なurlにアクセスしてみます。
&lt;code class=&quot;language-text&quot;&gt;Authorization&lt;/code&gt;ヘッダーに&lt;code class=&quot;language-text&quot;&gt;Bearer: &amp;lt;token&amp;gt;&lt;/code&gt;を付けて送信します。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;curl -H &amp;quot;Authorization: Bearer eyJ0eXAi....&amp;quot; http://&amp;lt;laravel-host&amp;gt;/api/me&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;実行すると&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;{&amp;quot;id&amp;quot;:1,&amp;quot;name&amp;quot;:&amp;quot;hoge&amp;quot;,&amp;quot;email&amp;quot;:&amp;quot;hoge@example.com&amp;quot;,&amp;quot;created_at&amp;quot;:&amp;quot;2018-03-26 14:33:21&amp;quot;,&amp;quot;updated_at&amp;quot;:&amp;quot;2018-03-26 14:33:21&amp;quot;}&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;ログインしているユーザーの情報が返ってきました。&lt;/p&gt;
&lt;p&gt;これを応用すればユーザー認証ができるWebAPIが作れます。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[めんどくさそうなことも、いざやってみたらめんどくさくなかった]]></title><description><![CDATA[タイトル通りのこと。 使ってるクレジットカード(dカード)の利用履歴をスマホでも確認したいなぁと思って、アプリをインストールしてたら、dカードとd…]]></description><link>https://blog.tkt989.info/2018/03/25/めんどくさそうなことも、いざやってみたらめんどくさくなかった</link><guid isPermaLink="false">https://blog.tkt989.info/2018/03/25/めんどくさそうなことも、いざやってみたらめんどくさくなかった</guid><pubDate>Sun, 25 Mar 2018 08:53:02 GMT</pubDate><content:encoded>&lt;p&gt;タイトル通りのこと。&lt;/p&gt;
&lt;p&gt;使ってるクレジットカード(dカード)の利用履歴をスマホでも確認したいなぁと思って、アプリをインストールしてたら、dカードとdアカウントを紐付けないといけなかった。
クレジットカードの番号とか暗証番号などを入力して登録してみようとするも、&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;クレジット暗証番号を一定回数以上間違って入力されたため､ご利用できません｡&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;と出て登録できず。&lt;/p&gt;
&lt;p&gt;見てわかるとおり、ロックされていた。&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;心当たりはあって、数ヶ月前におんなじことをやろうとして、そこで暗証番号を間違えすぎていた。
調べてみたら解除するには当然だけど電話する必要があって、それがめんどくさくてずっとそのままにしてしまっていた。&lt;/p&gt;
&lt;p&gt;もういい加減なんとかしたほうがいいと思っていたけど、インターネットで見ると、郵送で暗証番号を再設定だとか、カードを再発行しないといけないとかの記事を見ると、尻が重くなってしまったのでした。
そのうえ、ロックされたのは数ヶ月前だから、なんでもっと早く解除しようとしないのか怪しまれそうだとか思ってた。&lt;/p&gt;
&lt;p&gt;しかし、解除しないとアプリは使えない。
やっとのことでコールセンターに電話をかけて、自動音声の手続きに添って、ロック解除のためオペレーターの方に繋いでもらい、問い合わせた。
結果的には電話で本人確認してすぐにロック解除になった。10分もかからなかった。&lt;/p&gt;
&lt;p&gt;こんなに短いだったらもっと早くすれば良かったと、後悔。
自分勝手に不安な想像して、ずるずると先延ばしして動けなくなる、こんな習性、嫌だから直したい。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Cloud9でLaravel5.5を動かす]]></title><description><![CDATA[ブラウザで動くIDE、Cloud9でLaravelを使ってみる。
普段使っているパソコンにWEBサーバーやらDBやらを入れるのはしんどいので、こういうときにCloud9は便利です。 環境 PHP 7.2 Laravel 5.5 で導入する。 Cloud…]]></description><link>https://blog.tkt989.info/2018/03/24/Cloud9でLaravel5.5を動かす</link><guid isPermaLink="false">https://blog.tkt989.info/2018/03/24/Cloud9でLaravel5.5を動かす</guid><pubDate>Sat, 24 Mar 2018 13:23:18 GMT</pubDate><content:encoded>&lt;p&gt;ブラウザで動くIDE、Cloud9でLaravelを使ってみる。
普段使っているパソコンにWEBサーバーやらDBやらを入れるのはしんどいので、こういうときにCloud9は便利です。&lt;/p&gt;
&lt;h1&gt;環境&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;PHP 7.2&lt;/li&gt;
&lt;li&gt;Laravel 5.5&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;で導入する。&lt;/p&gt;
&lt;h1&gt;Cloud9セットアップ&lt;/h1&gt;
&lt;p&gt;まずはCloud9でマシンを生成しましょう。
当然ですが、言語はPHPを選択します。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/03/c9-php.png&quot;&gt;&lt;/p&gt;
&lt;h1&gt;PHP7をインストール&lt;/h1&gt;
&lt;p&gt;Cloud9に入っているPHPはバージョンが5なので7をインストールします。
デフォルトのaptリポジトリにはPHP7は登録されていないので、ppaを追加します。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;sudo add-apt-repository ppa:ondrej/php
sudo apt-get update&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;お次にPHP本体と必要なパッケージをインストール。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;sudo apt-get install php7.2 php7.2-dom php7.2-mbstring&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Laravelプロジェクトを作る&lt;/h1&gt;
&lt;p&gt;次にLaravelのプロジェクトを作ります。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;composer create-project laravel/laravel sample &amp;quot;5.5.*&amp;quot; --prefer-dist&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;終わったら&lt;code class=&quot;language-text&quot;&gt;sample&lt;/code&gt;フォルダにLaravelのプロジェクトが生成されます。&lt;/p&gt;
&lt;h1&gt;動かしてみる&lt;/h1&gt;
&lt;p&gt;正しく動くか確認するためにサーバーを起動してみましょう。
Cloud9のPreview用のアドレスとポートを指定しておきます。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;cd sample
php artisan serve --host=$IP --port=$PORT&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;コマンドのあと、Cloud9の&lt;code class=&quot;language-text&quot;&gt;Preview -&amp;gt; Preview Running Application&lt;/code&gt;を選択したらLaravelの画面が表示された。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/03/c9-laravel.png&quot;&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Laravel on Homestead on Mac を始める]]></title><description><![CDATA[VirtualBoxをインストール Oracle VM VirtualBox Vagrantをインストール Download - Vagrant by HashiCorp Homestead Vagrant Boxをインストール Homesteadをインストール]]></description><link>https://blog.tkt989.info/2018/03/21/Laravel-on-Homestead-on-Mac-を始める</link><guid isPermaLink="false">https://blog.tkt989.info/2018/03/21/Laravel-on-Homestead-on-Mac-を始める</guid><pubDate>Wed, 21 Mar 2018 11:38:11 GMT</pubDate><content:encoded>&lt;h1&gt;VirtualBoxをインストール&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;https://www.virtualbox.org/&quot;&gt;Oracle VM VirtualBox&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;Vagrantをインストール&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;https://www.vagrantup.com/downloads.html&quot;&gt;Download - Vagrant by HashiCorp&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;Homestead Vagrant Boxをインストール&lt;/h1&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ vagrant box add laravel/homestead&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;Homesteadをインストール&lt;/h1&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ git clone https://github.com/laravel/homestead.git Homestead&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content:encoded></item><item><title><![CDATA[画像認識の講義を受けてきた]]></title><description><![CDATA[メモ 環境 Visual Studio 2015。
OpenCVのバージョンは2.1。 Haar Like…]]></description><link>https://blog.tkt989.info/2018/03/17/画像認識の講義を受けてきた</link><guid isPermaLink="false">https://blog.tkt989.info/2018/03/17/画像認識の講義を受けてきた</guid><pubDate>Sat, 17 Mar 2018 14:59:43 GMT</pubDate><content:encoded>&lt;h1&gt;メモ&lt;/h1&gt;
&lt;h2&gt;環境&lt;/h2&gt;
&lt;p&gt;Visual Studio 2015。
OpenCVのバージョンは2.1。&lt;/p&gt;
&lt;h2&gt;Haar Like 分類器&lt;/h2&gt;
&lt;p&gt;認識がとても速い。
これが登場したおかげで、顔認識が実用化したとのこと。&lt;/p&gt;
&lt;p&gt;階調差を利用して物体を検知するアルゴリズムらしい。
講師の方が説明していたけど、なんでこれで上手く分類できるのかが不思議だ。&lt;/p&gt;
&lt;p&gt;論文はこちら。全部英語。
&lt;a href=&quot;https://www.cs.cmu.edu/~efros/courses/LBMV07/Papers/viola-cvpr-01.pdf&quot;&gt;paper.dvi&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;弱分類器、強分類器&lt;/h2&gt;
&lt;p&gt;画像認識を行っている様子の動画を見たのだが、そのときに顔っぽくないところを判断して、認識処理を省くような処理をやっている。
こういうふうに、顔ではないことを判別するのは&lt;strong&gt;弱分類器&lt;/strong&gt;というらしい。
逆を&lt;strong&gt;強分類器&lt;/strong&gt;というらしい。&lt;/p&gt;
&lt;p&gt;認識中の動画。&lt;/p&gt;
&lt;div class=&quot;gatsby-resp-iframe-wrapper&quot; style=&quot;padding-bottom: 95.3125%; position: relative; height: 0; overflow: hidden; margin-bottom: 1.0725rem&quot; &gt; &lt;iframe src=&quot;https://player.vimeo.com/video/12774628&quot; frameborder=&quot;0&quot; webkitallowfullscreen mozallowfullscreen allowfullscreen style=&quot; position: absolute; top: 0; left: 0; width: 100%; height: 100%; &quot;&gt;&lt;/iframe&gt; &lt;p&gt;&lt;a href=&quot;https://vimeo.com/12774628&quot;&gt;OpenCV Face Detection: Visualized&lt;/a&gt; from &lt;a href=&quot;https://vimeo.com/adamhrv&quot;&gt;Adam Harvey&lt;/a&gt; on &lt;a href=&quot;https://vimeo.com&quot;&gt;Vimeo&lt;/a&gt;.&lt;/p&gt; &lt;/div&gt;
&lt;p&gt;顔のあたりで認識処理に時間をかけていることがわかる。&lt;/p&gt;
&lt;h2&gt;Webカメラ&lt;/h2&gt;
&lt;p&gt;講義ではWebカメラを使って、顔認識を試した。
Webカメラはローリングシャッターという、画素のラインごとに映像をPCに送信する方式が多いらしい。
場合によっては、不完全な画像が送られる。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.shodensha.net/info/term/q50.html&quot;&gt;ローリングシャッターとグローバルシャッターの違いは何ですか？｜マイクロスコープとは？のお悩み解決！何でも辞典&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;Hough変換&lt;/h2&gt;
&lt;p&gt;廊下の画像から、廊下床面の直線を検出するプログラムを見せてもらった。
Hough変換を使っている。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://ja.wikipedia.org/wiki/%E3%83%8F%E3%83%95%E5%A4%89%E6%8F%9B&quot;&gt;ハフ変換 - Wikipedia&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;平均重心距離法による鍵検出&lt;/h2&gt;
&lt;p&gt;講師の方が発明したアルゴリズムらしいです。
いくつかある鍵の画像から特定の鍵を見つける。
鏡像、反転してても検出できる。&lt;/p&gt;
&lt;p&gt;論文を見つけた。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://ci.nii.ac.jp/els/contentscinii.pdf?id=ART0007340418&quot;&gt;contentscinii.pdf&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;Macで講義のプログラムを動かす&lt;/h1&gt;
&lt;p&gt;OpenCVをインストール。Homebrewを使用する。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;brew install opencv&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;以下のコマンドでコンパイル。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;g++ `pkg-config --cflags --libs opencv` main.cpp -o main&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;pkg-config&lt;/code&gt;でOpenCV関連のライブラリを指定している。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/03/lena_detect.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;なんか顔じゃないところも顔だと認識しているみたいですが。。。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Visual Studio for Mac + Vim Extension メニューを開いたときにクラッシュ]]></title><description><![CDATA[Vimのキーバインドが好きです。 新しいIDEとかエディタは導入したらまずはVimの拡張機能があるかどうかを調べるほどVimに依存しています。 にもVimのキーバインドにしてくれるエクステンションを入れていました。
けれど使用していると、ときどきVisual Studio…]]></description><link>https://blog.tkt989.info/2018/03/11/Visual-Studio-for-Mac-+-Vim-Extension-メニューを開いたときにクラッシュ</link><guid isPermaLink="false">https://blog.tkt989.info/2018/03/11/Visual-Studio-for-Mac-+-Vim-Extension-メニューを開いたときにクラッシュ</guid><pubDate>Sun, 11 Mar 2018 12:59:39 GMT</pubDate><content:encoded>&lt;p&gt;Vimのキーバインドが好きです。&lt;/p&gt;
&lt;p&gt;新しいIDEとかエディタは導入したらまずはVimの拡張機能があるかどうかを調べるほどVimに依存しています。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;Visual Studio for Mac&lt;/code&gt;にもVimのキーバインドにしてくれるエクステンションを入れていました。
けれど使用していると、ときどきVisual Studioがクラッシュしてしまうようになってしまった。&lt;/p&gt;
&lt;p&gt;クラッシュする契機はメニューを開いたときだとわかったのですが、解決方法が見つからなかったため、渋々Vimエクステンションをアンインストールすることに。&lt;/p&gt;
&lt;p&gt;しかし、使い続けるうちにふつふつと、操作にストレスを感じる。
単にコピペしたいだけなのに、Ctrlキー押したりトラックパッドで選択したりするのがめんどう。&lt;/p&gt;
&lt;p&gt;やっぱり入れ直そう、最近Visual Studioの更新がきたので、もしかしたら修正されているかもと思っていたのですが、依然としてメニューを開くとクラッシュしてしまいました。&lt;/p&gt;
&lt;p&gt;がっかりしながらも、また元に戻るのも嫌なので、何か解決方法はないかと検索していると、やっと見つけることができました。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/nosami/XSVim/issues/156&quot;&gt;Visual Studio for Mac crashes when opening Edit menu · Issue #156 · nosami/XSVim&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;Format Document&lt;/code&gt;のキーバインドを外したら直るようです。&lt;/p&gt;
&lt;p&gt;デフォルトのキーバインドは&lt;code class=&quot;language-text&quot;&gt;Ctrl+I&lt;/code&gt;になっているので、Visual Studioの設定から外します。&lt;/p&gt;
&lt;img src=&quot;/2018/03/vsmac.png&quot; width=70%&gt;
&lt;p&gt;今のところ、これを行ってからクラッシュしないようになりました。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Radikoを予約録音してGoogleMusicに自動的にアップロード]]></title><description><![CDATA[Radikoを録音するサーバーを作って、楽しく聞いていたのだけど、いちいちサーバーからスマホにデータを移すのがめんどうくさい。 録音したら勝手にスマホからアクセスできるところに移すようにしたいなーと思い、その先としてGoogleMusicを使うことを企てた。 gmusicapi…]]></description><link>https://blog.tkt989.info/2018/03/10/Radikoを予約録音してGoogleMusicに自動的にアップロード</link><guid isPermaLink="false">https://blog.tkt989.info/2018/03/10/Radikoを予約録音してGoogleMusicに自動的にアップロード</guid><pubDate>Sat, 10 Mar 2018 14:55:36 GMT</pubDate><content:encoded>&lt;p&gt;Radikoを録音するサーバーを作って、楽しく聞いていたのだけど、いちいちサーバーからスマホにデータを移すのがめんどうくさい。&lt;/p&gt;
&lt;p&gt;録音したら勝手にスマホからアクセスできるところに移すようにしたいなーと思い、その先としてGoogleMusicを使うことを企てた。&lt;/p&gt;
&lt;h1&gt;gmusicapi-scriptsをインストール&lt;/h1&gt;
&lt;p&gt;python3.4以上が必要です。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ pip3 install gmusicapi-scripts&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;初回起動時には認証が行われる。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ gmupload

...

Visit the following url:
 https://accounts.google.com/.../
 
Follow the prompts, then paste the auth code here and hit enter:&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;こんな風にURLが表示されるのでアクセスしてログインする。
するとアクセストークンが表示されるので画面に入力。&lt;/p&gt;
&lt;p&gt;認証が終了したので、試しに音楽をアップロードしてみました。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ gmupload abc.mp3
MusicManagerWrapper authentication succeeded.

Loading local songs...
Excluded 0 local songs
Filtered 0 local songs
Loaded 1 local songs

Uploading 1 song(s) to Google Music


(1/1) Successfully uploaded -- xxx.mp3 (...)

All done!&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;確認するとちゃんとアップロードされてましたー。設定は上手くいったみたいです。&lt;/p&gt;
&lt;h1&gt;Radiko録音スクリプトを修正&lt;/h1&gt;
&lt;p&gt;録音は先人の方たちがスクリプトを共有してくださっています。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://gist.github.com/matchy2/3956266/71c4d50435bb74147676d043f1ade5e76cb38c99&quot;&gt;簡易Radiko録音スクリプト&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;これを自動アップロードに対応させるためにちょっと修正。以下のようになりました。&lt;/p&gt;
&lt;script src=&quot;https://gist.github.com/tkt989/521eca79b646394a97834e13c6f0718e.js&quot;&gt;&lt;/script&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;ffmpeg&lt;/code&gt;で変換するときにタグを付けるようにしています。付けとかないとGoogleMusicでは「不明なアルバム」とか表示されて分かりにくくなってしまいます。&lt;/p&gt;
&lt;h1&gt;cronに登録&lt;/h1&gt;
&lt;p&gt;これで下準備はできたので、指定した時間にスクリプトが実行されるようcronに登録します。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;crontab -e&lt;/code&gt;で例えばこんな感じに。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;59 0 * * 3 ~/rec_radiko.sh TBS 120 &amp;quot;爆笑問題カーボーイ&amp;quot;
59 0 * * 0 ~/rec_radiko.sh LFR 120 &amp;quot;オードリーのオールナイトニッポン&amp;quot;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;録音は1分前に開始するようにしてます。&lt;/p&gt;
&lt;p&gt;もちろん番組は皆さんが好きなように変えましょう。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[C#でExcelファイルを扱うときはClosedXMLが便利]]></title><description><![CDATA[C#でExcelファイル(xlsx)を扱えるライブラリを探していた。 やりたいことはセルの中に特定の形式で書き込まれたデータを見つけて、その値を置き換える。
xlsxをテンプレートにして、C#側で好きなデータを埋め込むみたいな処理をやりたかったのです。 Interop…]]></description><link>https://blog.tkt989.info/2018/03/05/C-でExcelファイルを扱うときはClosedXMLが便利</link><guid isPermaLink="false">https://blog.tkt989.info/2018/03/05/C-でExcelファイルを扱うときはClosedXMLが便利</guid><pubDate>Mon, 05 Mar 2018 09:04:57 GMT</pubDate><content:encoded>&lt;p&gt;C#でExcelファイル(xlsx)を扱えるライブラリを探していた。&lt;/p&gt;
&lt;p&gt;やりたいことはセルの中に特定の形式で書き込まれたデータを見つけて、その値を置き換える。
xlsxをテンプレートにして、C#側で好きなデータを埋め込むみたいな処理をやりたかったのです。&lt;/p&gt;
&lt;h2&gt;Interopはメモリ管理しないといけない、うえに遅い&lt;/h2&gt;
&lt;p&gt;すこしググると&lt;code class=&quot;language-text&quot;&gt;Microsoft.Office.Interop.Excel&lt;/code&gt;というのが見つかった。&lt;/p&gt;
&lt;p&gt;これは簡単に言えばxlsxを扱うというより、Excelを操作するようなものみたいで。&lt;/p&gt;
&lt;p&gt;セルを操作するのに直接本物のExcelを使うわけですから、おそらく互換性からみればピカイチなのでしょうが調べてみると、動作が遅かったり、ちょっと組むのを間違えるとExcelのプロセスが残り続けるみたいです。
 以下参考。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://qiita.com/midori44/items/acab9106e6dad9653e73&quot;&gt;Excelファイルを C# と VB.NET で読み込む “正しい” 方法&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;使いにくそうなので、最終的には上の記事にも載っている&lt;code class=&quot;language-text&quot;&gt;ClosedXML&lt;/code&gt;を見つけた。&lt;/p&gt;
&lt;h1&gt;ClosedXMLが使いやすい!&lt;/h1&gt;
&lt;p&gt;プロジェクトに追加するのはNuGetでできる。
VisualStudioのNuGet管理機能で検索すればでてくるので、それをインストールすればいい。&lt;/p&gt;
&lt;h2&gt;使い方&lt;/h2&gt;
&lt;p&gt;例えばxlsxを開いた１番目のシートの左上のセルに適当な文字を書き込むには以下のように。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; book &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;XLWorkbook&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;@&quot;.\template.xlsx&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; sheet &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; book&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Worksheet&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
sheet&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Cell&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Hoge&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;シートやセルを選択する添字が1始まりなのに注意してください。&lt;/p&gt;
&lt;h1&gt;便利な点&lt;/h1&gt;
&lt;p&gt;ClosedXMLにはxlsxを操作するのに便利機能がある。&lt;/p&gt;
&lt;h2&gt;使用している範囲のみ取得&lt;/h2&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;Sheet.RangeUsed()&lt;/code&gt;でシートの中の使用しているセルだけを取得できる。
Excelのシートって縦横でほぼ無限なくらいに広がっているから、シートの中から特定のデータを探すとなると、どれくらい走破しないといけないのよって考えてしまう。&lt;/p&gt;
&lt;p&gt;しかし、&lt;code class=&quot;language-text&quot;&gt;RangeUsed()&lt;/code&gt;を使えば難しいこと考えずに済むわけです。&lt;/p&gt;
&lt;p&gt;Interopの方にもある機能なのかもしれないけど、調べてないです！
先にこっちを見つけちゃったので。&lt;/p&gt;
&lt;h2&gt;行の内容を検索&lt;/h2&gt;
&lt;p&gt;セルだけじゃなくて行のでデータを以下のようにとれます。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; row &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; sheet&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;FirstRow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;んで、その行の中から文字列を検索して、別のデータに置き換えるみたいな処理が以下のように書ける。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;row&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Search&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;{message}&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Hello&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;上の一行だけで、&lt;code class=&quot;language-text&quot;&gt;{message}&lt;/code&gt;を&lt;code class=&quot;language-text&quot;&gt;Hello&lt;/code&gt;に変換できます。&lt;/p&gt;
&lt;h1&gt;やりたかったこと&lt;/h1&gt;
&lt;p&gt;当初の目的である文字列を検索して置き換える処理は以下のようにしてできる。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; row &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt; sheet&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;RangeUsed&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Rows&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	row&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Search&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;hoge&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Value &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;piyo&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;直感的に書けていいですね。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Moqのメモ]]></title><description><![CDATA[ユニットテストを書くときにはモックライブラリがあると便利。
JavaではMockitoを使っていましたが、最近C#を使うことが多くなったので、よく使われているMoqの使い方をメモ。 Moq…]]></description><link>https://blog.tkt989.info/2018/03/03/Moqのメモ</link><guid isPermaLink="false">https://blog.tkt989.info/2018/03/03/Moqのメモ</guid><pubDate>Sat, 03 Mar 2018 05:46:34 GMT</pubDate><content:encoded>&lt;p&gt;ユニットテストを書くときにはモックライブラリがあると便利。
JavaではMockitoを使っていましたが、最近C#を使うことが多くなったので、よく使われているMoqの使い方をメモ。&lt;/p&gt;
&lt;h1&gt;Moqの使い方&lt;/h1&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;IFoo&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Greet&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;abstract&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;DoSomething&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt; text&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;このクラスをモック化してみます。&lt;/p&gt;
&lt;h2&gt;メソッドを上書き&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; mock &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token generic-method&quot;&gt;&lt;span class=&quot;token function&quot;&gt;Mock&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;IFoo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
mock&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Setup&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;foo &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; foo&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Greet&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Returns&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;hello&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; f &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; mock&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Object&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

Assert&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;AreEqual&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;hello&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; f&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Greet&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;Setup&lt;/code&gt;にラムダ式でメソッドを登録して、&lt;code class=&quot;language-text&quot;&gt;Returns&lt;/code&gt;で戻り値を設定できます。&lt;/p&gt;
&lt;h2&gt;引数で戻り値を分ける&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; mock &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token generic-method&quot;&gt;&lt;span class=&quot;token function&quot;&gt;Mock&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;IFoo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
mock&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Setup&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;foo &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; foo&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;DoSomething&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;hoge&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Returns&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
mock&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Setup&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;foo &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; foo&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;DoSomething&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;piyo&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Returns&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
mock&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Setup&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;foo &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; foo&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;DoSomething&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;It&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token generic-method&quot;&gt;&lt;span class=&quot;token function&quot;&gt;Is&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;s &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; s&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Contains&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;a&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Returns&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; f &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; mock&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Object&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

Assert&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;AreEqual&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; f&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;DoSomething&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;hoge&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
Assert&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;AreEqual&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; f&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;DoSomething&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;piyo&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
Assert&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;AreEqual&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; f&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;DoSomething&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;bar&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;Setup&lt;/code&gt;の中で指定すれば特定の引数のときだけの戻り値を設定できます。&lt;/p&gt;
&lt;p&gt;ある条件に引数が一致するかを判断したいときは&lt;code class=&quot;language-text&quot;&gt;It&lt;/code&gt;が使える。
上では”a”を含んでいるstringのときのみ-1を返すようにしています。&lt;/p&gt;
&lt;p&gt;そのほかにも&lt;code class=&quot;language-text&quot;&gt;It&lt;/code&gt;のメソッドを見ればいろいろ条件の指定方法を見つけることができます。&lt;/p&gt;
&lt;h2&gt;例外を投げる&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; mock &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token generic-method&quot;&gt;&lt;span class=&quot;token function&quot;&gt;Mock&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;IFoo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
mock&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Setup&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;foo &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; foo&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;DoThrowableTask&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Throws&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;InvalidOperationException&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; f &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; mock&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Object&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;try&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    f&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;DoThrowableTask&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;InvalidOperationException&lt;/span&gt; e&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
Assert&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Fail&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;特定メソッドの呼び出しを確認&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;csharp&quot;&gt;&lt;pre class=&quot;language-csharp&quot;&gt;&lt;code class=&quot;language-csharp&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; mock &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token generic-method&quot;&gt;&lt;span class=&quot;token function&quot;&gt;Mock&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;IFoo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; f &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; mock&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Object&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

f&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Greet&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

mock&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Verify&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;foo &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; foo&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Greet&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
mock&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Verify&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;foo &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; foo&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;DoSomething&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;hoge&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Times&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Never&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;Verify&lt;/code&gt;でメソッドが呼ばれたか、もしくは呼ばれていないかをチェックすることができる。&lt;/p&gt;
&lt;h1&gt;Mockitoとの比較&lt;/h1&gt;
&lt;p&gt;JavaのMockitoと違いモック化できるのは、interfaceやabstractやvirtualなどの動作を上書きできるメソッドに限られる。&lt;/p&gt;
&lt;p&gt;この制限があるのが残念です。。。
Mockitoだったらほぼ全てのメソッドをモックにすることができるんですけど。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Xamarin.FormsでListViewの行をタップしたときのハイライトを消す]]></title><description><![CDATA[Xamarin.FormsでListViewを試してみると以下のように。  タップした行にハイライトが付いてる。 うーん、今作りたいアプリにはこの機能はあんまり嬉しくない…。
できればAndroidのListView…]]></description><link>https://blog.tkt989.info/2018/02/25/Xamarin.FormsでListViewの行をタップしたときのハイライトを消す</link><guid isPermaLink="false">https://blog.tkt989.info/2018/02/25/Xamarin.FormsでListViewの行をタップしたときのハイライトを消す</guid><pubDate>Sat, 24 Feb 2018 16:27:47 GMT</pubDate><content:encoded>&lt;p&gt;Xamarin.FormsでListViewを試してみると以下のように。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/02/xamarin_listview1.gif&quot;&gt;&lt;/p&gt;
&lt;p&gt;タップした行にハイライトが付いてる。&lt;/p&gt;
&lt;p&gt;うーん、今作りたいアプリにはこの機能はあんまり嬉しくない…。
できればAndroidのListViewみたいになってほしいです。&lt;/p&gt;
&lt;p&gt;ということで消す方法を試してみた。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;cs&quot;&gt;&lt;pre class=&quot;language-cs&quot;&gt;&lt;code class=&quot;language-cs&quot;&gt;listView&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ItemTapped &lt;span class=&quot;token operator&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;sender&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; e&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;ListView&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;sender&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;SelectedItem &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;イベントハンドラの中で、タップされたらすぐ未選択にすればいいみたいです。&lt;/p&gt;
&lt;p&gt;これでAndroidのネイティブな動きのようになりました。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/02/xamarin_listview2.gif&quot;&gt;&lt;/p&gt;
&lt;h1&gt;参考&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;https://stackoverflow.com/questions/26657932/how-to-disable-highlight-on-listview-in-xamarin-forms&quot;&gt;How to disable highlight on ListView in Xamarin.Forms - Stack Overflow&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA['hugo serve' を実行中はGoogleAnalyticsを無効に]]></title><description><![CDATA[記事を公開する前にで確認していると、GoogleAnalyticsのページビューがガンガン増えていってしまう。 自分で自分のブログのアクセス数を稼ぐのは虚しいので、テスト用にサーバーを実行している間はGoogleAnalytics…]]></description><link>https://blog.tkt989.info/2018/02/23/&apos;hugo-serve&apos;-を実行中はGoogleAnalyticsを無効に</link><guid isPermaLink="false">https://blog.tkt989.info/2018/02/23/&apos;hugo-serve&apos;-を実行中はGoogleAnalyticsを無効に</guid><pubDate>Fri, 23 Feb 2018 14:55:18 GMT</pubDate><content:encoded>&lt;p&gt;記事を公開する前に&lt;code class=&quot;language-text&quot;&gt;hugo serve&lt;/code&gt;で確認していると、GoogleAnalyticsのページビューがガンガン増えていってしまう。&lt;/p&gt;
&lt;p&gt;自分で自分のブログのアクセス数を稼ぐのは虚しいので、テスト用にサーバーを実行している間はGoogleAnalyticsはオフにしておきたい。	&lt;/p&gt;
&lt;h1&gt;設定&lt;/h1&gt;
&lt;p&gt;下のサイトを参考に設定してみました。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://discourse.gohugo.io/t/how-to-exclude-google-analytics-when-running-under-hugo-local-server/6092/7&quot;&gt;How to Exclude Google Analytics When Running Under Hugo Local Server - support - Hugo Discussion&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;仕組みとしては、環境変数に&lt;code class=&quot;language-text&quot;&gt;HUGO_ENV=production&lt;/code&gt;が設定されているときだけ、GoogleAnalyticsのコードを埋め込むようにする。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;go&quot;&gt;&lt;pre class=&quot;language-go&quot;&gt;&lt;code class=&quot;language-go&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; eq &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;getenv &lt;span class=&quot;token string&quot;&gt;&quot;HUGO_ENV&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;production&quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; template &lt;span class=&quot;token string&quot;&gt;&quot;_internal/google_analytics_async.html&quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; end &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Hugoのレイアウトhtmlは&lt;code class=&quot;language-text&quot;&gt;theme&lt;/code&gt;フォルダの中に入っているはずなので、使用しているテーマのファイルの中からGoogleAnalyticsを埋め込んでいる箇所を見つける。&lt;/p&gt;
&lt;p&gt;このブログで使っているEvenというテーマでは&lt;code class=&quot;language-text&quot;&gt;partials/scripts.html&lt;/code&gt;の中にありました。&lt;/p&gt;
&lt;p&gt;見つけたら上のコードのように、&lt;code class=&quot;language-text&quot;&gt;HUGO_ENV&lt;/code&gt;が設定されているときだけ、埋め込まれるように編集する。&lt;/p&gt;
&lt;h1&gt;実行&lt;/h1&gt;
&lt;p&gt;確認用のサーバーを起動するときは、普通にそのまま実行する。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;$ hugo serve       &lt;span class=&quot;token comment&quot;&gt;# GAのコードは埋め込まれない&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;実際に公開するときのhtmlを生成するときは、環境変数を設定して実行する。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;$ HUGO_ENV=production hugo&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;これでGoogleAnalyticsのコードを埋め込むかどうかを切り替えれます。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Unityを触ってゲームを作るのがすごく身近になっているのを実感]]></title><description><![CDATA[ゲームを作ってみたいなぁと思ってUnityの本を読んでる。 各章ごとにミニゲームを作りながら進んでいくようになっているので、ゲームを作れてる実感があって良い。 最初は2Dゲームから始めて、だんだん機能を紹介しながら最終的には3D…]]></description><link>https://blog.tkt989.info/2018/02/20/Unityを触ってゲームを作るのがすごく身近になっているのを実感</link><guid isPermaLink="false">https://blog.tkt989.info/2018/02/20/Unityを触ってゲームを作るのがすごく身近になっているのを実感</guid><pubDate>Tue, 20 Feb 2018 14:21:45 GMT</pubDate><content:encoded>&lt;p&gt;ゲームを作ってみたいなぁと思ってUnityの本を読んでる。&lt;/p&gt;
&lt;iframe style=&quot;width:120px;height:240px;&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; src=&quot;//rcm-fe.amazon-adsystem.com/e/cm?lt1=_blank&amp;bc1=000000&amp;IS2=1&amp;bg1=FFFFFF&amp;fc1=000000&amp;lc1=0000FF&amp;t=blogtkt989inf-22&amp;o=9&amp;p=8&amp;l=as4&amp;m=amazon&amp;f=ifr&amp;ref=as_ss_li_til&amp;asins=4797393521&amp;linkId=7a0dff993ec86ab95323ba15a1fd4615&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;各章ごとにミニゲームを作りながら進んでいくようになっているので、ゲームを作れてる実感があって良い。&lt;/p&gt;
&lt;p&gt;最初は2Dゲームから始めて、だんだん機能を紹介しながら最終的には3Dも扱えるようになるみたいです。&lt;/p&gt;
&lt;br /&gt;
今はPhysicsの物理演算を使ってゲームを面白くしようっていうところ。
マウスでポチポチするだけでゲームのキャラが物理的に動いててすごく簡単。
&lt;p&gt;コマアニメみたいなアニメーションを管理する機能もある。
実際に動かしてみるとアニメーションがつくだけで、ぐっとゲームっぽくなる。&lt;/p&gt;
&lt;p&gt;これを実際に一から組もうと思ったらどれだけ掛かるんだろうと思う。&lt;/p&gt;
&lt;br /&gt;
昔、C言語でゲームを作ったことがあるのですが、そのときはDXライブラリというのを使ってました。
&lt;p&gt;DXライブラリはDirectXのラッパーみたいなもので、DirectXが全然わからなかった僕でも簡単に作れたので、インベーダーゲームみたいなものを一度作ったりしていた。
そんなしょぼいゲームを作るときでも当たり判定だとか、三角関数を使って角度の計算などなどいろいろ覚えることがありました。&lt;/p&gt;
&lt;p&gt;移動や当たり判定などのシステム部分もだけど、シーンの切り替えなどめんどうくさい処理がゲームには多い。
Unityはそこらへんを全部カバーしてくれるので、ゲーム制作のおもしろいところだけを堪能できそう。&lt;/p&gt;
&lt;br /&gt;
調べてみたら現在のDXライブラリは、PS4、PSVitaにも対応してるんですね。身近なツールがガチのコンソール機で動いているなんてちょっとワクワクする。
Unityも実際のゲーム機でも動くし、素人とプロの境目が薄くなってる感じがします。
&lt;p&gt;今までコンソールのゲーム開発は中でどういうライブラリが使われているか、なんて知らないから作ることなんてできなかったけど、現在は誰でも使えるツールで行える。
すごい時代だな今更ながら思う。&lt;/p&gt;
&lt;br /&gt;
せっかく勉強してるんだから、何かゲームを作って公開してみたいな。
暇ができたら単純なものでもいいから作ってみようかな。
しょぼいものでも出したほうがいいよね。</content:encoded></item><item><title><![CDATA[ブログのホスト先をVPSからNetlifyに変えた]]></title><description><![CDATA[このブログについて このブログはHugoという静的サイトジェネレーターを使ってhtmlを作成しています。
生成したhtmlをConohaで契約しているVPSで公開しておりました。 VPS上では、リバースプロキシのNginx…]]></description><link>https://blog.tkt989.info/2018/02/13/ブログのホスト先をVPSからNetlifyに変えた</link><guid isPermaLink="false">https://blog.tkt989.info/2018/02/13/ブログのホスト先をVPSからNetlifyに変えた</guid><pubDate>Tue, 13 Feb 2018 13:02:11 GMT</pubDate><content:encoded>&lt;h1&gt;このブログについて&lt;/h1&gt;
&lt;p&gt;このブログはHugoという静的サイトジェネレーターを使ってhtmlを作成しています。
生成したhtmlをConohaで契約しているVPSで公開しておりました。&lt;/p&gt;
&lt;p&gt;VPS上では、リバースプロキシのNginxを立てて、いくつか個人用に立てているサーバーと一緒に、ブログ用のNginx on Dokcerのサーバーを立てているという構成です。&lt;/p&gt;
&lt;p&gt;だけど、個人用のサーバーソフトも三日坊主でほとんど使わなくなり、実質ブログだけにしか使っていない状態。&lt;/p&gt;
&lt;p&gt;そして、最近&lt;a href=&quot;https://www.netlify.com/&quot;&gt;Netlify&lt;/a&gt;というサービスのことを知り、もうVPSを棄ててこちらに乗り換えました。&lt;/p&gt;
&lt;h1&gt;Netlifyに乗り換えた&lt;/h1&gt;
&lt;p&gt;Netlifyは、HugoやJekyllなどのサイトジェネレーターに対応していて、サイトの記事を更新してGithubにPushすれば自動的にビルドしてくれて、サイトを公開してくれます。&lt;/p&gt;
&lt;p&gt;独自ドメインやSSLにも対応しているんです。
ブログを公開するだけなら、わざわざVPSよりもこちらのほうがいいのかなぁ、と。&lt;/p&gt;
&lt;h1&gt;やっぱり無料がいい&lt;/h1&gt;
&lt;p&gt;VPSでブログを公開するのに一番不満なのが、やはりお金がかかることです。
一番安いプランを使っているので(630円くらい)高いわけではないのですが、できることなら無料で公開したい。&lt;/p&gt;
&lt;p&gt;そんなわけで、ホスト先をNetlifyに変更した。
変えたあとに記事を書いているので、これを読んでいるときはすでに切り替わった後だと思います。&lt;/p&gt;
&lt;h1&gt;エラー&lt;/h1&gt;
&lt;p&gt;Netlifyに乗り換えるのに、ちょっと躓いたので少しメモ。&lt;/p&gt;
&lt;p&gt;Netlify上のHugoでサイトをビルドするときに&lt;code class=&quot;language-text&quot;&gt;function &amp;quot;now&amp;quot; is not defined&lt;/code&gt;というエラーが起きた。
これはHugoのバージョンを変えることで解消できました。&lt;/p&gt;
&lt;p&gt;使用するHugoのバージョンは環境変数で設定できます。&lt;/p&gt;
&lt;p&gt;名前は&lt;code class=&quot;language-text&quot;&gt;HUGO_VERSION&lt;/code&gt;にして値にHugoのバージョンを指定するだけです。&lt;/p&gt;
&lt;p&gt;具体的には、Netlifyのサイトの設定画面で&lt;code class=&quot;language-text&quot;&gt;Build &amp;amp; deploy&lt;/code&gt;-&gt;&lt;code class=&quot;language-text&quot;&gt;Build environment variables&lt;/code&gt;で、&lt;code class=&quot;language-text&quot;&gt;Edit variable&lt;/code&gt;をクリックして新しい環境変数を追加。
上記の&lt;code class=&quot;language-text&quot;&gt;HUGO_VERSION&lt;/code&gt;を追加します。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/02/netlify.png&quot;&gt;&lt;/p&gt;
&lt;h1&gt;乗り換えての感想&lt;/h1&gt;
&lt;p&gt;Netlifyに変えてみての感想としては、アクセスログが見られないのは、少しつまらなくなってしまいました。まぁ今までそんなに見ていたわけではないですが。&lt;/p&gt;
&lt;p&gt;あとそれと、表示速度は遅くなってます。
たぶんNetlifyは海外にサーバーがあるみたいなので、国内VPSよりかはどうしても遅くなってしまうでしょう。
でも耐えがたいほど遅いわけではないですし、これから先なにも問題が起こらなければこのままでいいかな。&lt;/p&gt;
&lt;p&gt;少しの間ですが、VPSで自分でブログを作ったのはいい経験。&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;おまけで、GoogleAnalyticsで解析したブログのアクセス状況。&lt;/p&gt;
&lt;p&gt;アクセス数はだいたい1日20人くらい。最弱レベルのブログです。&lt;/p&gt;
&lt;p&gt;一番アクセスが多いのがGooglePlayServiceのFusedLocationの紹介をした記事。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://blog.tkt989.info/2017/12/09/google-play-service%E3%81%AEfusedlocation%E3%81%A7%E4%BD%8D%E7%BD%AE%E6%83%85%E5%A0%B1%E3%82%92%E5%8F%96%E5%BE%97/&quot;&gt;Google Play ServiceのFusedLocationで位置情報を取得 - tkt989’s diary&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;休日は少ないけど、平日になるとアクセス数が少し多くなります。
これはAPIの使い方を仕事中に調べている方が多いからなのかな。
休日でもアクセス数が増えるようにしたいです。&lt;/p&gt;
&lt;p&gt;こんな人知れぬブログですが、見に来てくれる人に感謝です。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[jQuery DataTablesを使うときのXSS対策]]></title><description><![CDATA[なにも考えずにそのままデータを追加すると、サニタイズされないのでXSSが成立してしまう。 なので、ユーザーから入力されたものを含んだデータはにを設定しておきましょう。 参考 DataTables - Security]]></description><link>https://blog.tkt989.info/2018/02/07/jQuery-DataTablesを使うときのXSS対策</link><guid isPermaLink="false">https://blog.tkt989.info/2018/02/07/jQuery-DataTablesを使うときのXSS対策</guid><pubDate>Wed, 07 Feb 2018 08:32:53 GMT</pubDate><content:encoded>&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; result &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;/* サーバーから取得したデータとか */&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;#dataTable&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;DataTable&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	data&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; result&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	columns&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; data&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;name&quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; data&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;age&quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; data&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;tel&quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;なにも考えずにそのままデータを追加すると、サニタイズされないのでXSSが成立してしまう。&lt;/p&gt;
&lt;p&gt;なので、ユーザーから入力されたものを含んだデータは&lt;code class=&quot;language-text&quot;&gt;render&lt;/code&gt;に&lt;code class=&quot;language-text&quot;&gt;$.fn.dataTable.render.text()&lt;/code&gt;を設定しておきましょう。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;js&quot;&gt;&lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token function&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;#dataTable&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;DataTable&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	data&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; result&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
	columns&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; data&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; render&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; $&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;fn&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;dataTable&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;render&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; data&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;age&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;  render&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; $&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;fn&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;dataTable&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;render&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; data&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;tel&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;  render&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; $&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;fn&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;dataTable&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;render&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;token operator&quot;&gt;...&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;参考&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;https://datatables.net/manual/security&quot;&gt;DataTables - Security&lt;/a&gt;&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Android用のKotlin拡張関数を集めたAndroid KTXが便利そう]]></title><description><![CDATA[GoogleDevelopersのビデオで知りました。 Android KTXとは android/android-ktx: A set of Kotlin extensions for Android app development. Kotlin…]]></description><link>https://blog.tkt989.info/2018/02/06/Android用のKotlin拡張関数を集めたAndroid-KTXが便利そう</link><guid isPermaLink="false">https://blog.tkt989.info/2018/02/06/Android用のKotlin拡張関数を集めたAndroid-KTXが便利そう</guid><pubDate>Tue, 06 Feb 2018 12:38:01 GMT</pubDate><content:encoded>&lt;div class=&quot;gatsby-resp-iframe-wrapper&quot; style=&quot;padding-bottom: 56.25%; position: relative; height: 0; overflow: hidden; margin-bottom: 1.0725rem&quot; &gt; &lt;iframe src=&quot;https://www.youtube.com/embed/kmvS3sZF_y0&quot; frameborder=&quot;0&quot; allow=&quot;autoplay; encrypted-media&quot; allowfullscreen style=&quot; position: absolute; top: 0; left: 0; width: 100%; height: 100%; &quot;&gt;&lt;/iframe&gt; &lt;/div&gt;
&lt;p&gt;GoogleDevelopersのビデオで知りました。&lt;/p&gt;
&lt;h1&gt;Android KTXとは&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/android/android-ktx&quot;&gt;android/android-ktx: A set of Kotlin extensions for Android app development.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Kotlinの拡張関数を使ってAndroid APIでの開発をやりやすくしよう、というものです。&lt;/p&gt;
&lt;p&gt;新しい機能が使えるようになるというわけではないのですが、もともとJava向けに書かれたAndroid APIですから、Kotlinで書こうとすると少し冗長になっていたところが、
簡潔にわかりやすく書くことができます。&lt;/p&gt;
&lt;h1&gt;どういうのがあるの&lt;/h1&gt;
&lt;p&gt;Githubに載っているのや、ドキュメントのを書いてみます。&lt;/p&gt;
&lt;h2&gt;Uri&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;kotlin&quot;&gt;&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// kotlin&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; uri &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Uri&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;parse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;myUriString&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// android-ktx&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; uri &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; myUriString&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toUri&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;String&lt;/code&gt;にメソッドが追加されるので、文字列からそのまま変換できます。&lt;/p&gt;
&lt;h2&gt;View&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;kotlin&quot;&gt;&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// kotlin&lt;/span&gt;
view&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;postDelayed&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// android-ktx&lt;/span&gt;
view&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;postDelayed&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token operator&quot;&gt;..&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Kotlinは最後の引数がラムダ式の場合は括弧を閉じた後にラムダ式を書けるのですが、デフォルトのメソッドではミリ秒が最後になっているので、全体を括弧で閉じざるをえない。&lt;/p&gt;
&lt;h2&gt;SharedPreferences&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;kotlin&quot;&gt;&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// kotlin&lt;/span&gt;
sharedPreferences&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;edit&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;putBoolean&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;key&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;apply&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    
&lt;span class=&quot;token comment&quot;&gt;// android-ktx&lt;/span&gt;
sharedPreferences&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;edit&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;putBoolean&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;key&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;Bundle&lt;/h2&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;kotlin&quot;&gt;&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// kotlin&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; bundle &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Bundle&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
bundle&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;putString&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;ID&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;1234&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
bundle&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;putString&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;NAME&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;hoge&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;// android-ktx&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; bundle &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;bundleOf&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;ID &lt;span class=&quot;token keyword&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;1234&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; NAME &lt;span class=&quot;token keyword&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;hoge&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;etc…&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://android.github.io/android-ktx/core-ktx/index.html&quot;&gt;core-ktx&lt;/a&gt;で探すことができます。&lt;/p&gt;
&lt;h1&gt;使うには&lt;/h1&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;build.gradle&lt;/code&gt;に追加。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;groovy&quot;&gt;&lt;pre class=&quot;language-groovy&quot;&gt;&lt;code class=&quot;language-groovy&quot;&gt;dependencies &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    implementation &lt;span class=&quot;token string&quot;&gt;&apos;androidx.core:core-ktx:0.1&apos;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;まとめ&lt;/h1&gt;
&lt;p&gt;ちょっとした違いなのですが、このちょっとしたことだけでプログラムを組むのが楽しくなりそうですね。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[CoreMLで画像認識にチャレンジ]]></title><description><![CDATA[iOS11から使えるCoreML…]]></description><link>https://blog.tkt989.info/2018/02/04/CoreMLで画像認識にチャレンジ</link><guid isPermaLink="false">https://blog.tkt989.info/2018/02/04/CoreMLで画像認識にチャレンジ</guid><pubDate>Sun, 04 Feb 2018 12:20:59 GMT</pubDate><content:encoded>&lt;p&gt;iOS11から使えるCoreMLという機械学習フレームワークがあります。&lt;/p&gt;
&lt;p&gt;気になって&lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2017/703/&quot;&gt;紹介ビデオ&lt;/a&gt;を見たら、数行のコードを書くだけで画像認識を行い、なにが写っているかを推測できるようです。&lt;/p&gt;
&lt;p&gt;画像認識がこんなに簡単にできるなんてすごい、おもしろそうなので実際に使ってみました。&lt;/p&gt;
&lt;h1&gt;モデルを取得&lt;/h1&gt;
&lt;p&gt;まずは画像を学習したモデルをダウンロードします。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://developer.apple.com/jp/machine-learning/&quot;&gt;https://developer.apple.com/jp/machine-learning/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;上のサイトに用途に合わせていくつかのモデルがダウンロードできます。今回はMobileNetというものを使って見ようと思います。&lt;/p&gt;
&lt;p&gt;モデルを取得したらXCodeのプロジェクトにドラッグアンドドロップでモデルファイルを追加します。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/02/coreml1.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;.mlmodel&lt;/code&gt;がモデルファイルですね。&lt;/p&gt;
&lt;p&gt;選択するとモデルに渡す形式や出力の情報を確認することができます。&lt;/p&gt;
&lt;p&gt;この情報を読むと、MobileNetは224x224の画像を入力すると、&lt;code class=&quot;language-text&quot;&gt;Dictionary&lt;/code&gt;で写っているものを表すカテゴリとその確率、そしてもっとも確率が高いものカテゴリを出力するようです。&lt;/p&gt;
&lt;h1&gt;画像を選ぶ&lt;/h1&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;swift&quot;&gt;&lt;pre class=&quot;language-swift&quot;&gt;&lt;code class=&quot;language-swift&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; imagePickerController &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;UIImagePickerController&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
imagePickerController&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;sourceType &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;photoLibrary
imagePickerController&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;delegate &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;self&lt;/span&gt;
        
&lt;span class=&quot;token function&quot;&gt;present&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;imagePickerController&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; animated&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; completion&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;モデルに入力する画像を選ぶために&lt;code class=&quot;language-text&quot;&gt;UIImagePickerController&lt;/code&gt;を使います。&lt;/p&gt;
&lt;p&gt;次に、選んだ画像をモデルに入力するわけですが、&lt;code class=&quot;language-text&quot;&gt;CVPixelBuffer&lt;/code&gt;という型に変換する必要があります。&lt;/p&gt;
&lt;p&gt;自分でやってみようと思ったのですが、ちょっと複雑そうだったので、StackOverflowに載っていたコードをそのままコピペ。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://stackoverflow.com/questions/44400741/convert-image-to-cvpixelbuffer-for-machine-learning-swift&quot;&gt;https://stackoverflow.com/questions/44400741/convert-image-to-cvpixelbuffer-for-machine-learning-swift&lt;/a&gt;&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;swift&quot;&gt;&lt;pre class=&quot;language-swift&quot;&gt;&lt;code class=&quot;language-swift&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;UIImage&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    
    &lt;span class=&quot;token keyword&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;resize&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;to newSize&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;CGSize&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;UIImage&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token function&quot;&gt;UIGraphicsBeginImageContextWithOptions&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;CGSize&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;width&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; newSize&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;width&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; height&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; newSize&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;height&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;draw&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CGRect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;x&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; y&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; width&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; newSize&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;width&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; height&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; newSize&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;height&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; resizedImage &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;UIGraphicsGetImageFromCurrentImageContext&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;
        &lt;span class=&quot;token function&quot;&gt;UIGraphicsEndImageContext&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        
        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; resizedImage
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    
    &lt;span class=&quot;token keyword&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;pixelBuffer&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;CVPixelBuffer&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; width &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;size&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;width
        &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; height &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;size&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;height
        &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; attrs &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;kCVPixelBufferCGImageCompatibilityKey&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;kCFBooleanTrue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
                     &lt;span class=&quot;token constant&quot;&gt;kCVPixelBufferCGBitmapContextCompatibilityKey&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;kCFBooleanTrue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;CFDictionary&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;var&lt;/span&gt; pixelBuffer&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;CVPixelBuffer&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; status &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CVPixelBufferCreate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token constant&quot;&gt;kCFAllocatorDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
                                         &lt;span class=&quot;token function&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;width&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
                                         &lt;span class=&quot;token function&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;height&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
                                         kCVPixelFormatType_32ARGB&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
                                         attrs&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
                                         &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&lt;/span&gt;pixelBuffer&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        
        &lt;span class=&quot;token keyword&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; resultPixelBuffer &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; pixelBuffer&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; status &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;kCVReturnSuccess&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;nil&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
        
        &lt;span class=&quot;token function&quot;&gt;CVPixelBufferLockBaseAddress&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;resultPixelBuffer&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CVPixelBufferLockFlags&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;rawValue&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; pixelData &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CVPixelBufferGetBaseAddress&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;resultPixelBuffer&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        
        &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; rgbColorSpace &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CGColorSpaceCreateDeviceRGB&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; context &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CGContext&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;data&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; pixelData&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
                                      width&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;width&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
                                      height&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;height&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
                                      bitsPerComponent&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
                                      bytesPerRow&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CVPixelBufferGetBytesPerRow&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;resultPixelBuffer&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
                                      space&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; rgbColorSpace&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
                                      bitmapInfo&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;CGImageAlphaInfo&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;noneSkipFirst&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;rawValue&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
                                        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;nil&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
        
        context&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;translateBy&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;x&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; y&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; height&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        context&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;scaleBy&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;x&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; y&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        
        &lt;span class=&quot;token function&quot;&gt;UIGraphicsPushContext&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;context&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;draw&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CGRect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;x&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; y&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; width&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; width&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; height&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; height&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token function&quot;&gt;UIGraphicsPopContext&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token function&quot;&gt;CVPixelBufferUnlockBaseAddress&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;resultPixelBuffer&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CVPixelBufferLockFlags&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;rawValue&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        
        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; resultPixelBuffer
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;画像をモデルに入力&lt;/h1&gt;
&lt;p&gt;デリゲートのメソッドで選択した画像を取得。
入力用にリサイズして、形式を変換します。&lt;/p&gt;
&lt;p&gt;その後、モデルクラスを生成して、&lt;code class=&quot;language-text&quot;&gt;prediction&lt;/code&gt;を呼び出すと、結果を取得することができます。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;swift&quot;&gt;&lt;pre class=&quot;language-swift&quot;&gt;&lt;code class=&quot;language-swift&quot;&gt;    &lt;span class=&quot;token keyword&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;imagePickerController&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;_&lt;/span&gt; picker&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;UIImagePickerController&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; didFinishPickingMediaWithInfo info&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token builtin&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;Any&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; image &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;info&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token builtin&quot;&gt;UIImagePickerControllerOriginalImage&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;UIImage&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;resize&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;to&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;CGSize&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;width&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;224&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; height&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;224&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        
        &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; pixelBuffer &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; image&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;pixelBuffer&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        
        &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; model &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;MobileNet&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; prediction &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt; model&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;prediction&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;image&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; pixelBuffer&lt;span class=&quot;token operator&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        
        &lt;span class=&quot;token keyword&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;label&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;text &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; prediction&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;classLabel
        &lt;span class=&quot;token keyword&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;image&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;image &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; image
        
        &lt;span class=&quot;token function&quot;&gt;dismiss&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;animated&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; completion&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token constant&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;実行してみた結果&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;/2018/02/coreml2.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;どうやら上手い具合に推測できているようです。&lt;/p&gt;
&lt;p&gt;ほかに試してみましょう。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/02/coreml3.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;baboonはヒヒのことです。&lt;/p&gt;
&lt;p&gt;ちなみに上手くいかなかったことも、、、&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/02/coreml4.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;うーん、惜しい。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Githubの有料アカウントを取得]]></title><description><![CDATA[右上のアカウントメニューからを選択。  設定画面からを選択して課金メニューを開きます。  私はまだ支払い方法を登録していなかったので、ので支払い方法を選びます。
クレジットカードとPaypal…]]></description><link>https://blog.tkt989.info/2018/01/30/Githubの有料アカウントを取得</link><guid isPermaLink="false">https://blog.tkt989.info/2018/01/30/Githubの有料アカウントを取得</guid><pubDate>Tue, 30 Jan 2018 12:36:55 GMT</pubDate><content:encoded>&lt;p&gt;右上のアカウントメニューから&lt;code class=&quot;language-text&quot;&gt;Setting&lt;/code&gt;を選択。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/01/github1.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;設定画面から&lt;code class=&quot;language-text&quot;&gt;Billing&lt;/code&gt;を選択して課金メニューを開きます。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/01/github2.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;私はまだ支払い方法を登録していなかったので、&lt;code class=&quot;language-text&quot;&gt;Payment&lt;/code&gt;の&lt;code class=&quot;language-text&quot;&gt;Add payment method&lt;/code&gt;で支払い方法を選びます。
クレジットカードとPaypalが使えます。
私はクレジットカードを選択。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/01/github3.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;クレジットカードを登録したら、課金メニューに戻り、&lt;code class=&quot;language-text&quot;&gt;Get private repositories&lt;/code&gt;を選択。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/01/github5.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;一月ごと、もしくは一年ごとに支払うかの選べるので好きな方を選ぶ。
どちらにするのかを決めたら&lt;code class=&quot;language-text&quot;&gt;Upgrade plan&lt;/code&gt;をクリック。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/01/github6.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;これで有料アカウントになりました。
プライベートリポジトリが作り放題なので、世界に公開したくないソースコードでもGithubで管理できます！&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Goで比較明合成してみた]]></title><description><![CDATA[画像読み込み ファイルパスからを作る。 輝度計算 輝度はピクセルの明るさのことです。
以下のサイトを参照して計算していますが、比較明合成では実際の輝度の値ではなく、大小関係が知りたいだけなので、小数にせずに整数にして計算しています。 osakana.factory - HSB…]]></description><link>https://blog.tkt989.info/2018/01/23/Goで比較明合成してみた</link><guid isPermaLink="false">https://blog.tkt989.info/2018/01/23/Goで比較明合成してみた</guid><pubDate>Mon, 22 Jan 2018 22:42:13 GMT</pubDate><content:encoded>&lt;h2&gt;画像読み込み&lt;/h2&gt;
&lt;p&gt;ファイルパスから&lt;code class=&quot;language-text&quot;&gt;image.Image&lt;/code&gt;を作る。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;go&quot;&gt;&lt;pre class=&quot;language-go&quot;&gt;&lt;code class=&quot;language-go&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;decode&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;file &lt;span class=&quot;token builtin&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;image&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Image&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	reader&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; err &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Open&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;file&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; err &lt;span class=&quot;token operator&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;nil&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		log&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;defer&lt;/span&gt; reader&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Close&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

	img&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; err &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; image&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Decode&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;reader&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; err &lt;span class=&quot;token operator&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;nil&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		log&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; img&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;nil&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;輝度計算&lt;/h2&gt;
&lt;p&gt;輝度はピクセルの明るさのことです。
以下のサイトを参照して計算していますが、比較明合成では実際の輝度の値ではなく、大小関係が知りたいだけなので、小数にせずに整数にして計算しています。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://ofo.jp/osakana/cgtips/hsb.phtml&quot;&gt;osakana.factory - HSB 値と輝度の求め方&lt;/a&gt;&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;go&quot;&gt;&lt;pre class=&quot;language-go&quot;&gt;&lt;code class=&quot;language-go&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;luminance&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;color color&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Color&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token builtin&quot;&gt;uint32&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	r&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; g&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; b&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; color&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;RGBA&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;298&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; r &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;586&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; g &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;114&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; b
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;合成&lt;/h2&gt;
&lt;p&gt;画像のピクセルを一つずつ見ていき、色情報を取り出す。
輝度を計算し、大きい方の色を出力画像のピクセルとして書き出しています。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;go&quot;&gt;&lt;pre class=&quot;language-go&quot;&gt;&lt;code class=&quot;language-go&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;blend&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;img1&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; img2 image&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Image&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; image&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Image &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	width &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; img1&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Bounds&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Max&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;X
	height &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; img1&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Bounds&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Max&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Y

	out &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; image&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;NewRGBA&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;image&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Rect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; width&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; height&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; y &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; y &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; height&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; y&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;token keyword&quot;&gt;for&lt;/span&gt; x &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; x &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; width&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; x&lt;span class=&quot;token operator&quot;&gt;++&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
			color1 &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; img1&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;At&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;x&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; y&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
			color2 &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; img2&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;At&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;x&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; y&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

			&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;luminance&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;color1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;luminance&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;color2&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
				out&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;x&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; y&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; color1&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
			&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
				out&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;x&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; y&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; color2&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
			&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
		&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; out
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;main関数&lt;/h2&gt;
&lt;p&gt;最後にmain関数。
コマンドライン引数で合成用の画像ファイルと出力先を指定。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;go&quot;&gt;&lt;pre class=&quot;language-go&quot;&gt;&lt;code class=&quot;language-go&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
	img1&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; err &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;decode&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Args&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; err &lt;span class=&quot;token operator&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;nil&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		log&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	img2&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; err &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;decode&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Args&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; err &lt;span class=&quot;token operator&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;nil&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		log&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; img1&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Bounds&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;!=&lt;/span&gt; img2&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Bounds&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		log&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

	out &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;blend&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;img1&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; img2&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

	writer&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; err &lt;span class=&quot;token operator&quot;&gt;:=&lt;/span&gt; os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Create&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;os&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Args&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; err &lt;span class=&quot;token operator&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;nil&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
		log&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Fatal&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;err&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
	&lt;span class=&quot;token keyword&quot;&gt;defer&lt;/span&gt; writer&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Close&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

	jpeg&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Encode&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;writer&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; out&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&lt;/span&gt;jpeg&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Options&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;コード全文&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/tkt989/golang-blend&quot;&gt;tkt989/golang-blend&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;実行例&lt;/h1&gt;
&lt;p&gt;撮った写真でいくつか実行してみました。&lt;/p&gt;
&lt;hr&gt;
&lt;img src=&quot;/2018/01/pic1.JPG&quot; width=&quot;300&quot;&gt;
&lt;p&gt;+&lt;/p&gt;
&lt;img src=&quot;/2018/01/pic2.JPG&quot; width=&quot;300&quot;&gt;
&lt;p&gt;=&lt;/p&gt;
&lt;img src=&quot;/2018/01/out1.jpg&quot; width=&quot;300&quot;&gt;
&lt;hr&gt;
&lt;img src=&quot;/2018/01/pic3.JPG&quot; width=&quot;300&quot;&gt;
&lt;p&gt;+&lt;/p&gt;
&lt;img src=&quot;/2018/01/pic4.JPG&quot; width=&quot;300&quot;&gt;
&lt;p&gt;=&lt;/p&gt;
&lt;img src=&quot;/2018/01/out2.jpg&quot; width=&quot;300&quot;&gt;</content:encoded></item><item><title><![CDATA[Retrofitを使ってみる(Qiita APIs)]]></title><description><![CDATA[準備 以下のリンクからQiitaのアクセストークンを取得しておく。 アプリケーション - Qiita コード にretrofit本体と、Stringに変換するconverterを追加。 API…]]></description><link>https://blog.tkt989.info/2018/01/15/Retrofitを使ってみる(Qiita-APIs)</link><guid isPermaLink="false">https://blog.tkt989.info/2018/01/15/Retrofitを使ってみる(Qiita-APIs)</guid><pubDate>Mon, 15 Jan 2018 14:34:36 GMT</pubDate><content:encoded>&lt;h1&gt;準備&lt;/h1&gt;
&lt;p&gt;以下のリンクからQiitaのアクセストークンを取得しておく。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://qiita.com/settings/applications&quot;&gt;アプリケーション - Qiita&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;コード&lt;/h1&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;build.gradle&lt;/code&gt;にretrofit本体と、Stringに変換するconverterを追加。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;groovy&quot;&gt;&lt;pre class=&quot;language-groovy&quot;&gt;&lt;code class=&quot;language-groovy&quot;&gt;     compile &lt;span class=&quot;token string&quot;&gt;&apos;com.squareup.retrofit2:retrofit:2.3.0&apos;&lt;/span&gt;
    compile &lt;span class=&quot;token string&quot;&gt;&apos;com.squareup.retrofit2:converter-scalars:2.3.0&apos;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;APIにアクセスするインターフェイスを作成。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;user/:user_id&lt;/code&gt;を使って、ユーザー情報を取得するようにパスを設定。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://qiita.com/api/v2/docs#get-apiv2usersuser_id&quot;&gt;Qiita API v2ドキュメント - Qiita:Developer&lt;/a&gt;&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;kotlin&quot;&gt;&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;interface&lt;/span&gt; QiitaService &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token annotation builtin&quot;&gt;@GET&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;users/{userId}&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token annotation builtin&quot;&gt;@Path&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;userId&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; userId&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; String&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Call&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;String&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;アクセストークンを&lt;code class=&quot;language-text&quot;&gt;Authorization&lt;/code&gt;に書かないといけないので、&lt;code class=&quot;language-text&quot;&gt;OkHttpClient&lt;/code&gt;を生成して、
ヘッダーを追加。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;kotlin&quot;&gt;&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; okHttpClient &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; OkHttpClient&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addInterceptor&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; chain &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; original &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; chain&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

            &lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; request &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; original&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;newBuilder&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addHeader&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Authorization&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Bearer {ACCESS_TOKNE}&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
                    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

            &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;token label symbol&quot;&gt;@addInterceptor&lt;/span&gt; chain&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;proceed&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;request&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
       &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; retrofit &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; Retrofit&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;Builder&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addConverterFactory&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;ScalarsConverterFactory&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;okHttpClient&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;build&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;QiitaServiceを取得して、APIにリクエストを送る。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;kotlin&quot;&gt;&lt;pre class=&quot;language-kotlin&quot;&gt;&lt;code class=&quot;language-kotlin&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;val&lt;/span&gt; qiitaService &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; retrofit&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;QiitaService&lt;span class=&quot;token operator&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;java&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

qiitaService&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;user&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;tkt989&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;enqueue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Callback&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;String&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;onResponse&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;call&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Call&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;String&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; response&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Response&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;String&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;response&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;isSuccessful &lt;span class=&quot;token operator&quot;&gt;?:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            Log&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;javaClass&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;name&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; response&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;fun&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;onFailure&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;call&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Call&lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;String&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; t&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; Throwable&lt;span class=&quot;token operator&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content:encoded></item><item><title><![CDATA[別プロセスで動いているServiceとHermesEventBusで通信]]></title><description><![CDATA[EventBusって便利ですよね。
特に便利さを実感できるのがActivityとServiceで通信したいときだとおもいます。
ほんとうだったら、BroadcastReceiverクラスを作成して、Actionを定義して、、、としないといけないのですが、EventBus…]]></description><link>https://blog.tkt989.info/2018/01/12/別プロセスで動いているServiceとHermesEventBusで通信</link><guid isPermaLink="false">https://blog.tkt989.info/2018/01/12/別プロセスで動いているServiceとHermesEventBusで通信</guid><pubDate>Fri, 12 Jan 2018 13:50:22 GMT</pubDate><content:encoded>&lt;p&gt;EventBusって便利ですよね。
特に便利さを実感できるのがActivityとServiceで通信したいときだとおもいます。
ほんとうだったら、BroadcastReceiverクラスを作成して、Actionを定義して、、、としないといけないのですが、EventBusだったら&lt;code class=&quot;language-text&quot;&gt;register&lt;/code&gt;して&lt;code class=&quot;language-text&quot;&gt;@Subscribe&lt;/code&gt;するだけで済みます。&lt;/p&gt;
&lt;p&gt;しかし、EventBusで賄えないこともあります。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;android:process&lt;/code&gt;を使ってServiceが別プロセスで動いているときです。
EventBusは同じプロセス内のクラスにしか届きません。&lt;/p&gt;
&lt;h1&gt;HermesEventBus&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/elemers/HermesEventBus&quot;&gt;elemers/HermesEventBus&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;HermesEventBusというライブラリを使えば、プロセス間で通信することができます。&lt;/p&gt;
&lt;p&gt;使い方は、以下のような感じ。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token class-name&quot;&gt;HermesEventBus&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;register&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token class-name&quot;&gt;HermesEventBus&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;HogeEvent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;このように頭にHermesを付けるだけで、EventBusとほぼ同じように使うことができます。&lt;/p&gt;
&lt;p&gt;実際に、別プロセスで動いているServiceに通知できるサンプルコードを作ってみました。&lt;/p&gt;
&lt;h2&gt;サンプル&lt;/h2&gt;
&lt;p&gt;通知するイベントは以下のような感じ。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;GreetEvent&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;String&lt;/span&gt; message&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;GreetEvent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;String&lt;/span&gt; message&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;message &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; message&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getMessage&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; message&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2&gt;だめな例&lt;/h2&gt;
&lt;p&gt;まずはふつうにEventBusを使ってみた場合。&lt;/p&gt;
&lt;p&gt;最初はServiceです。
EventBusに登録して、&lt;code class=&quot;language-text&quot;&gt;@Subscribe&lt;/code&gt;を使ったメソッドを定義しておきます。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;MyService&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Service&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;onStartCommand&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Intent&lt;/span&gt; intent&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt; flags&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt; startId&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;EventBus&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;register&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;onStartCommand&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;intent&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; flags&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; startId&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Subscribe&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;onGreet&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;GreetEvent&lt;/span&gt; event&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;Toast&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;makeText&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; event&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getMessage&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Toast&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;LENGTH_LONG&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;別プロセスで動かすのでマニフェストは以下のようになっています。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;xml&quot;&gt;&lt;pre class=&quot;language-xml&quot;&gt;&lt;code class=&quot;language-xml&quot;&gt; &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;service&lt;/span&gt;
     &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;android:&lt;/span&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;.MyService&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
     &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;android:&lt;/span&gt;process&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;.myservice&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
     &lt;span class=&quot;token attr-name&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;android:process&lt;/code&gt;を指定しています。&lt;/p&gt;
&lt;p&gt;そして、Activityでpostしてみます。
もちろんpostするのはServiceを起動したあとです。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;MainActivity&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;AppCompatActivity&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;onCreate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Bundle&lt;/span&gt; savedInstanceState&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;onCreate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;savedInstanceState&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
        
        &lt;span class=&quot;token class-name&quot;&gt;EventBus&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;GreetEvent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Hello&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3&gt;結果&lt;/h3&gt;
&lt;p&gt;とうぜん、このコードではServiceはイベントを受け取ることはできません。
EventBusはプロセス間通信には対応していないからです。&lt;/p&gt;
&lt;p&gt;では、このコードをHermesEventBusを使うように変更してみましょう。&lt;/p&gt;
&lt;h2&gt;よい例&lt;/h2&gt;
&lt;h3&gt;初期設定&lt;/h3&gt;
&lt;p&gt;はじめに、&lt;code class=&quot;language-text&quot;&gt;build.gradle&lt;/code&gt;に追加しておきましょう。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;groovy&quot;&gt;&lt;pre class=&quot;language-groovy&quot;&gt;&lt;code class=&quot;language-groovy&quot;&gt;dependencies &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;...&lt;/span&gt;
    
    compile &lt;span class=&quot;token string&quot;&gt;&apos;xiaofei.library:hermes-eventbus:0.3.0&apos;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;HermesEventBusを使うにはまず、Applicationクラスで初期化する必要があります。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;MyApplication&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Application&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;onCreate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;onCreate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;token class-name&quot;&gt;HermesEventBus&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;ここで少々手続きが必要です。&lt;/strong&gt;
というのも、HermesEventBusは古いサポートライブラリに依存しているようで、このままだと&lt;code class=&quot;language-text&quot;&gt;ActionBarActivity&lt;/code&gt;が見つからないと言うエラーが発生してしまいます。&lt;/p&gt;
&lt;p&gt;対処法は以下の参照先のように、&lt;code class=&quot;language-text&quot;&gt;android.support.v7.app&lt;/code&gt;パッケージの中に、&lt;code class=&quot;language-text&quot;&gt;ActionBarActivity&lt;/code&gt;を自分で作っておきます。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;token namespace&quot;&gt;android&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;support&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;v7&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;app&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;ActionBarActivity&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;AppCompatActivity&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/elemers/HermesEventBus/issues/42&quot;&gt;适配新版本support库 · Issue #42 · elemers/HermesEventBus&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;HermesEventBusに対応させる&lt;/h3&gt;
&lt;p&gt;あとは、Activity、Serviceの中の&lt;code class=&quot;language-text&quot;&gt;EventBus&lt;/code&gt;を&lt;code class=&quot;language-text&quot;&gt;HermesEventBus&lt;/code&gt;に置き換えます。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;MainActivity&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;AppCompatActivity&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;onCreate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Bundle&lt;/span&gt; savedInstanceState&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;onCreate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;savedInstanceState&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        
        &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
        
        &lt;span class=&quot;token class-name&quot;&gt;HermesEventBus&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;GreetEvent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;Hello&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;MyService&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Service&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;onStartCommand&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Intent&lt;/span&gt; intent&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt; flags&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt; startId&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;HermesEventBus&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getDefault&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;register&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;onStartCommand&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;intent&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; flags&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; startId&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
    
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;こんなふうに単純に書き換えるだけです。&lt;/p&gt;
&lt;h3&gt;結果&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;/2018/01/toast.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;今度は、Toastが表示されます。
別プロセスでも、Serviceに通知が届いていることが確認できたかと思います。&lt;/p&gt;
&lt;h1&gt;まとめ&lt;/h1&gt;
&lt;p&gt;アプリの制作途中にServiceを別プロセスで動かすことになっても、BroadcastReceiverなどを使うよりかは変更する手間は省けます。&lt;/p&gt;
&lt;p&gt;もし、どうしても別プロセスで動かさなければならなくなったときは、便利なライブラリですね。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[ActivityのisFinishing()]]></title><description><![CDATA[Activityのが呼ばれたかどうかをチェックするため、というメソッドがあることを知った。 を使ってしまおうかと思う寸前だった、いやs〜危なかった。
恥ずかしながら知らなかったです。]]></description><link>https://blog.tkt989.info/2018/01/09/ActivityのisFinishing()</link><guid isPermaLink="false">https://blog.tkt989.info/2018/01/09/ActivityのisFinishing()</guid><pubDate>Tue, 09 Jan 2018 08:50:33 GMT</pubDate><content:encoded>&lt;p&gt;Activityの&lt;code class=&quot;language-text&quot;&gt;finish()&lt;/code&gt;が呼ばれたかどうかをチェックするため、&lt;code class=&quot;language-text&quot;&gt;isFinishing()&lt;/code&gt;というメソッドがあることを知った。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;boolean&lt;/code&gt;を使ってしまおうかと思う寸前だった、いやs〜危なかった。
恥ずかしながら知らなかったです。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[カスタムビューでボタンを作る]]></title><description><![CDATA[…]]></description><link>https://blog.tkt989.info/2018/01/06/カスタムビューでボタンを作る</link><guid isPermaLink="false">https://blog.tkt989.info/2018/01/06/カスタムビューでボタンを作る</guid><pubDate>Sat, 06 Jan 2018 05:07:33 GMT</pubDate><content:encoded>&lt;p&gt;
例えば以下のようなボタンを作りたいとします。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/01/custom_button_view.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;デフォルトのボタンでもアイコンは付けられるみたいですが、複雑なレイアウトを作るのはできないみたいです。
なので、カスタムビューを使って実現します。&lt;/p&gt;
&lt;h1&gt;レイアウト作成&lt;/h1&gt;
&lt;p&gt;まずはボタンにしたいカスタムビューのレイアウトファイルを作成します。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/01/custom_button_view_layout.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;ルートレイアウトはなんでもいいのですが、今回はConstraintLayoutを使用しました。&lt;/p&gt;
&lt;p&gt;次にこのレイアウトをボタンのような外見にします。
手順は&lt;strong&gt;ルートレイアウトのstyle属性にボタンのスタイルを設定&lt;/strong&gt;するだけです。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;xml&quot;&gt;&lt;pre class=&quot;language-xml&quot;&gt;&lt;code class=&quot;language-xml&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- view_custom_buttom.xml --&gt;&lt;/span&gt;

&lt;span class=&quot;token prolog&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;android.support.constraint.ConstraintLayout&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;xmlns:&lt;/span&gt;android&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;http://schemas.android.com/apk/res/android&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;xmlns:&lt;/span&gt;app&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;http://schemas.android.com/apk/res-auto&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;android:&lt;/span&gt;layout_width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;wrap_content&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;android:&lt;/span&gt;layout_height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;wrap_content&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token attr-name&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;@style/Widget.AppCompat.Button&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- ↑ここ! --&gt;&lt;/span&gt;
    
    ...

&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;android.support.constraint.ConstraintLayout&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;これで、見た目はボタンそっくり、押したときのリップルもちゃんと表示されデフォルトと瓜二つになりました。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/01/custom_button_view_style.png&quot;&gt;&lt;/p&gt;
&lt;h1&gt;カスタムビュークラス作成&lt;/h1&gt;
&lt;p&gt;次にカスタムビューのクラスを作成します。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// CustomButtonView.java&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;CustomButtonView&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;ConstraintLayout&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;CustomButtonView&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Context&lt;/span&gt; context&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;context&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;CustomButtonView&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Context&lt;/span&gt; context&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;AttributeSet&lt;/span&gt; attrs&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;context&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; attrs&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;token function&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;LayoutInflater&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getContext&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;inflate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;R&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;layout&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;view_custom_button&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;完成？&lt;/h1&gt;
&lt;p&gt;これでいったんActivityに埋め込んでみましょう。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;xml&quot;&gt;&lt;pre class=&quot;language-xml&quot;&gt;&lt;code class=&quot;language-xml&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;&amp;lt;!-- activity_main.xml --&gt;&lt;/span&gt;

....

&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;***.***.CustomButtonView&lt;/span&gt;
        &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;android:&lt;/span&gt;id&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;@+id/custom_button&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;android:&lt;/span&gt;layout_width&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;wrap_content&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;
        &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;android:&lt;/span&gt;layout_height&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;wrap_content&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;

...&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;onClickリスナーもセットしておきます。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// MainActivity.java&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;MainActivity&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;AppCompatActivity&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;onCreate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Bundle&lt;/span&gt; savedInstanceState&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;onCreate&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;savedInstanceState&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token function&quot;&gt;setContentView&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;R&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;layout&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;activity_main&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;token comment&quot;&gt;// インスタンスを取得&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;CustomButtonView&lt;/span&gt; customButton &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;findViewById&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;R&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;id&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;custom_button&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        
        &lt;span class=&quot;token comment&quot;&gt;// onClickにリスナーを設定&lt;/span&gt;
        customButton&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setOnClickListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;View&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;OnClickListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;onClick&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;View&lt;/span&gt; view&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;token class-name&quot;&gt;Toast&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;makeText&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;MainActivity&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Click!&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Toast&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;LENGTH_LONG&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;show&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;さて、これで上手くいきそう思えましたが、動かしてみるとカスタムボタンを&lt;strong&gt;押してもonClickリスナーが呼ばれません。&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;調べてみると以下の記事が参考になりました。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://qiita.com/konifar/items/518fcd6c90252a53bd86&quot;&gt;CustomViewのOnClickが反応しない時の対処方法 - Qiita&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;どうやらカスタムビューの場合はOnClickの処理は自分で書かないといけないみたいです。&lt;/p&gt;
&lt;h1&gt;CustomButtonViewにonClickの処理を追加&lt;/h1&gt;
&lt;p&gt;上記の記事を参考に以下を追加します。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// CustomButtonView.java&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;CustomButtonView&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;ConstraintLayout&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;

    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Nullable&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;OnClickListener&lt;/span&gt; listener&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;setOnClickListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token annotation punctuation&quot;&gt;@Nullable&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;OnClickListener&lt;/span&gt; l&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;listener &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; l&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;dispatchTouchEvent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;MotionEvent&lt;/span&gt; ev&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;ev&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getAction&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;MotionEvent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ACTION_UP&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;listener &lt;span class=&quot;token operator&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;token function&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Runnable&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
                    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
                    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
                        listener&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;onClick&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;CustomButtonView&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
                    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
                &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;dispatchTouchEvent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;ev&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;img src=&quot;/2018/01/custom_button_view_click.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;これでonClickが走るようになりました。&lt;/p&gt;
&lt;h1&gt;ボタンの範囲外にずらしたときの動作を修正&lt;/h1&gt;
&lt;p&gt;これで完成のように思えますがデフォルトのボタンとは微妙に異なる動作があります。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;ボタンをタップ&lt;/li&gt;
&lt;li&gt;ボタンを押したまま指をボタンの範囲外にずらす&lt;/li&gt;
&lt;li&gt;画面から離す&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;上の手順を行うとデフォルトのボタンではonClickは起こらないのですが、作成したCustomButtonViewではイベントが発生してしまいます。&lt;/p&gt;
&lt;p&gt;これを修正するには以下のように&lt;code class=&quot;language-text&quot;&gt;ACTION_UP&lt;/code&gt;のときの座標がボタンの範囲内にあるかをチェックして、範囲内の場合にだけリスナーを呼ぶようにします。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// CustomButtonView.java&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;CustomButtonView&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;ConstraintLayout&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;
    
    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;dispatchTouchEvent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;MotionEvent&lt;/span&gt; ev&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;ev&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getAction&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;MotionEvent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ACTION_UP&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;token comment&quot;&gt;// 範囲内のチェックを追加&lt;/span&gt;
            &lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;listener &lt;span class=&quot;token operator&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;checkInside&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;ev&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;token function&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Runnable&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
                    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
                    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
                        listener&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;onClick&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;CustomButtonView&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
                    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
                &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;dispatchTouchEvent&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;ev&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;token keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;boolean&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;checkInside&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;MotionEvent&lt;/span&gt; ev&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; point &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;token function&quot;&gt;getLocationOnScreen&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;point&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt; x &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; point&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;int&lt;/span&gt; y &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; point&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

        &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;ev&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getRawX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;=&lt;/span&gt; x &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; ev&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getRawX&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;=&lt;/span&gt; x &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getWidth&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt;
                &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;ev&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getRawY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&gt;=&lt;/span&gt; y &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; ev&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getRawY&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;=&lt;/span&gt; y &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getHeight&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;完成!&lt;/h1&gt;
&lt;p&gt;これで、見た目も動作もデフォルトのボタンとほぼ同様なカスタムビューボタンを作ることができました。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Objective-Cで気になったもの(クラス拡張)]]></title><description><![CDATA[最近はiOSアプリの勉強をしています。
都合により、SwiftじゃなくてObjective-Cで書いています。
iOSアプリ開発では言語というよりSDKであるUIKitの使い方を覚えるほうが大事みたいなので、Objective-C…]]></description><link>https://blog.tkt989.info/2018/01/04/Objective-Cで気になったもの(クラス拡張)</link><guid isPermaLink="false">https://blog.tkt989.info/2018/01/04/Objective-Cで気になったもの(クラス拡張)</guid><pubDate>Thu, 04 Jan 2018 13:33:50 GMT</pubDate><content:encoded>&lt;p&gt;最近はiOSアプリの勉強をしています。
都合により、SwiftじゃなくてObjective-Cで書いています。
iOSアプリ開発では言語というよりSDKであるUIKitの使い方を覚えるほうが大事みたいなので、Objective-Cで勉強したとしても無駄にはなりません。&lt;/p&gt;
&lt;p&gt;この記事ではObjective-Cで書いていて気になったものをちょっとメモ。&lt;/p&gt;
&lt;hr&gt;
&lt;h1&gt;疑問&lt;/h1&gt;
&lt;p&gt;XcodeでViewControllerを作成するとヘッダーファイルと&lt;code class=&quot;language-text&quot;&gt;.m&lt;/code&gt;の実装ファイルができる。
ヘッダーの方には&lt;code class=&quot;language-text&quot;&gt;@interface&lt;/code&gt;のクラス宣言が書かれていて、&lt;code class=&quot;language-text&quot;&gt;.m&lt;/code&gt;の方で&lt;code class=&quot;language-text&quot;&gt;@implementation&lt;/code&gt;を使って実際にメソッドの処理を記述するようになっています。&lt;/p&gt;
&lt;p&gt;しかし、自動生成して作ったファイルには実装のほうにも&lt;code class=&quot;language-text&quot;&gt;@interface&lt;/code&gt;がある。
これはなに？&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;objectivec&quot;&gt;&lt;pre class=&quot;language-objectivec&quot;&gt;&lt;code class=&quot;language-objectivec&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;// HogeController.m&lt;/span&gt;

&lt;span class=&quot;token macro property&quot;&gt;#&lt;span class=&quot;token directive keyword&quot;&gt;import&lt;/span&gt; &quot;HogeViewController.h&quot;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;@interface&lt;/span&gt; HogeViewController &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;@end&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;// ↑これ&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;@implementation&lt;/span&gt; HogeViewController

&lt;span class=&quot;token comment&quot;&gt;/*
...
*/&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;@end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;クラス宣言がダブってエラーになったりしないのでしょうか。というかここの中身は、なにも書かなくていいの？&lt;/p&gt;
&lt;p&gt;そのうえ、クラス名のあとに&lt;code class=&quot;language-text&quot;&gt;()&lt;/code&gt;がついていて、ただのクラス宣言と違った特殊な雰囲気を醸し出しています。お前はいったいなんなんだ。&lt;/p&gt;
&lt;h1&gt;クラス拡張&lt;/h1&gt;
&lt;p&gt;調べてみれば、これはクラス拡張というものらしいです。&lt;/p&gt;
&lt;p&gt;Objective-Cには既存のクラスにあとづけでメソッドを追加できる&lt;strong&gt;カテゴリ&lt;/strong&gt;という機能があります。
カテゴリは&lt;code class=&quot;language-text&quot;&gt;@interface NSString (カテゴリ名)&lt;/code&gt;のように、&lt;code class=&quot;language-text&quot;&gt;@interface&lt;/code&gt;のクラス名のあとにカテゴリをカッコで囲むようになっています。&lt;/p&gt;
&lt;p&gt;そのカッコの中身が無くなったのが&lt;strong&gt;クラス拡張&lt;/strong&gt;です。&lt;/p&gt;
&lt;p&gt;実際にはカテゴリとクラス拡張はまったく違う機能みたいなのですが、今のところ似たようなものと理解しておけばいいと思います。&lt;/p&gt;
&lt;p&gt;要するに、すでにクラス宣言した内容にあとづけでいろいろなメソッドやプロパティを追加できるのがクラス拡張です。&lt;/p&gt;
&lt;h1&gt;使いみち&lt;/h1&gt;
&lt;p&gt;privateなメソッドやプロパティを宣言するために使います。&lt;/p&gt;
&lt;p&gt;ヘッダーファイルの&lt;code class=&quot;language-text&quot;&gt;@interface&lt;/code&gt;内に書かれている内容は、importしたファイルからは丸見えになります。
しかし、内部の処理は隠蔽して外部には見せたくないときもありますよね。&lt;/p&gt;
&lt;p&gt;そういうときはクラス拡張の中に書くことで、ヘッダーファイルにはそのメソッドなどの情報がなくなりますので、内部だけで使用することができます。&lt;/p&gt;
&lt;p&gt;JavaやC++では&lt;code class=&quot;language-text&quot;&gt;private&lt;/code&gt;を付ければいいのですが、見た目も特殊なObjective-Cではこういうテクニック？を使うみたいです。&lt;/p&gt;
&lt;h1&gt;参考&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://qiita.com/edo_m18/items/e1f9b5d8c272853a5316&quot;&gt;クラス拡張と無名カテゴリ - Qiita&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.toyship.org/archives/1464&quot;&gt;カテゴリーとクラスエクステンション&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content:encoded></item><item><title><![CDATA[iTermでguakeぽく使う]]></title><description><![CDATA[Mac用ターミナルアプリiTermでLinuxのguakeのような、画面の上部分からニュッと出て来る動作を設定してみました。 プロファイル作成 guake用のプロファイルを作成します。 iTermの Preferences -> Profiles…]]></description><link>https://blog.tkt989.info/2018/01/02/iTermでguakeぽく使う</link><guid isPermaLink="false">https://blog.tkt989.info/2018/01/02/iTermでguakeぽく使う</guid><pubDate>Tue, 02 Jan 2018 12:38:07 GMT</pubDate><content:encoded>&lt;p&gt;Mac用ターミナルアプリiTermでLinuxのguakeのような、画面の上部分からニュッと出て来る動作を設定してみました。&lt;/p&gt;
&lt;h1&gt;プロファイル作成&lt;/h1&gt;
&lt;p&gt;guake用のプロファイルを作成します。&lt;/p&gt;
&lt;p&gt;iTermの Preferences -&gt; Profiles の&lt;code class=&quot;language-text&quot;&gt;+&lt;/code&gt;ボタンを押して新しいプロファイルを作成。
名前は適当に&lt;code class=&quot;language-text&quot;&gt;guake&lt;/code&gt;などにしておきます。&lt;/p&gt;
&lt;p&gt;次はguakeの動作に近づける設定をしていきます。&lt;/p&gt;
&lt;p&gt;プロファイル設定のWindowsタブを選択し以下のように設定。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Styles: Top of Screen&lt;/li&gt;
&lt;li&gt;Screen: MainScreen&lt;/li&gt;
&lt;li&gt;Space: All Spaces&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;また、背景を透明にしたりぼかしたい場合は、TransparencyやBlurを適宜設定します。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/01/iterm_guake_profile.png&quot;&gt;&lt;/p&gt;
&lt;h1&gt;ショートカットキーの設定&lt;/h1&gt;
&lt;p&gt;次はターミナルを出すためのショートカットを設定します。&lt;/p&gt;
&lt;p&gt;Kyesタブの&lt;code class=&quot;language-text&quot;&gt;A hotkey opens a dedicated window with this profile.&lt;/code&gt;にチェックを入れると、ダイアログが出てきます。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;HotKey&lt;/code&gt;に使用したいショートカットキーを設定し、&lt;code class=&quot;language-text&quot;&gt;Floating window&lt;/code&gt;のチェックを外します。&lt;/p&gt;
&lt;p&gt;私はF12に割り当てました。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/01/iterm_guake_keys.png&quot;&gt;&lt;/p&gt;
&lt;p&gt;これで作業は終了です。&lt;/p&gt;
&lt;p&gt;F12を押せば画面の上からターミナルが出て来るようになりました。&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/2018/01/iterm_guake_desktop.png&quot;&gt;
こんな感じ。&lt;/p&gt;
&lt;h1&gt;guake風のときはtmuxを使わないようにする&lt;/h1&gt;
&lt;p&gt;tmuxを自動起動するように設定していると、このguake風ターミナルを開いたときにも既に起動しているセッションにアタッチするようになります。&lt;/p&gt;
&lt;p&gt;個人的にはこのターミナルは他のものとは独立して動かしたいなと思ってます。&lt;/p&gt;
&lt;p&gt;iTermでシェルを開いたときには&lt;code class=&quot;language-text&quot;&gt;env&lt;/code&gt;の&lt;code class=&quot;language-text&quot;&gt;ITERM_PROFILE&lt;/code&gt;にiTermのプロファイル名が入るので、これを使って以下のようにtmuxが起動しないようにしました。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;.zshrc&lt;/code&gt;や&lt;code class=&quot;language-text&quot;&gt;.bashrc&lt;/code&gt;でtmuxが起動するようにしている場合は、以下のように&lt;code class=&quot;language-text&quot;&gt;$TMUX&lt;/code&gt;を調べてtmux内にいるかどうかを調べるようになっているはずです。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt; -z &lt;span class=&quot;token variable&quot;&gt;$TMUX&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;then&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;..&lt;/span&gt;.
&lt;span class=&quot;token keyword&quot;&gt;fi&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;この条件にプロファイルが&lt;code class=&quot;language-text&quot;&gt;guake&lt;/code&gt;かどうか入れて、&lt;code class=&quot;language-text&quot;&gt;guake&lt;/code&gt;の場合は起動しないようにします。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt; -z &lt;span class=&quot;token variable&quot;&gt;$TMUX&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;token variable&quot;&gt;$ITERM_PROFILE&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;guake&quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;then&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;..&lt;/span&gt;.
&lt;span class=&quot;token keyword&quot;&gt;fi&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;これで開いてもtmuxが起動しないようになりました。&lt;/p&gt;
&lt;p&gt;いつでもどこでもターミナルにアクセスできるようになったので快適。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Macbook Pro 13インチ 購入]]></title><description><![CDATA[構成 13インチ TouchBarなし Core i5 メモリ 16GB SSD 512GB です。 理由 everymacというサイトで調べてみるとCore i5の型番は7360Uです。
i7は7666U…]]></description><link>https://blog.tkt989.info/2018/01/01/Macbook-Pro-13インチ-購入</link><guid isPermaLink="false">https://blog.tkt989.info/2018/01/01/Macbook-Pro-13インチ-購入</guid><pubDate>Mon, 01 Jan 2018 07:05:24 GMT</pubDate><content:encoded>&lt;img src=&quot;/2018/01/Desktop.jpg&quot;&gt;
&lt;h1&gt;構成&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;13インチ&lt;/li&gt;
&lt;li&gt;TouchBarなし&lt;/li&gt;
&lt;li&gt;Core i5&lt;/li&gt;
&lt;li&gt;メモリ 16GB&lt;/li&gt;
&lt;li&gt;SSD 512GB&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;です。&lt;/p&gt;
&lt;h2&gt;理由&lt;/h2&gt;
&lt;p&gt;everymacというサイトで調べてみるとCore i5の型番は7360Uです。
i7は7666Uなのですが、ベンチマークのスコアを比べてみるとそんなに違いがないみたいです。
7360Uよりもスコアが低いPCで開発用のアプリを動かしていたとき、そんなに不満を感じなかったのでi7はまではいらないかなと思いi5にしました。&lt;/p&gt;
&lt;p&gt;メモリはデフォルトの8GBから16GBに変更。
開発用に使うにはCPUよりもメモリが贅沢なほうがいいと思います。&lt;/p&gt;
&lt;p&gt;SSDは256GBと最後まで迷いました。
デスクトップPCを持っているのでこっちのMacbookにデータを溜め込むことはないです。
しかし、いろいろアプリを入れたりするとあっという間に消費してしまいそう。
その上、VirtualBoxやBootcampを使ったりすると256GBは少々不安でした。&lt;/p&gt;
&lt;p&gt;残り容量に怯えながら使うとせっかくのMac環境を満喫できなさそうなので、思い切って512GBにしました。&lt;/p&gt;
&lt;h1&gt;使ってみての感想&lt;/h1&gt;
&lt;p&gt;&lt;strong&gt;Taptic Engineがすごい。&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;凹んでないのに押している感覚があります。その証拠に電源を消したら反応がなくなります。本当に魔法みたいです。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;画面がきれい&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;もともとMacは文字レンダリングがWindowsと違って美しいですが、Retinaディスプレイと合わさって&lt;/p&gt;
&lt;p&gt;ちょっとギラギラで反射が強いので電子書籍を読んでいるときは目が疲れやすい感じがしました。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;開発用のソフトウェアが充実してる&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;WindowsではUnix系のコマンドを使いたいときは仮想環境にUbuntuを入れていたのですが、Macだと一台で普段使いと開発の両方ができるのがいいですね。&lt;/p&gt;
&lt;p&gt;一台で完結できるのは便利です。&lt;/p&gt;
&lt;p&gt;まだまだWindowsとの違いに慣れないところが多いのですが大切にして長く使っていきたいな。&lt;/p&gt;
&lt;h1&gt;インストールした便利アプリ&lt;/h1&gt;
&lt;h2&gt;Xcode&lt;/h2&gt;
&lt;p&gt;基本ですね。
開発系のコマンドや下のHomebrewを入れるのにも必須のアプリです。
iOSプログラミングもやってみたいですね、今までAndroidだけだったので。&lt;/p&gt;
&lt;h2&gt;Homebrew&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://brew.sh/index_ja.html&quot;&gt;Homebrew&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Ubuntuのaptみたいなパッケージマネージャー。&lt;/p&gt;
&lt;p&gt;CLIツールをインストールできる、だけでなく開発系以外のアプリもあるみたいです。
同じアプリでも、普通に配布サイトからダウンロードしてアプリケーションフォルダに入れるよりも、こちらから入れたほうが管理しやすいかもしれませんね。&lt;/p&gt;
&lt;p&gt;こういうツールは他にもMacportなどがあるみたいですが、人気の高さからHomebrewを選択。
色々なツールのMac用インストール方法でもHomebrewが採用されている気がします。&lt;/p&gt;
&lt;h2&gt;Visual Studio Code&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://code.visualstudio.com/&quot;&gt;Visual Studio Code&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;プログラミング用のエディタ。
何も拡張機能を入れてないデフォルトの状態でも使いやすい。&lt;/p&gt;
&lt;h2&gt;Alfred&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://www.alfredapp.com/&quot;&gt;Alfred&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;いろんなサイトでおすすめされてるアプリ。
テキストに打ち込んで様々なアプリやコマンドを実行することができます。
Macにデフォルトで付いているSpotlightがまさに同じ機能を提供しているのですが、こちらのほうがカスタマイズ性が高いみたいです。&lt;/p&gt;
&lt;h2&gt;Docker For Mac&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://www.docker.com/docker-mac&quot;&gt;Docker For Mac&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Linuxの仮想環境を簡単に作ったり壊したりできます。
新しいツールとか言語とかを使ってみたいときにDocker上の仮想環境に入れてから使っています。
Macに直接入れてもいいのですが、たくさん入れすぎると何をインストールしたのか忘れてしまって環境が汚れてしまうのが嫌なのでDockerを使っています。&lt;/p&gt;
&lt;h2&gt;BetterTouchTool&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://www.boastr.net/&quot;&gt;BetterTouchTool&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;トラックパッドのジェスチャーを追加できます。
また、ウインドウを画面横に押し付けると自動的に画面半分を専有するようにリサイズするWindows10のスナップみたいな機能もあります。
有料だけど45日間は試用期間があります。&lt;/p&gt;
&lt;h2&gt;f.lux&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://justgetflux.com/&quot;&gt;f.lux&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;ディスプレイの色温度を変えて目が疲れにくくしてくれます。
日没に応じて変化してくれる機能もあります。&lt;/p&gt;
&lt;h2&gt;AppCleaner&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://freemacsoft.net/appcleaner/&quot;&gt;AppCleaner&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;アプリをアンインストールするツール。
基本的にはアプリケーションフォルダから消すだけでアンインストールできるのですが、これを使えば設定ファイルなども消してくれるので完全にアンインストールすることができます。&lt;/p&gt;
&lt;h2&gt;KeePassX&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://www.keepassx.org/&quot;&gt;KeePassX&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;パスワード管理ソフト。&lt;/p&gt;
&lt;p&gt;オープンソースで他のプラットフォームのアプリもあるので、データベースであるkbdxファイルを共有すれば様々なデバイスから管理してるパスワードを参照できます。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Docker Composeのportsとexposeの違い]]></title><description><![CDATA[…]]></description><link>https://blog.tkt989.info/2017/12/19/Docker-Composeのportsとexposeの違い</link><guid isPermaLink="false">https://blog.tkt989.info/2017/12/19/Docker-Composeのportsとexposeの違い</guid><pubDate>Tue, 19 Dec 2017 14:13:49 GMT</pubDate><content:encoded>&lt;p&gt;どちらとも指定したポートに穴を開けるコマンドですが、少し用途が違います。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;ports&lt;/code&gt;は指定したポートが外部に公開されるので、誰でもアクセスできる状態になります。
いっぽう&lt;code class=&quot;language-text&quot;&gt;expose&lt;/code&gt;はホストのみにポートを公開します。&lt;/p&gt;
&lt;p&gt;リバースプロキシで外部からのアクセスを振り分ける構成を作っていたときに、振り分け先のコンテナが丸見えだったのでメモ。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[ReactNativeを少しだけ]]></title><description><![CDATA[インストール プロジェクトを作成 に以下のファイルが生成されます。 動かす ReactNativeはIOSやAndroid向けにネイティブコードへビルドできますが、Expoというアプリを使えばXcodeやAndroidSDK…]]></description><link>https://blog.tkt989.info/2017/12/12/ReactNativeを少しだけ</link><guid isPermaLink="false">https://blog.tkt989.info/2017/12/12/ReactNativeを少しだけ</guid><pubDate>Tue, 12 Dec 2017 13:51:06 GMT</pubDate><content:encoded>&lt;h1&gt;インストール&lt;/h1&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;npm&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;install&lt;/span&gt; -g create-react-native-app&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;プロジェクトを作成&lt;/h1&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;create-react-native-app reactnative-tutorial&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;reactnative-tutorial&lt;/code&gt;に以下のファイルが生成されます。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token builtin class-name&quot;&gt;.&lt;/span&gt;
├── App.js
├── App.test.js
├── README.md
├── app.json
└── package.json&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;動かす&lt;/h1&gt;
&lt;p&gt;ReactNativeはIOSやAndroid向けにネイティブコードへビルドできますが、Expoというアプリを使えばXcodeやAndroidSDKをインストールせずお手軽にアプリの動作を確認することができます。&lt;/p&gt;
&lt;p&gt;アプリストアからExpoをインストールしておきます。&lt;/p&gt;
&lt;p&gt;その後&lt;code class=&quot;language-text&quot;&gt;npm start&lt;/code&gt;を実行。
QRコードが出てくるので、Expoから読み込む。
JSファイルのビルドが終了したらアプリの画面がでてきます。&lt;/p&gt;
&lt;h1&gt;いじる&lt;/h1&gt;
&lt;p&gt;App.jsは以下になっています。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; React &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;react&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; 
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; StyleSheet&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Text&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; View &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;react-native&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; 
 
&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;App&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Component&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; 
  &lt;span class=&quot;token function&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; 
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt; 
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;View&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;styles&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;container&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt; 
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Text&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;Open up App.js to start working on your app!&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Text&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt; 
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Text&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;Changes you make will automatically reload.&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Text&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt; 
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Text&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;Shake your phone to open the developer menu.&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Text&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt; 
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;View&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; 
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; 
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; 
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; 
 
&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; styles &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; StyleSheet&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; 
  container&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; 
    flex&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 
    backgroundColor&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;#fff&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 
    alignItems&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;center&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 
    justifyContent&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;center&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; 
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Reactとほぼおんなじです。違いは&lt;code class=&quot;language-text&quot;&gt;div&lt;/code&gt;や&lt;code class=&quot;language-text&quot;&gt;span&lt;/code&gt;の代わりに&lt;code class=&quot;language-text&quot;&gt;View&lt;/code&gt;や&lt;code class=&quot;language-text&quot;&gt;Text&lt;/code&gt;というReatNativeのコンポーネントを使っていることです。&lt;/p&gt;
&lt;p&gt;CSSもそのまま動くので、backgroundColorなどを変えればアプリに反映されます。&lt;/p&gt;
&lt;p&gt;テキストボックスの&lt;code class=&quot;language-text&quot;&gt;TextInput&lt;/code&gt;を使って少しいじってみました。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;jsx&quot;&gt;&lt;pre class=&quot;language-jsx&quot;&gt;&lt;code class=&quot;language-jsx&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; React &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;react&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; StyleSheet&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; Text&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; View&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; TextInput &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;react-native&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;default&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;App&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;extends&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;React&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;Component&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;props&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;props&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;state &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;text&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;token function&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;
      &lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;View&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;styles&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;container&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;TextInput&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;style&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;styles&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;input&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;onChangeText&lt;/span&gt;&lt;span class=&quot;token script language-javascript&quot;&gt;&lt;span class=&quot;token script-punctuation punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setState&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;text&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Text&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;state&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;text &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Text&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token plain-text&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;View&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; styles &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; StyleSheet&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
  container&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    flex&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    backgroundColor&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;#fff&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    alignItems&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;center&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
    justifyContent&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;center&apos;&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  input&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    width&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&apos;60%&apos;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;入力した内容を表示するだけの簡単なもの。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Google Play ServiceのFusedLocationで位置情報を取得]]></title><description><![CDATA[Androidで位置情報を取得する方法は、一昔前はが使われていたようですが現在はのを使うのが推奨されています。 では位置情報の取得にGPSを使うか、WIFI…]]></description><link>https://blog.tkt989.info/2017/12/09/Google-Play-ServiceのFusedLocationで位置情報を取得</link><guid isPermaLink="false">https://blog.tkt989.info/2017/12/09/Google-Play-ServiceのFusedLocationで位置情報を取得</guid><pubDate>Sat, 09 Dec 2017 13:50:31 GMT</pubDate><content:encoded>&lt;p&gt;Androidで位置情報を取得する方法は、一昔前は&lt;code class=&quot;language-text&quot;&gt;LocationManager&lt;/code&gt;が使われていたようですが現在は&lt;code class=&quot;language-text&quot;&gt;Google Play Service&lt;/code&gt;の&lt;code class=&quot;language-text&quot;&gt;FusedLocation&lt;/code&gt;を使うのが推奨されています。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;LocationManager&lt;/code&gt;では位置情報の取得にGPSを使うか、WIFIやモバイルネットワークを使うかを指定しなければなりませんでしたが、&lt;code class=&quot;language-text&quot;&gt;FusedLocation&lt;/code&gt;ではライブラリ側が適切な取得方法を自動的に判断してくれます。使う側は「高精度で取得したい」とか「大雑把でいいからバッテリー持ちを重視したい」な感じで設定するだけでいいんです。&lt;/p&gt;
&lt;h1&gt;ライブラリの追加&lt;/h1&gt;
&lt;p&gt;プロジェクトルートの&lt;code class=&quot;language-text&quot;&gt;build.gradle&lt;/code&gt;の&lt;code class=&quot;language-text&quot;&gt;repository&lt;/code&gt;に&lt;code class=&quot;language-text&quot;&gt;google()&lt;/code&gt;を追加します。
その後使用するモジュール内の&lt;code class=&quot;language-text&quot;&gt;build.gradle&lt;/code&gt;の&lt;code class=&quot;language-text&quot;&gt;dependencies&lt;/code&gt;に&lt;code class=&quot;language-text&quot;&gt;implementation &amp;quot;com.google.android.gms:play-services-location:11.6.0&amp;quot;&lt;/code&gt;を追加します。
&lt;code class=&quot;language-text&quot;&gt;11.6.0&lt;/code&gt;の部分はバージョンなので、変わる可能性があります。この記事を書いているときはこれが一番新しいバージョンでした。&lt;/p&gt;
&lt;p&gt;バージョンに何を指定するかは、以下のサイトで取得できます。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://developers.google.com/android/guides/setup&quot;&gt;https://developers.google.com/android/guides/setup&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;追加したらGradleの同期を行います。&lt;/p&gt;
&lt;h1&gt;パーミッションの追加&lt;/h1&gt;
&lt;p&gt;位置情報の取得にはパーミッションの追加が必要なので&lt;code class=&quot;language-text&quot;&gt;AndroidManifest.xml&lt;/code&gt;に以下を追加します。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;xml&quot;&gt;&lt;pre class=&quot;language-xml&quot;&gt;&lt;code class=&quot;language-xml&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;uses-permission&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;android:&lt;/span&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;android.permission.ACCESS_FINE_LOCATION&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;uses-permission&lt;/span&gt; &lt;span class=&quot;token attr-name&quot;&gt;&lt;span class=&quot;token namespace&quot;&gt;android:&lt;/span&gt;name&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;android.permission.ACCESS_COARSE_LOCATION&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;/&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;また、デバイスで動かすときには&lt;code class=&quot;language-text&quot;&gt;RuntimePermission&lt;/code&gt;を使ってユーザーから許可を得る必要があります。
今回は動作確認したいだけなので、設定画面から手動で許可を通します。&lt;/p&gt;
&lt;h1&gt;現在の位置を取得&lt;/h1&gt;
&lt;p&gt;以下から実際のコードで書く部分です。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;FusedLocationProviderClient&lt;/code&gt;というクラスを生成します。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token class-name&quot;&gt;FusedLocationProviderClient&lt;/span&gt; client &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;FusedLocationProviderClient&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;このクラスを通して位置情報を取得することができます。&lt;/p&gt;
&lt;p&gt;現在の位置を取得するには&lt;code class=&quot;language-text&quot;&gt;getLastLocation()&lt;/code&gt;を呼び出します。このメソッドは非同期で実行されて代わりに&lt;code class=&quot;language-text&quot;&gt;Task&lt;/code&gt;というオブジェクトを返します。この&lt;code class=&quot;language-text&quot;&gt;Task&lt;/code&gt;の&lt;code class=&quot;language-text&quot;&gt;addOnSuccessListener&lt;/code&gt;にリスナーを指定して位置情報を取得します。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;client&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getLastLocation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addOnSuccessListener&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;OnSuccessListener&lt;/span&gt;&lt;span class=&quot;token generics&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Location&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;onSuccess&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Location&lt;/span&gt; location&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;/* ... */&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;Location&lt;/code&gt;から緯度経度を得ることができます。&lt;/p&gt;
&lt;h1&gt;リアルタイムで位置を取得&lt;/h1&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;requestLocationUpdates(ReuqestLocation, LocationCallback, Looper)&lt;/code&gt;でリアルタイム位置情報を取得することができます。&lt;/p&gt;
&lt;p&gt;RequestLocationは取得する際のパラメーターを設定します。
LocationCallbackは更新された内容を受け取るリスナーです。
Looperはスレッド関係の設定なのですが、あんまり詳しくないので今回はnullを指定します。&lt;/p&gt;
&lt;h2&gt;ReuqestLocation&lt;/h2&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;RequestLocation&lt;/code&gt;でパラメータを設定できます。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token class-name&quot;&gt;LocationRequest&lt;/span&gt; locationRequest &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;LocationRequest&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setPriority&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;LocationRequest&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;PRIORITY_HIGH_ACCURACY&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;setPriority()&lt;/code&gt;でどのくらいの精度で取得したいのかを設定できます。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;HIGH_ACCURACY&lt;/code&gt;が最も高い精度で主にGPSが使用されるます。
&lt;code class=&quot;language-text&quot;&gt;BALANCED_POWER_ACCURACY&lt;/code&gt;はちょっと精度が低くなり、誤差は100メートルほどになりますが、消費電力を低く抑えることができます。
細かい位置情報は必要ない。ユーザーがどの都市にいるのかという大雑把な情報が欲しい場合は&lt;code class=&quot;language-text&quot;&gt;LOW_POWER&lt;/code&gt;を使います。
&lt;code class=&quot;language-text&quot;&gt;NO_POWER&lt;/code&gt;は消費電力をほとんど使いません、他のクライアントが位置情報をリクエストしたときに同じデータを取得できます。&lt;/p&gt;
&lt;p&gt;他にも更新間隔などを設定できます。詳細は以下に載っています。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest&quot;&gt;https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;LocationCallback&lt;/h2&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;LocationCallback&lt;/code&gt;が位置情報が更新されたときに受け取るリスナーです。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;onLocationResult()&lt;/code&gt;で受け取ることができます。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;client&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;requestLocationUpdates&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;locationRequest&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;LocationCallback&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token annotation punctuation&quot;&gt;@Override&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;onLocationResult&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;LocationResult&lt;/span&gt; locationResult&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token keyword&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;onLocationResult&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;locationResult&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;token class-name&quot;&gt;Location&lt;/span&gt; location &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; locationResult&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getLastLocation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;注意点&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;requestLocationUpdates()&lt;/code&gt;を実行したら、使わなくなったら&lt;code class=&quot;language-text&quot;&gt;removeLocationUpdates()&lt;/code&gt;を呼び出してリスナーを解除すること。&lt;/li&gt;
&lt;li&gt;&lt;code class=&quot;language-text&quot;&gt;getLastLocation()&lt;/code&gt;はnullを返すときがあります。以前タブレットでWIFIを切り、GPSのみで使用していたときに毎回nullが返ってきたため何か設定で失敗しているのかなと思っていました。がWIFIをオンにしたら結果を返すようになりました。おそらく屋内だったのでGPSだけでは位置情報を取得できなかったのだと思います。&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;普段で使うようなアプリでは、モバイルネットワークやWIFIなど複数の情報源から位置を取得しているため、GPSって屋内だとほとんど届かないことに気づきにくかったです。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[NginxでLet's Encrypt]]></title><description><![CDATA[無料でSSL証明書を取得できるLet’s Encryptでnginxをhttps対応にしました。 SSL証明書には以下の三種類があり、下に向かう順に取得するための審査が厳しくなります。 DV(ドメイン認証)証明書 OV(企業認証)証明書 EV証明書 DV…]]></description><link>https://blog.tkt989.info/2017/12/03/NginxでLet&apos;s-Encrypt</link><guid isPermaLink="false">https://blog.tkt989.info/2017/12/03/NginxでLet&apos;s-Encrypt</guid><pubDate>Sun, 03 Dec 2017 11:24:39 GMT</pubDate><content:encoded>&lt;p&gt;無料でSSL証明書を取得できるLet’s Encryptでnginxをhttps対応にしました。&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;SSL証明書には以下の三種類があり、下に向かう順に取得するための審査が厳しくなります。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;DV(ドメイン認証)証明書&lt;/li&gt;
&lt;li&gt;OV(企業認証)証明書&lt;/li&gt;
&lt;li&gt;EV証明書&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;DV証明書&lt;/strong&gt;はドメインを所持していれば発行してもらえる証明書です。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;OV証明書&lt;/strong&gt;ではドメインの所持だけでなく、第三者機関や電話での確認によって実在性が確認できて発行されてもらえます。&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;EV証明書&lt;/strong&gt;では実在性の確認をもっと厳格に行うので最も信頼性が高い証明書です。&lt;/p&gt;
&lt;p&gt;Let’s encryptではこの内のDV証明書を&lt;strong&gt;無料&lt;/strong&gt;で発行しています。&lt;/p&gt;
&lt;hr&gt;
&lt;h1&gt;環境&lt;/h1&gt;
&lt;ul&gt;
&lt;li&gt;ConohaVPS&lt;/li&gt;
&lt;li&gt;Ubuntu 16.04 64bit&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;letsencryptのインストール&lt;/h1&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;sudo&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;apt-get&lt;/span&gt; intstall letsencrypt&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;apt経由でインストールします。&lt;/p&gt;
&lt;h1&gt;コマンドの実行&lt;/h1&gt;
&lt;p&gt;let’s encryptは指定されたドメインでサーバーにアクセスできることを確認する必要があります。
通常は80ポートを使うのですが、nginxが動いているので代わり443ポートで認証を行うようにしました。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# --standalone-supported-challenges tls-sni-01をつけると443ポートで認証を行う。&lt;/span&gt;
&lt;span class=&quot;token function&quot;&gt;sudo&lt;/span&gt; letsencrypt certonly --standalone --standalone-supported-challenges tls-sni-01 &lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;コマンドを実行すると証明書関連の通知を行う先のメールアドレスの入力があります。
その後ドメインの入力があるので、https通信したいドメインを入力します。&lt;/p&gt;
&lt;p&gt;サブドメインでも使いたい場合は、カンマ区切りで入力します。&lt;/p&gt;
&lt;p&gt;正しく認証ができたら&lt;code class=&quot;language-text&quot;&gt;Congratulations&lt;/code&gt;のメッセージが出て、&lt;code class=&quot;language-text&quot;&gt;/etc/letsencrypt/live/[domain]&lt;/code&gt;に証明書が生成されます。&lt;/p&gt;
&lt;p&gt;うまく行かなかったときは、認証を行うポートが開いているか確認しましょう。&lt;/p&gt;
&lt;h1&gt;nginxの設定&lt;/h1&gt;
&lt;p&gt;nginxの設定ファイルに以下を書く。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;ssl_certificate /etc/letsencrypt/live/&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;domain&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;/fullchain.pem&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
ssl_certificate_key /etc/letsencrypt/live/&lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;domain&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;/privkey.pem&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;同じく設定ファイルの&lt;code class=&quot;language-text&quot;&gt;server&lt;/code&gt;内をポートを443に、SSL通信をオンにするように設定する。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;server &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    listen: &lt;span class=&quot;token number&quot;&gt;443&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    ssl on&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    
    &lt;span class=&quot;token punctuation&quot;&gt;..&lt;/span&gt;.
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;その後再起動、ブラウザを開いてhttpsで通信できているか確認する。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[ConohaVPSの初期設定]]></title><description><![CDATA[ConohaVPSを使い始めたので、初期設定を記録しておく。 使用しているOSはUbunto16.04。 パッケージを更新 ファイアウォールを設定 ssh以外のポートを閉じる 一般ユーザーを作成 sudoを使うためにグループにユーザーを追加します。 rootでのssh…]]></description><link>https://blog.tkt989.info/2017/12/02/ConohaVPSの初期設定</link><guid isPermaLink="false">https://blog.tkt989.info/2017/12/02/ConohaVPSの初期設定</guid><pubDate>Sat, 02 Dec 2017 06:56:42 GMT</pubDate><content:encoded>&lt;p&gt;ConohaVPSを使い始めたので、初期設定を記録しておく。&lt;/p&gt;
&lt;p&gt;使用しているOSはUbunto16.04。&lt;/p&gt;
&lt;h1&gt;パッケージを更新&lt;/h1&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# apt-get update&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# apt-get upgrade&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;ファイアウォールを設定&lt;/h1&gt;
&lt;p&gt;ssh以外のポートを閉じる&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# ufw default deny&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# ufw allow ssh&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# ufw enable&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h1&gt;一般ユーザーを作成&lt;/h1&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# useradd -m -g sudo -s /bin/bash [user]&lt;/span&gt;
&lt;span class=&quot;token comment&quot;&gt;# passwd [user]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;sudoを使うために&lt;code class=&quot;language-text&quot;&gt;sudo&lt;/code&gt;グループにユーザーを追加します。&lt;/p&gt;
&lt;h1&gt;rootでのsshログインを禁止&lt;/h1&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;/etc/ssh/sshd_config&lt;/code&gt;の&lt;code class=&quot;language-text&quot;&gt;PermitRootLogin yes&lt;/code&gt;を&lt;code class=&quot;language-text&quot;&gt;no&lt;/code&gt;に変更&lt;/p&gt;
&lt;h1&gt;ssh公開鍵を設定、パスワードログインを禁止&lt;/h1&gt;
&lt;p&gt;パスワードでログイン出来ないようにするために公開鍵を設定しておきます。&lt;/p&gt;
&lt;p&gt;Linuxの場合は&lt;code class=&quot;language-text&quot;&gt;ssh-keygen&lt;/code&gt;、Windowsの場合はrloginなどのクライアントで作成した公開鍵ファイルを
&lt;code class=&quot;language-text&quot;&gt;~/.ssh/authorized_keys&lt;/code&gt;に追記。&lt;/p&gt;
&lt;p&gt;その後パスワードでのログインを禁止するために
&lt;code class=&quot;language-text&quot;&gt;/etc/ssh/sshd_config&lt;/code&gt;の&lt;code class=&quot;language-text&quot;&gt;PasswordAuthentication yes&lt;/code&gt;を&lt;code class=&quot;language-text&quot;&gt;no&lt;/code&gt;に変更します。&lt;/p&gt;
&lt;h1&gt;sshのポート番号を変更&lt;/h1&gt;
&lt;p&gt;デフォルトのままだと不正ログインを試みようとする人たちが大量に来るので、変更しておきます。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;/etc/ssh/sshd_config&lt;/code&gt;の&lt;code class=&quot;language-text&quot;&gt;Port 22&lt;/code&gt;を49152~65535の適当な数に変更。&lt;/p&gt;
&lt;p&gt;ufwで指定したポート番号を許可。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;$ &lt;span class=&quot;token function&quot;&gt;sudo&lt;/span&gt; ufw allow &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;port&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;ポート番号を変えてログインできるのを確認できたら、デフォルトのポートを閉じます。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;$ &lt;span class=&quot;token function&quot;&gt;sudo&lt;/span&gt; ufw delete allow &lt;span class=&quot;token function&quot;&gt;ssh&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;その後、sshdを再起動。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;bash&quot;&gt;&lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;$ &lt;span class=&quot;token function&quot;&gt;sudo&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;service&lt;/span&gt; sshd restart&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content:encoded></item><item><title><![CDATA[CompletableとSingleが混ざった処理を行う方法]]></title><description><![CDATA[…]]></description><link>https://blog.tkt989.info/2017/11/30/CompletableとSingleが混ざった処理を行う方法</link><guid isPermaLink="false">https://blog.tkt989.info/2017/11/30/CompletableとSingleが混ざった処理を行う方法</guid><pubDate>Thu, 30 Nov 2017 13:02:30 GMT</pubDate><content:encoded>&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Completable&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;connect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;/* ... */&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Single&lt;/span&gt;&lt;span class=&quot;token generics&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Integer&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;getValue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;/* ... */&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Completable&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;disconnect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;/* .. */&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;例えばこんなメソッドがあるとする。&lt;/p&gt;
&lt;p&gt;何かと接続し、値を取得して切断するという処理で。呼び出す順番は必ず&lt;code class=&quot;language-text&quot;&gt;connect()&lt;/code&gt; &gt; &lt;code class=&quot;language-text&quot;&gt;getValue()&lt;/code&gt; &gt; &lt;code class=&quot;language-text&quot;&gt;disconnect()&lt;/code&gt; でなければならない。&lt;/p&gt;
&lt;p&gt;ところで、&lt;code class=&quot;language-text&quot;&gt;Completable&lt;/code&gt;をメソッドチェーンを使って直列に処理したい場合以下のようにすればいい。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token function&quot;&gt;connect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;andThen&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;task1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;andThen&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;task2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* ... */&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;andThen&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;disconnect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;subscribe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token comment&quot;&gt;/* ... */&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;しかし、直列処理の途中で&lt;code class=&quot;language-text&quot;&gt;Single&lt;/code&gt;が混ざったときはどのように書くのか?&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;toCompletable()&lt;/code&gt;や&lt;code class=&quot;language-text&quot;&gt;flatMapCompletable()&lt;/code&gt;を使えば一応繋げられるけど、&lt;code class=&quot;language-text&quot;&gt;getValue()&lt;/code&gt;の結果を無視してしまっている。。。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token function&quot;&gt;connect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;andThen&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getValue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toCompletable&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;andThen&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;disconnect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;subscribe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token comment&quot;&gt;/* ... */&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;token comment&quot;&gt;/* ... */&lt;/span&gt;

&lt;span class=&quot;token function&quot;&gt;connect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;andThen&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getValue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;flatMapCompletable&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;disconnect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token comment&quot;&gt;// valueのスコープはこのラムダ式内なのでsubscribeの中で参照できない。。。&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;subscribe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token comment&quot;&gt;/* ... */&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;どうやればいいか悩んでいたのですが、調べた結果以下のようにすればいいです。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token function&quot;&gt;connect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;andThen&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getValue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;flatMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;disconnect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;andThen&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Single&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;just&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;subscribe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;/* ... */&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;これで&lt;code class=&quot;language-text&quot;&gt;subscribe()&lt;/code&gt;で値を参照することができます。&lt;/p&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;Single&lt;/code&gt;のあとに複数の処理があっても、値を次々と受け渡していけばOKです。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token function&quot;&gt;connect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;andThen&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;getValu&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;flatMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;task1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;andThen&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Single&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;just&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;flatMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;task2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;andThen&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Single&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;just&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token comment&quot;&gt;/* ... */&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;flatMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;disconnect&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;andThen&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Single&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;just&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;subscribe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;/* ... */&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;</content:encoded></item><item><title><![CDATA[テスト駆動開発を読んだ]]></title><description><![CDATA[その名の通り、テスト駆動開発の本です。 著者の方がブログで、この本について書いているのを見て、すぐに読みたいと思い購入。 私はわりと出版されてから数日後くらいの早めに購入したので無事に手に入れることができたのですが、最近まではAmazon…]]></description><link>https://blog.tkt989.info/2017/11/28/テスト駆動開発を読んだ</link><guid isPermaLink="false">https://blog.tkt989.info/2017/11/28/テスト駆動開発を読んだ</guid><pubDate>Tue, 28 Nov 2017 13:50:07 GMT</pubDate><content:encoded>&lt;iframe style=&quot;width:120px;height:240px;&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; src=&quot;https://rcm-fe.amazon-adsystem.com/e/cm?ref=qf_sp_asin_til&amp;t=blogtkt989inf-22&amp;m=amazon&amp;o=9&amp;p=8&amp;l=as1&amp;IS1=1&amp;detail=1&amp;asins=4274217884&amp;linkId=ec42af4efa915d11101baf46d00322c2&amp;bc1=ffffff&amp;lt1=_blank&amp;fc1=333333&amp;lc1=0066c0&amp;bg1=ffffff&amp;f=ifr&quot;&gt;
    &lt;/iframe&gt;
&lt;p&gt;その名の通り、テスト駆動開発の本です。&lt;/p&gt;
&lt;p&gt;著者の方がブログで、この本について書いているのを見て、すぐに読みたいと思い購入。&lt;/p&gt;
&lt;p&gt;私はわりと出版されてから数日後くらいの早めに購入したので無事に手に入れることができたのですが、最近まではAmazonで売り切れ状態が続いていたみたいです。早めに動いてよかった。&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;内容は、第一部が通貨の変換をJavaで、二部はjUnitのようなテストフレームワークをPythonで作る。&lt;/p&gt;
&lt;p&gt;コードを写経して読み進めて、テスト駆動開発の実践を追体験できました。&lt;/p&gt;
&lt;p&gt;普段だったら一気にコードを実装しちゃいたくなるけど、「不安」を解消しつつテストを書きながらじっくりと進めていく。一気に書いたコードって暫く経つと「正しく動いてるのかな…?」って気になってしまうことがよくあります。&lt;/p&gt;
&lt;p&gt;テストコードを残して置くことで、いつでも実装がちゃんと動いているかを確認できるのは精神的に楽になりますね。リファクタリングも行って前進しつつも後ろも確認して作業を進めていくテスト駆動開発の流れは、実践してみたいです。&lt;/p&gt;
&lt;p&gt;また、todoリストの書き方も参考になりました。&lt;/p&gt;
&lt;p&gt;なんとなく自分はtodoなので、明確に定まっているような「やるべきこと」を書くもんだと思っていたのですが、この本では「実装方法はまだ思いつかないけど一応書いておく」みたいな軽い感じでtodoに追加してました。とりあえず、思いついたことや気になることもバンバン追加していったほうがいいのかな。&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;写経に使用したコードは、githubに上げてみました。&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/tkt989/tdd&quot;&gt;tkt989/tdd&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;本の内容と同じJavaとPythonで書いたけど他の言語でやってみるのも面白そう。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[AndroidOrmaとRoomの初期化速度を比較]]></title><description><![CDATA[作成しているアプリでAndroid OrmaをORMとして使っていたのですが、の生成時に少し時間が掛かるのが気になっていました。
もう一つのORMライブラリであるRoomではどうなんだろうと思って生成速度を比較してみました。 設定 動作端末は家で余っていたタブレットZ370C…]]></description><link>https://blog.tkt989.info/2017/11/27/AndroidOrmaとRoomの初期化速度を比較</link><guid isPermaLink="false">https://blog.tkt989.info/2017/11/27/AndroidOrmaとRoomの初期化速度を比較</guid><pubDate>Mon, 27 Nov 2017 14:10:25 GMT</pubDate><content:encoded>&lt;p&gt;作成しているアプリで&lt;a href=&quot;https://github.com/maskarade/Android-Orma&quot;&gt;Android Orma&lt;/a&gt;をORMとして使っていたのですが、&lt;code class=&quot;language-text&quot;&gt;OrmaDatabase&lt;/code&gt;の生成時に少し時間が掛かるのが気になっていました。
もう一つのORMライブラリである&lt;a href=&quot;https://developer.android.com/topic/libraries/architecture/room.html&quot;&gt;Room&lt;/a&gt;ではどうなんだろうと思って生成速度を比較してみました。&lt;/p&gt;
&lt;h1&gt;設定&lt;/h1&gt;
&lt;p&gt;動作端末は家で余っていたタブレット&lt;a href=&quot;https://www.asus.com/jp/Tablets/ASUS_ZenPad_70_Z370C/&quot;&gt;Z370C&lt;/a&gt;。&lt;/p&gt;
&lt;p&gt;それぞれSQLにアクセスするオブジェクトを生成したあと、データをひとつだけ追加する処理の時間を計測。&lt;/p&gt;
&lt;h1&gt;結果&lt;/h1&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;ライブラリ&lt;/th&gt;
&lt;th&gt;時間&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Android Orma&lt;/td&gt;
&lt;td&gt;1902.4584ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Room&lt;/td&gt;
&lt;td&gt;143.45172ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Roomの方がかなり速かったです。&lt;/p&gt;
&lt;p&gt;Android Ormaはなぜこんなことになっているんだろう？
私の設定が間違っているのかな？&lt;/p&gt;
&lt;h1&gt;ソース&lt;/h1&gt;
&lt;p&gt;以下が計測用のソースです。&lt;/p&gt;
&lt;p&gt;{{&amp;#x3C; gist tkt989 7759c1fc5b7e6ada0f29be2c246666a6 &gt;}}&lt;/p&gt;</content:encoded></item><item><title><![CDATA[ResizeAdjustとResizePanの違い]]></title><description><![CDATA[windowSoftInputModeにResizeAdjustもしくはResizePanを指定することで、ソフトウェアキーボードを開いたときの動作を変えることができます。 下部のボタンやToolbarを見れば分かりやすいですが、はキーボード分Activity…]]></description><link>https://blog.tkt989.info/2017/11/21/ResizeAdjustとResizePanの違い</link><guid isPermaLink="false">https://blog.tkt989.info/2017/11/21/ResizeAdjustとResizePanの違い</guid><pubDate>Tue, 21 Nov 2017 13:16:25 GMT</pubDate><content:encoded>&lt;img src=&quot;/2017/11/21/resizeadjust&amp;#x3068;resizepan&amp;#x306E;&amp;#x9055;&amp;#x3044;/anime.gif&quot;&gt;
&lt;p&gt;windowSoftInputModeにResizeAdjustもしくはResizePanを指定することで、ソフトウェアキーボードを開いたときの動作を変えることができます。&lt;/p&gt;
&lt;p&gt;下部のボタンやToolbarを見れば分かりやすいですが、&lt;code class=&quot;language-text&quot;&gt;ResizeAdjust&lt;/code&gt;はキーボード分Activityのサイズを縮めていて、&lt;code class=&quot;language-text&quot;&gt;ResizePan&lt;/code&gt;はActivity全体を上にずらすようになっています。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[RxJavaでPromiseぽいことをやる]]></title><description><![CDATA[Javaで非同期処理を行うと、コールバック地獄になって書きづらくなってしまいます。 JavascriptではPromiseを使えば見やすく、エラー処理もしやすくなって便利ですよね。 Javaでこういう感じの非同期処理したい。 そんなときはRxJava…]]></description><link>https://blog.tkt989.info/2017/11/20/RxJavaでPromiseぽいことをやる</link><guid isPermaLink="false">https://blog.tkt989.info/2017/11/20/RxJavaでPromiseぽいことをやる</guid><pubDate>Mon, 20 Nov 2017 14:49:15 GMT</pubDate><content:encoded>&lt;p&gt;Javaで非同期処理を行うと、コールバック地獄になって書きづらくなってしまいます。&lt;/p&gt;
&lt;p&gt;JavascriptではPromiseを使えば見やすく、エラー処理もしやすくなって便利ですよね。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;javascript&quot;&gt;&lt;pre class=&quot;language-javascript&quot;&gt;&lt;code class=&quot;language-javascript&quot;&gt;&lt;span class=&quot;token function&quot;&gt;connectAsync&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// いろいろ...&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;then&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// いろいろ...&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;catch&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token comment&quot;&gt;// エラー処理&lt;/span&gt;
  &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Javaでこういう感じの非同期処理したい。&lt;/p&gt;
&lt;p&gt;そんなときはRxJavaの&lt;code class=&quot;language-text&quot;&gt;Completable&lt;/code&gt;を使おう。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;connectAsync&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;andThen&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;task1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;andThen&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;task2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;subscribe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
              &lt;span class=&quot;token comment&quot;&gt;// 成功したときの処理&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;e&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
              &lt;span class=&quot;token comment&quot;&gt;// 例外が発生したときの処理&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Completable&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;connectAsync&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Completable&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;emitter&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// てきとうな処理&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// ...&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;connect&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        emitter&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;onComplete&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;observeOn&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Schedulers&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;computation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Completable&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;task1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Completable&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;emitter&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// てきとうな処理&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// ...&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;task1&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        emitter&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;onComplete&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;observeOn&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Schedulers&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;computation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Completable&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;task2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Completable&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;emitter&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// てきとうな処理&lt;/span&gt;
        &lt;span class=&quot;token comment&quot;&gt;// ...&lt;/span&gt;
        &lt;span class=&quot;token class-name&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;task2&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
        emitter&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;onComplete&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;observeOn&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Schedulers&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;computation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;出力結果は&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;sh&quot;&gt;&lt;pre class=&quot;language-sh&quot;&gt;&lt;code class=&quot;language-sh&quot;&gt;connect
task1
task2&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;となり、observeOnで別スレッドで動かしているにも関わらず常に順番に実行されます。&lt;/p&gt;
&lt;p&gt;結果を返す処理は&lt;code class=&quot;language-text&quot;&gt;Single&lt;/code&gt;を使う。&lt;/p&gt;
&lt;div class=&quot;gatsby-highlight&quot; data-language=&quot;java&quot;&gt;&lt;pre class=&quot;language-java&quot;&gt;&lt;code class=&quot;language-java&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token function&quot;&gt;readValue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;flatMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;v&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;toDouble&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;v&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;flatMap&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;v&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;increment&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;v&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;subscribe&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;v&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;token class-name&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;out&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;println&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;v&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Single&lt;/span&gt;&lt;span class=&quot;token generics&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Integer&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;readValue&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token class-name&quot;&gt;Single&lt;/span&gt; single &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Single&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;emitter&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        emitter&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;onSuccess&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token number&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; single&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;observeOn&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Schedulers&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;computation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Single&lt;/span&gt;&lt;span class=&quot;token generics&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Integer&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;toDouble&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Integer&lt;/span&gt; value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token class-name&quot;&gt;Single&lt;/span&gt; single &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Single&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;emitter&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        emitter&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;onSuccess&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value &lt;span class=&quot;token operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; single&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;observeOn&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Schedulers&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;computation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;token keyword&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Single&lt;/span&gt;&lt;span class=&quot;token generics&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Integer&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;increment&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Integer&lt;/span&gt; value&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;token class-name&quot;&gt;Single&lt;/span&gt; single &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;Single&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;emitter&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;-&gt;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;
        emitter&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;onSuccess&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;value &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; single&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;observeOn&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token class-name&quot;&gt;Schedulers&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;computation&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-text&quot;&gt;Single&lt;/code&gt;では&lt;code class=&quot;language-text&quot;&gt;andThen&lt;/code&gt;ではなく&lt;code class=&quot;language-text&quot;&gt;flatMap&lt;/code&gt;になります。&lt;/p&gt;
&lt;p&gt;名前が違うのはPromiseとRxJavaでは意識している部分が違うせいではないかと思っています。&lt;/p&gt;
&lt;p&gt;それぞれが注目しているのは、Promiseでは &lt;strong&gt;処理&lt;/strong&gt; の流れ、いっぽうRxJavaでは &lt;strong&gt;データ&lt;/strong&gt; の流れになっているのだと思います。&lt;/p&gt;</content:encoded></item><item><title><![CDATA[Bluetoothデバイスの名前を取得する方法]]></title><description><![CDATA[ペアリング済みのデバイスは設定画面から名前を変更することができます。 この名前を取得したいと思ったのですが、BluetoothDeviceではそれらしいのは見つかりませんでした。(getName…]]></description><link>https://blog.tkt989.info/2017/11/19/Bluetoothデバイスの名前を取得する方法</link><guid isPermaLink="false">https://blog.tkt989.info/2017/11/19/Bluetoothデバイスの名前を取得する方法</guid><pubDate>Sun, 19 Nov 2017 13:51:12 GMT</pubDate><content:encoded>&lt;img src=&quot;/2017/11/19/bluetoothデバイスの名前を取得する方法/bt.png&quot;&gt;
&lt;p&gt;ペアリング済みのデバイスは設定画面から名前を変更することができます。&lt;/p&gt;
&lt;p&gt;この名前を取得したいと思ったのですが、&lt;a href=&quot;https://developer.android.com/reference/android/bluetooth/BluetoothDevice.html&quot;&gt;BluetoothDevice&lt;/a&gt;ではそれらしいのは見つかりませんでした。(getName()は変更する前の初期値が返ってきた)&lt;/p&gt;
&lt;p&gt;いろいろ調べて見ると非公開のメソッドを使えば取得できることが判明。&lt;/p&gt;
&lt;p&gt;BluetoothDeviceの&lt;a href=&quot;https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/bluetooth/BluetoothDevice.java#883&quot;&gt;getAlias()&lt;/a&gt;をリフレクションなりを使ってアクセスすれば名前を取得できます。&lt;/p&gt;
&lt;p&gt;しかし、@hideなAPIなので突然使えなくなるかもしれない。
使うときは要注意。&lt;/p&gt;</content:encoded></item></channel></rss>