今、Mac で FTPコマンドを使う

無くなってますよね。

Command Not Found. ですよね、今。

こうですか?

$ brew install inetutils

あれ、fomula 見つかりませんね、今。

I posted a question on the Emacs Stack Exchange which goes into detail
about my specific problem: https://emacs.stackexchange.com/q/35747/10761

Basically, I'm seeing some weird behavior and errors in Emacs when I try
to use Dired as an FTP client while using GNU's `ftp'. The same behavior
does not exist when I use Apple's `ftp' (which can be found at
this link: https://opensource.apple.com/tarballs/lukemftp/ ).

I'm inclined to think that this issue is a bug for `inetutils' on OS X,
as the same problem does not occur on Ubuntu. Is this the case or is it
the fault of Emacs or something else entirely?

[bug-inetutils] Problems with `ftp' on OS X 10.13

inetutils unfortunately exhibits some bugs on High Sierra so this will be a better solution and should make everyone happy.

こうでしょうか。

$ brew install tnftp

これで、いけましたね。

terminal - How to get BSD FTP and Telnet back in 10.13 (High Sierra)? - Ask Different

Emacs でブクマークしておきますか。

設定ファイル:~/.netrc: UNIX/Linuxの部屋

みなさん、様々な環境でやっているだろうから。

調べるのもなんだかなあだろうし。


関連ワード:  今さら聞けない


Android Architecture Blueprints での コルーチンの使われ方

良い記事がたくさんあります。

Kotlin の Coroutine を概観する

入門Kotlin coroutines

読んでみましたが、きちんと理解できてる自信がありません!

MVPの中で、どのように使われているかAndroid Architecture Blueprintsで見てみましょう。

todo-mvp-kotlin-coroutines

すべての非同期処理をコルーチンで置き換えます。シンプルな非同期プログラミングとなり、直感的にコード書くことができます。

 

Presenter

非同期処置の記述はここが起点になります。


private fun loadTasks(forceUpdate: Boolean, showLoadingUI: Boolean) = launchSilent(uiContext) {
    // ...
    val result = tasksRepository.getTasks()
    // ...
}

TasksPresenter.kt#L69

メインのデータをリポジトリから取得する部分です。


launchSilent(uiContext) {
  // ...
}

CoroutineExt.kt#L18-L25

と見慣れない コルーチンビルダーがありますが、元の形に戻すと、


launch(
  context = UI,
  start = CoroutineStart.DEFAULT,
  parent = null) {
  // ...
}

AppExecutors.kt#L32-L35

です。

Presenterでは、launch() でコルーチンの起点を作っています。

Viewのメソッドを利用しないメソッドでは、コルーチンコンテクストは、DefaultDispatcher となり省略することができます。

 

Repository


override suspend fun getTasks(): Result<List<Task>> {
  // ...
  val result = tasksLocalDataSource.getTasks()
  // ...
 }

TasksRepository.kt#L49-L69


override suspend fun getTasks(): Result<List<Task>> = withContext(appExecutors.ioContext) {
  // ...
  Result.Success(tasksDao.getTasks())
  // ...
}

TasksLocalDataSource.kt#L34-L41

Repository -> LocalDataSource とサスベンドなfunctionが深く呼ばれていきます。

LocalDataSource では、Presenterでのlauch()時のコルーチンコンテキストから、withContext(appExecutors.ioContext) として、すべて、ioContext としての DefaultDispatcher に一時的に切り替えています。

 

まとめ

ざっくり、コルーチン関連の入れ子関係を書いてみると、


// presenter
launch(context = UI, parent = null) {

  // repository
  withContext(DefaultDispatcher) {
    // fetch data from database
  }

}

Presenter で launch() して、Repository末端(local/remote) で withContext() でコンテクスト切り替え。

もちろん、コルーチン内から呼ばれるのは、repository の suspend な functionず。


Admob firebase-ads:15.0.1 でメモリーリークする

なんか以前からよくリークしてましたよね、Admob。

今回は, 以下バージョン。


implementation "com.google.firebase:firebase-core:15.0.2"
implementation "com.google.firebase:firebase-ads:15.0.1"

Activity#finish()後、

百発百中でLeakCanaryが鳴く。

情報はないか、と探すが古いものばかり。

最新の公式サンプルを見る。

BannerExamples

advanced-APIDemo

BannerRecyclerViewExample

AndroidManifest.xmlの「INTERNET」関連の2行はもう不要だったり。

サンプル通りライフサイクル周り記述しても消えやしない。

百発百中でアウトでござる。


// Called when leaving the activity
public override fun onPause() {
    ad_view.pause()
    super.onPause()
}

// Called when returning to the activity
public override fun onResume() {
    super.onResume()
    ad_view.resume()
}

// Called before the activity is destroyed
public override fun onDestroy() {
    ad_view.destroy()
    super.onDestroy()
}

公式サンプルの中に以下を見つけた。


if (adView.getParent() != null) {
  ((ViewGroup) adView.getParent()).removeView(adView);
}

RecyclerViewAdapter.java#L146-L148

ぶら下がったままだった模様。

以下で完。


inline fun AdView.remove() {
  if (parent != null) {
    (parent as ViewGroup).removeView(this)
  }
}

最初のライフサイクル周りは、

公式マニュアル通り不要だったりしたが。