Skip to content

Instantly share code, notes, and snippets.

@SUPERCILEX
SUPERCILEX / Async.kt
Created March 27, 2018 06:02
Google Play Services Tasks API with Kotlin Coroutines support
suspend fun <T> Task<T>.await(): T {
if (isComplete) return if (isSuccessful) result else throw exception!!
return suspendCoroutine { c: Continuation<T> ->
addOnSuccessListener { c.resume(it) }
addOnFailureListener { c.resumeWithException(it) }
}
}
fun <T> Deferred<T>.asTask(): Task<T> {
val source = TaskCompletionSource<T>()
@fullkomnun
fullkomnun / RxErrorHandlingCallAdapterFactory.kt
Created February 6, 2018 10:17
Wraps retrofit reactive calls so that retrofit errors can be traced back to client code that invoked the operation
class RxErrorHandlingCallAdapterFactory private constructor(private val original: RxJava2CallAdapterFactory) : CallAdapter.Factory() {
override fun get(returnType: Type, annotations: Array<Annotation>, retrofit: Retrofit): CallAdapter<*, *>? =
original.get(returnType, annotations, retrofit)?.let {
RxCallAdapterWrapper(it as CallAdapter<Any, Any>)
}
private class RxCallAdapterWrapper(private val wrapped: CallAdapter<Any, Any>) : CallAdapter<Any, Any> by wrapped {
override fun adapt(call: Call<Any>): Any {
@mweibel
mweibel / passport-mock.js
Last active December 5, 2022 03:33
Mock passport.js with an own strategy
/**
* Author: Michael Weibel <michael.weibel@gmail.com>
* License: MIT
*/
var passport = require('passport')
, StrategyMock = require('./strategy-mock');
module.exports = function(app, options) {
// create your verify function on your own -- should do similar things as