minimal ruby client for WebDriverAgent

WebDriverAgent developed by Facebook is one of WebDriver tool which run on iOS. Previous some posts, I investigated this module. And now, I develop minimal wrapper Ruby cli client to help some operations. https://github.com/KazuCocoa/wda_client I implemented some operations such as taking screenshots, getting source tree, status about the driver and install arbitrary app to the…More

[Elixir]read GenStage and try a bit

GenStageの0.3.0がリリースされたと合わせて、GenStageに関してのアナウンスがされたので触ってみました。合わせて、GenEventの問題点や解決したい問題がかかれているので参考になると思います。 http://elixir-lang.org/blog/2016/07/14/announcing-genstage/ GenStageとは https://github.com/elixir-lang/gen_stage#genstage に書いている通り、producerとconsumerの別れた役割を持つプロセスの間のイベントをやりとりするためのライブラリです。 GenEventだとイベントを1つの1つのプロセスで処理していたので、何かエラーが発生した時にsupervisorを再起動するというような戦略が取れないことだったりなど、データの流れを考える上で平行処理やその周辺に開発者が気を配らないといけない、と手間がかかっていました。そのため、開発者がデータの処理に集中できるように、そこら辺をいい感じにしてくれるものを用意するために作られたものがこれのようです。 3つの役割 GenStageは、0.3.0現在は3つの役割を持つことができます。 producer consumer producer_consumer 1は、callbackの実装時に handle_demand/2 を実装する必要があります。これは、2や3から要求が来た時に行う処理を書きます。2と3は handle_events/3 を実装する必要があります。これは、イベントを得た時に行う処理を書きます。 関係性の定義 GenStage.sync_subscribe c, to: b のように書くことで、このcとbの間にはconsumer(c)とproducer(b)の関係ができます。つまり、cからbに要求が送られ、それに対して行われた要求が処理されcに対して応答として帰ってきます。ここでは sync_subscribe/3 なので、同期的な挙動を行います。一定時間応答がなかったらtimeoutに成るし、そうなるまでcはbから返答を待ちます。 他にも async_subscribe/2 も存在して、これはこの関係が非同期的に行われる、ということですね。 https://hexdocs.pm/gen_stage/Experimental.GenStage.html#async_subscribe/2 https://hexdocs.pm/gen_stage/Experimental.GenStage.html#sync_subscribe/3 これらの関係性がわかるサンプル実装が以下にあります。 https://github.com/elixir-lang/gen_stage/blob/master/examples/producer_consumer.exs 最後に GenStageはまだ開発中で、 Experimental.GenStage.Flow の実装を控えているそうです。今はまだプロトタイプとしてのドキュメントが以下にあるだけですが、外部データの流れをうまく扱う Flow を練っているようですね。 https://hexdocs.pm/gen_stage/Experimental.GenStage.Flow.html ここら辺は以下のような使い方に寄与するみたいです。 Developers who maintain libraries that integrate with external data sources, be it a RabbitMQ, Redis or…More

[Android]Chat Client for Phoenix server

I implemented a chat server and an iOS application and posted about them on [Swift][Elixir]implement chat server and client. Today, I implemented easy an android chat application for the server. https://github.com/KazuCocoa/WebSocketDemoForAndroid Use Toothpick and Smoothie I use libraries called toothpick and smoothie as DI, such as Dagger but they are simpler than it. https://github.com/KazuCocoa/WebSocketDemoForAndroid/commit/24e9d3d8fa3abf8a8e1116b35334ff22d8d81d2e And…More

[Swift][Elixir]implement chat server and client

Implement Chat Server with Phoenix and chat client with iOS application. Server https://github.com/KazuCocoa/my_chat_ex/tree/master After running the server, you can open chat page, http://localhost:4000/, via browser. The server has no DB. So, history will be deleted if someone reload browser. Client https://github.com/KazuCocoa/WebSocketDemoForiOS/tree/master connect to http://localhost:4000/socket/websocket as websocket Only join the room and send pre-set message to…More

[Elixir]Channelを使った実装とテストコード

