Skip to content

Instantly share code, notes, and snippets.

View ryohji's full-sized avatar

Ryohji Ikebe ryohji

  • Tokyo, Japan
View GitHub Profile
@ryohji
ryohji / kotlin-native+coroutine.diff
Created July 27, 2019 15:56
Kotlin/Native プロジェクト(サンプル)に Coroutine を追加する
diff --git a/build.gradle b/build.gradle
index 29bd433..6a89632 100644
--- a/build.gradle
+++ b/build.gradle
@@ -26,6 +26,9 @@ kotlin {
}
macosTest {
}
+ commonMain.dependencies {
+ implementation('org.jetbrains.kotlinx:kotlinx-coroutines-core-native:1.2.2')
@ryohji
ryohji / android-paging.diff
Created July 15, 2019 15:22
The diff of google code lab's android-paging.
diff --git a/app/src/main/java/com/example/android/codelabs/paging/data/GithubRepository.kt b/app/src/main/java/com/example/android/codelabs/paging/data/GithubRepository.kt
index b1b9b6c..c23688f 100644
--- a/app/src/main/java/com/example/android/codelabs/paging/data/GithubRepository.kt
+++ b/app/src/main/java/com/example/android/codelabs/paging/data/GithubRepository.kt
@@ -17,9 +17,8 @@
package com.example.android.codelabs.paging.data
import android.util.Log
-import androidx.lifecycle.MutableLiveData
+import androidx.paging.LivePagedListBuilder
@ryohji
ryohji / exercise-2.4.md
Created July 4, 2019 15:46
計算機プログラムの構造と解釈 第二版 問題 2.4

問題 2.4

これは対のもう一つの手続き表現である.この表現について任意のオブジェクト xy に対し, (car (cons x y))x を生じることを証明せよ.

(define (cons x y)
 (lambda (m) (m x y)))

(define (car z)
 (z (lambda (p q) p)))
@ryohji
ryohji / exercise-2.6.md
Last active July 4, 2019 15:44
計算機プログラムの構造と解釈 第二版 問題 2.6

問題 2.6

対を手続きで表現することがそれほどの驚きでなければ,手続きを操作出来る言語では,0 と, 1 を足す演算を

(define zero (lambda (f) (lambda (x) x)))

(define (add-1 n)
 (lambda (f) (lambda (x) (f ((n f) x)))))

と実装することで,(少なくとも非負の整数だけを問題とする限りは)数を使わないで済せることが出来ることを考えよう.この表現は発明者 Alonzo Church(λ算法を発明した論理学者)に従い, Church 数 (Church numerals)として知られている.

@ryohji
ryohji / single-coroutine-executor.kt
Last active June 5, 2019 09:17
The idea of single threaded execution in Kotlin Coroutine.
private val semaphore = AtomicBoolean(false)
private suspend fun Service.checkAndRefreshAccessToken() {
val aSecond = 1000L
  var mills = 1L
  // wait (binary-) semaphore to ensure only one coroutine
// executing this function's try ... catch body.
  while (!semaphore.compareAndSet(false, true)) {
    delay(millis)
    mills = minOf(aSecond, millis * 2)