Skip to content

Instantly share code, notes, and snippets.

import android.arch.lifecycle.LiveData
import android.arch.lifecycle.Transformations
fun <X, Y> LiveData<X>.map(f: (X?) -> Y?): LiveData<Y> {
return Transformations.map(this, f)
}
fun <X, Y> LiveData<X>.switchMap(f: (X?) -> LiveData<Y>): LiveData<Y> {
return Transformations.switchMap(this, f)
}
import java.net.InetAddress
import java.net.Socket
import javax.net.ssl.SSLSocket
import javax.net.ssl.SSLSocketFactory
/**
* Enables TLS v1.2 when creating SSLSockets.
*
* For some reason, android supports TLS v1.2 from API 16, but enables it by
* default only from API 20.
@YusukeIwaki
YusukeIwaki / backing_field_practice.kt
Created January 6, 2018 06:05
backing fieldのgetでCloseしないといけないリソースを返して、そいつをuseしたときにitで新たなリソースが生成されないことを確認する
import java.io.Closeable
class Resource: Closeable {
init {
println("resource ref +1")
}
fun play() {
println("play")
}
package io.github.yusukeiwaki.example;
import android.os.Handler;
import android.os.Message;
// Activityに以下のような感じで実装する
//
// @Override public void onBackPressed() {
// if (backPressHandler.handleBackPressed()) {
// Toast.makeText(this, "アプリを終了するにはもう一回戻るキーを押して", Toast.LENGTH_SHORT).show();
@YusukeIwaki
YusukeIwaki / RealmResultsObservable
Created April 27, 2017 12:57
RealmResults#asObservableをRxJava2対応に
package io.github.yusukeiwaki.realm_java_helpers;
import java.util.IdentityHashMap;
import java.util.Map;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.MainThreadDisposable;
import io.realm.RealmChangeListener;
import io.realm.RealmModel;
@YusukeIwaki
YusukeIwaki / chrome-remote-desktop.patch
Created March 26, 2017 23:43
chrome-remote-desktopをdisplay 0表示するように改造するための修正ポイント
diff --git a/chrome-remote-desktop.orig b/chrome-remote-desktop
index a40063b..de1b3b0 100755
--- a/chrome-remote-desktop.orig
+++ b/chrome-remote-desktop
@@ -66,11 +66,11 @@ XORG_DUMMY_VIDEO_RAM = 1048576 # KiB
# with large or multiple monitors. This is a comma-separated list of
# resolutions that will be made available if the X server supports RANDR. These
# defaults can be overridden in ~/.profile.
-DEFAULT_SIZES = "1600x1200,3840x2560"
+DEFAULT_SIZES = "1920x1080"
@YusukeIwaki
YusukeIwaki / default.xml
Last active February 6, 2017 08:42
droidkaigi
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote name="github" fetch="https://github.com/" />
<default revision="master" remote="github" />
<project name="square/okhttp.git" path="okhttp3" />
<project name="square/retrofit.git" path="retrofit" />
<project name="square/picasso.git" path="picasso" />
<project name="ReactiveX/RxJava.git" path="RxJava_1" revision="1.x" />
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote name="github" fetch="https://github.com/" />
<default revision="master" remote="github" />
<project name="rails/rails.git" path="rails" />
<project name="rspec/rspec-rails.git" path="rspec-rails" />
<project name="rspec/rspec-core.git" path="rspec-core" />
<project name="rspec/rspec-expectations.git" path="rspec-expectations" />
<project name="rspec/rspec-support.git" path="rspec-support" />
@YusukeIwaki
YusukeIwaki / rxjava_unsub_flatmap_test.java
Created January 23, 2017 01:19
flatMapしてるものは、unsubscribeしたら実行されないよね確認
import rx.Observable;
import rx.Single;
import rx.Subscription;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
public class Hoge {
public static void main(String[] args) {
@YusukeIwaki
YusukeIwaki / kotlin.rb
Created December 2, 2016 13:06
kotlin-1.1-M03をインストールするためのFormula
class Kotlin < Formula
desc "Statically typed programming language for the JVM"
homepage "https://kotlinlang.org/"
url "https://github.com/JetBrains/kotlin/releases/download/v1.1-M03/kotlin-compiler-1.1-M03.zip"
sha256 "55f630899df71894d01f1b25a048bbcc592e28e2545f955eb1034be0eb12c1a7"
bottle :unneeded
def install
libexec.install %w[bin lib]