Phoenixは、WebSocketを提供するためにChannelという機構を持っています。少し探せば色々参考になるコードもあるのですが、テストコードも書いてみたのでここに備忘録としてのせておきます。 Pathの設定 Phoenix v1.2 の時点では、以下の通り endpoint.ex 内でWebSocketのコネクションを成功させるパスとその処理先を決めます。 https://github.com/KazuCocoa/my_chat_ex/blob/master/lib/my_chat_ex/endpoint.ex#L4 例えば、 とした時、 /socket にWebSocketで接続を確立するとその処理先は MyChatEx.UserSocket、 /socket/other に対しては MyChatEx.OtherSocket が処理先になります。 WebSocketの確立では、transportの指定が必要です。このtransportの指定により、Phoenix Frameworkでは処理対象がWebSocketか、Long pollingかを判定します。 これは、 user_socket.ex におけるChannel Routesの指定箇所で合わせて処理されます。具体的には、以下のようにwebsocketを指定します。 これにより、最終的には以下のパスが構築され、このパスへのWebSocketの通信がそのまま MyChatEx.UserSocket などの処理へ通されます。 このパスは、たとえばChromeのinspectionにより確認可能です。 Channel Channelにおける内部処理は use Phoenix.Channel によるコールバックの実装で最低限は実現可能になります。同期的に通信する応答や、非同期で行う通信など。 https://github.com/KazuCocoa/my_chat_ex/blob/dc536e573c9b01d313cc4aaad89cf76208a8da13/web/channels/my_room_channel.ex Channelに対する認証 このChannelには、認証をかけることが容易に出来ます。これをうまく使うと、WebSocketの確立なども認証されていないものは弾く、という処理が容易に可能です。 https://github.com/KazuCocoa/my_chat_ex/blob/dc536e573c9b01d313cc4aaad89cf76208a8da13/web/channels/user_socket.ex#L24 https://github.com/KazuCocoa/myChatEx/blob/dc536e573c9b01d313cc4aaad89cf76208a8da13/web/router.ex#L28 Test code Channelに対するテストコードは以下 https://github.com/KazuCocoa/myChatEx/blob/dc536e573c9b01d313cc4aaad89cf76208a8da13/test/channels/my_room_channel_test.exs 最後に Elixir x Phoenixにて、このようなWebSocket実装などをBEAM VM上に構築できるというのは良いですね。それに特化した形でフレームワークのサポートもしていますし。More

[Elixir]diff of struct against elixir 1.2.6 and 1.3.1

pattern match with struct Structでもpattern matchingすることができる [Kernel] Allow variable struct names when matching, for example, %module{key: “value”} = struct __struct__ __struct__ が補完候補に出てこない。けれど、使うことは可能。 Elixir 1.2.6 Elixir 1.3.1 ただし、Elixir1.3.1でも、 と使うことは可能。More

[Elixir]Calendar Type in Elixir 1.3

in Elixir 1.3, calendar type was introduced. Usually, we use except for NaiveDateTime in application layer. NaiveDateTime is for developers who develop 3rd party libraries. Date http://elixir-lang.org/docs/stable/elixir/Date.html Time http://elixir-lang.org/docs/stable/elixir/Time.html DateTime http://elixir-lang.org/docs/stable/elixir/DateTime.html NaviDateTime http://elixir-lang.org/docs/stable/elixir/NaiveDateTime.html Developers should avoid creating the NaiveDateTime struct directly and instead rely on the functions provided by this module as well as the…More

Learn Deep Learning with www.udacity.com

Googleが公開しているdeep learningのコースを学ぶことにした。実務よりな知見として。 私の基礎は、大学院までで学んだcomputer scienceと、最近だと人工知能学会から出版された深層学習を読んだくらい。 Stanfordの Courseraが有名どころぽいですが、モデル自体を学んで作るより、TensorFlowをなぞりながら学ぶ方が今の私には適度かなと思いましたので、こちらから。学術的なところも必要になったらその時学ぼう。 コースはこれ Deep Learning Lesson 1では、SGDをざっくり学んだ感じ。classificationとか、学習曲線の形とか、有意差(と、誤差)とか。比較的漠然と学んだ感じ。ネイピア数出たりと、数学感あって楽しかったです。ゆっくり話してくれるので、今の所英語は問題なし。 SGDって、stochastic gradient descentの省略形なのですが、省略しない形がパッと覚えられなかった… TensorFlowについているExampleも順に解いていくとちょうど良い感じぽい。 Pythonに慣れないとな感… 数年前に少し触れた程度だ… 普段、Ruby/Elixir/Erlangを手軽に使う言語として触れていると return を忘れてしまう… Java/Swift/ObjCの感覚で書かないとね。 Python、return必要だった… — KazuCocoa (@Kazu_cocoa) June 19, 2016 TensorFlowのforked repository: https://github.com/KazuCocoa/tensorflow/tree/my_practiceMore

[Android]Try Espresso Test Recorder

AS2.2 Preview3がリリースされましたね。その中で、個人的に待っていたEspresso Test Recorderが実装されたので試してみました。 https://sites.google.com/a/android.com/tools/recent/androidstudio22preview3available 生成されたコードはこちら。 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters package com.kazucocoa.droidtodo; import android.support.test.espresso.ViewInteraction; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4;…More