Skip to content

Instantly share code, notes, and snippets.

@seka
seka / HTMLConverter.kt
Created October 21, 2018 16:59
HTML から Android のコンポーネントを作成してみるサンプル
package jp.example.android.util.html
import android.content.Context
import android.graphics.Bitmap
import android.support.v4.content.ContextCompat
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.text.Spanned.SPAN_INCLUSIVE_INCLUSIVE
import android.text.style.TextAppearanceSpan
import android.view.Gravity.CENTER
@ToshihitoKon
ToshihitoKon / Kotlin構文CheatSheet.kt
Last active May 16, 2018 05:13
Kotlinの構文わからなくなるのでメモ
// #関数定義
// fun [関数名] ( [引数名1]:[型], [引数名2]:[型] ... ): [返り値型] { [式] }
fun addOne(num: Int): Int {
num+1
}
// fun [関数名] ( [引数名1]:[型], [引数名2]:[型] ... ): [返り値型] = { [式] }
fun addOne(num: Int): Int = num+1
// 返り値の型が自明な場合は省略可(可読性下がるため非推奨)
@alex-shpak
alex-shpak / Interceptor.java
Last active March 29, 2023 21:06
Refreshing OAuth token with okhttp interceptors. All requests will wait until token refresh finished, and then will continue with the new token.
private class HttpInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
//Build new request
Request.Builder builder = request.newBuilder();
builder.header("Accept", "application/json"); //if necessary, say to consume JSON
@daschl
daschl / gist:db9fcc9d2b932115b679
Last active August 26, 2020 23:17
Draft: Writing Code for Production

Writing Resilient Reactive Applications

This guide is a first draft (that will end up in the official docs) on writing resilient code for production with the Couchbase Java SDK. At the end, the reader will be able to write code that withstands bugs, latency issues or anything else that can make their application fail.

Note that lots of concepts can be applied for both synchronous and asynchronous access. When necessary, both patterns are discussed separately. Also, the focus is on database interaction, but if you are using RxJava as part of your stack you can apply most of the principles there as well (and should!).

RxJava 101 Recap: Cold and Hot Observables

When working with Observables, it is important to understand the difference between cold and hot. Cold Observables will start to emit events once a Observer subscribes, and will do it "fresh" for each Observer. Hot Observables instead are starting to emit data as soon as it becomes available, and will return the same (or parts of the same)