Skip to content

Instantly share code, notes, and snippets.

View BulkheadClientInterceptor.kt
import io.github.resilience4j.bulkhead.Bulkhead
import io.github.resilience4j.bulkhead.utils.BulkheadUtils
import io.grpc.CallOptions
import io.grpc.Channel
import io.grpc.ClientCall
import io.grpc.ClientInterceptor
import io.grpc.ClientInterceptors
import io.grpc.ForwardingClientCallListener
import io.grpc.Metadata
import io.grpc.MethodDescriptor
@eungju
eungju / TRawHttpSocket.java
Last active May 11, 2018
RawHTTP libthrift TTransport
View TRawHttpSocket.java
import com.athaydes.rawhttp.core.EagerBodyReader;
import com.athaydes.rawhttp.core.EagerHttpResponse;
import com.athaydes.rawhttp.core.MethodLine;
import com.athaydes.rawhttp.core.RawHttp;
import com.athaydes.rawhttp.core.RawHttpHeaders;
import com.athaydes.rawhttp.core.RawHttpRequest;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@eungju
eungju / CircuitBreakerMetrics.kt
Last active Apr 12, 2018
Timeout CircuitBreaker
View CircuitBreakerMetrics.kt
interface CircuitBreakerMetrics {
fun executionCompleted(name: String, latency: Double) = Unit
}
@eungju
eungju / RxTest.kt
Last active Nov 26, 2017
Catch UndeliverableException
View RxTest.kt
@Test
fun simple() {
val observable = Observable.create<Int> { emitter ->
emitter.onNext(1)
emitter.onError(IOException("Timeout"))
}
observable
.take(1)
.subscribe({ assertEquals(1, it) }, { assertTrue(it is UndeliverableException) })
}
@eungju
eungju / Correct.kt
Last active Aug 29, 2017
Rx에서 reactive base type 만들 때 자주 하는 실수
View Correct.kt
override fun connectDevice(userDeviceRef: UserDeviceRef, deviceAttributes: DeviceAttributes, nodeRef: PilsnerRef): Completable
= Completable.fromRunnable {
rwLock.write {
devicePresences[userDeviceRef.deviceId] = Presence(userDeviceRef, deviceAttributes, nodeRef)
userDevices.put(userDeviceRef.userId, userDeviceRef.deviceId)
}
}
override fun getPresencesOfUser(userId: UserId): Single<List<Presence>>
= Single.fromCallable {
@eungju
eungju / Headers.kt
Last active Jul 21, 2017
HTTP 헤더 이름은 왜 타입을 안만드나?
View Headers.kt
class Http {
data class HeaderName(val name: String) : Comparable<HeaderName> {
override fun compareTo(other: HeaderName): Int = name.compareTo(other.name, true)
fun get(headers: MultiMap): String? = headers.get(name)
fun set(headers: MultiMap, value: String): Unit { headers.set(name, value) }
fun copyIfExist(from: MultiMap, to: MultiMap) {
get(from)?.let { set(to, it) }
}
@eungju
eungju / README.md
Last active Jul 2, 2017
Kotlin let run apply also
View README.md

let

inline fun <T, R> T.let(block: (T) -> R): R = block(this)

run

inline fun <T, R> T.run(block: T.() -> R): R = block()

apply

@eungju
eungju / RxJavaTest.java
Created Jun 15, 2017
RxJava 2.1.0+withLatestFrom+cache+firstOrError causes NoSuchElementException
View RxJavaTest.java
@Test
fun withLatestFromCausesNoSuchElementException() {
val state = Observable.just(42).cacheWithInitialCapacity(1)
var error = 0
val threads = (0..4 - 1)
.map {
Thread {
Observable.just(Unit)
.withLatestFrom(state, BiFunction { _: Unit, state: Int -> state })
.firstOrError()
@eungju
eungju / FlowLayout.java
Last active Sep 1, 2016
안드로이드 커스텀 레이아웃 단위 테스트
View FlowLayout.java
/**
* https://github.com/ultimate-deej/FlowLayout-for-Android/blob/master/src/org/deejdev/android/FlowLayout.java
*/
public class FlowLayout extends ViewGroup {
public static final int LEFT_TO_RIGHT = 0;
public static final int TOP_DOWN = 1;
public static final int RIGHT_TO_LEFT = 2;
public static final int BOTTOM_UP = 3;
private int mGravity;
@eungju
eungju / RxPermission.kt
Last active Aug 8, 2016
Android Permissions with RxJava
View RxPermission.kt
import rx.Observable
interface RxPermission {
val isGranted: Boolean
fun request(): Observable<Boolean>
}