This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.lettuce.core.api.StatefulRedisConnection | |
import kotlinx.coroutines.future.await | |
import kotlinx.serialization.KSerializer | |
import kotlinx.serialization.json.Json | |
import kotlinx.serialization.serializer | |
import kotlin.time.Duration | |
enum class ExpiryType { | |
none, after_write, after_access |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tue Jun 25 16:58:14 UTC 2019 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun JsonReader.skipNameAndValue() { | |
skipName() | |
skipValue() | |
} | |
fun JsonReader.nextLongOrNull() = | |
if (peek() == JsonReader.Token.NULL) { | |
nextNull<Long>() | |
null | |
} else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val Connection.asSuspendable get(): SuspendableConnection = SuspendableConnectionImpl(this) | |
interface SuspendableConnection { | |
/** | |
* | |
* Disconnects this object. You should discard this object after calling this method. No more queries | |
* will be accepted. | |
* | |
* @return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.ktor.application.* | |
import io.ktor.pipeline.* | |
import io.ktor.routing.* | |
import io.ktor.util.* | |
import io.micrometer.core.instrument.* | |
import io.micrometer.core.instrument.binder.MeterBinder | |
import io.micrometer.core.instrument.binder.jvm.* | |
import io.micrometer.core.instrument.binder.system.* | |
import java.util.concurrent.atomic.AtomicInteger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ContextDsl | |
fun Route.coGet(path: String, block: suspend ApplicationCall.() -> ServerResponse): Route = get("/") { | |
val result = call.block() | |
when (result) { | |
is ServerResponse.Empty -> | |
call.respondText { "" } | |
is ServerResponse.Json -> | |
call.respondText(result.jsonString, ContentType.Application.Json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Route.coHandler(controller: suspend RoutingContext.() -> ServerResponse): Route = | |
handler { | |
launch(it.vertx().dispatcher()) { | |
val response = it.controller() | |
when (response) { | |
is ServerResponse.Empty -> | |
it.response().end() | |
is ServerResponse.Json -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context | |
import com.gun0912.tedpermission.PermissionListener | |
import com.gun0912.tedpermission.TedPermission | |
import kotlinx.coroutines.experimental.CoroutineStart | |
import kotlinx.coroutines.experimental.async | |
import kotlinx.coroutines.experimental.suspendCancellableCoroutine | |
import timber.log.Timber | |
import java.util.ArrayList | |
fun <T> Context.withPermission(permission: String, block: () -> T) = async(start = CoroutineStart.LAZY) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.experimental.* | |
import kotlinx.coroutines.experimental.channels.* | |
import org.junit.Test | |
import kotlin.coroutines.experimental.CoroutineContext | |
data class Intent(val action: String) | |
class BroadcastSender() { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.vertx.core.json.JsonArray | |
import io.vertx.ext.sql.ResultSet | |
import io.vertx.ext.sql.SQLConnection | |
import io.vertx.ext.sql.UpdateResult | |
import io.vertx.kotlin.core.json.JsonArray | |
import io.vertx.kotlin.core.json.get | |
import io.vertx.kotlin.coroutines.awaitResult | |
import io.vertx.ext.sql.SQLClient as VertxSQLClient | |
// ---- Db access |