Skip to content

Instantly share code, notes, and snippets.

View LouisCAD's full-sized avatar

Louis CAD LouisCAD

View GitHub Profile
@npryce
npryce / speech_synthesis.kt
Created December 12, 2017 15:34
Kotlin definitions for the browser speech synthesis API
package browser
import org.w3c.dom.events.Event
import org.w3c.dom.events.EventTarget
typealias EventHandler<E> = (E) -> Unit
external val speechSynthesis: SpeechSynthesis
external class SpeechSynthesis : EventTarget {
@JoseAlcerreca
JoseAlcerreca / ObservableViewModel.kt
Last active February 28, 2021 00:07
An Observable ViewModel for Data Binding and Architecture Components
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@vmichalak
vmichalak / Random.kt
Created January 4, 2018 09:59
Kotlin Random
import kotlin.math.floor
/**
* This class implement a Linear Congruential Generator.
*
* @author Valentin Michalak
*/
class Random(private var seed: Long = 0) {
companion object {
@zach-klippenstein
zach-klippenstein / SelectClauses.kt
Last active August 20, 2021 16:39
Helper methods to build select clauses for Kotlin coroutines
package com.zachklipp.coroutines
import kotlinx.coroutines.experimental.DisposableHandle
import kotlinx.coroutines.experimental.intrinsics.startCoroutineCancellable
import kotlinx.coroutines.experimental.selects.SelectClause0
import kotlinx.coroutines.experimental.selects.SelectClause1
import kotlinx.coroutines.experimental.selects.SelectClause2
import kotlinx.coroutines.experimental.selects.SelectInstance
/**
@hannesstruss
hannesstruss / ChannelSwitchMap.kt
Last active August 6, 2018 06:57
Attempt at implementing RxJava's switchMap for Kotlin Coroutine Channels
import kotlinx.coroutines.experimental.Unconfined
import kotlinx.coroutines.experimental.channels.ReceiveChannel
import kotlinx.coroutines.experimental.channels.consumes
import kotlinx.coroutines.experimental.channels.produce
import kotlinx.coroutines.experimental.selects.whileSelect
import kotlin.coroutines.experimental.CoroutineContext
fun <T, R> ReceiveChannel<T>.switchMap(context: CoroutineContext = Unconfined,
transform: suspend (T) -> ReceiveChannel<R>): ReceiveChannel<R> {
val input = this
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.*
import kotlinx.coroutines.delay
import java.time.Duration
import java.util.concurrent.TimeUnit
fun <T> ReceiveChannel<T>.debounce(timeout: Long, scope: CoroutineScope) =
this.debounce(Duration.ofMillis(timeout), scope)
fun <T> ReceiveChannel<T>.debounce(
@ZacSweers
ZacSweers / GuardTest.kt
Last active September 14, 2018 23:05
Demo of how the Nothing type in Kotlin can allow a Swift-style guard function
import com.google.common.truth.Truth.assertThat
import org.junit.Test
inline fun <T> guard(receiver: T?, block: () -> Nothing): T {
if (receiver == null) {
block()
}
return receiver
}
@ZacSweers
ZacSweers / OkioAtomicFile.kt
Created September 16, 2018 06:02
Okio/AtomicFile interop kotlin extensions
import android.util.AtomicFile
import okio.Buffer
import okio.Sink
import okio.sink
import okio.source
import java.io.FileOutputStream
import java.io.IOException
fun AtomicFile.source() = openRead().source()
@sdeleuze
sdeleuze / kotlin-frontend.md
Last active October 25, 2022 14:50
My call for Kotlin as a major frontend language

My call for Kotlin as a major frontend language

I try to push for quite a long time for first class support for WebAssembly in Kotlin because I really believe that frontend development is a domain where Kotlin can be as strong as in mobile, and because this is something that would also help to increase even more the adoption on server-side.

I truly appreciate all the work already done by Kotlin/JS and Kotlin/Native teams. The dead code elimination tool and the initial WebAssembly support in Kotlin/Native are important steps in the right direction. But I believe that Kotlin needs now to make frontend a real priority to take it to the next level.

Need for a consistent and unified web frontend strategy

The first point I would like to raise is that what Kotlin needs IMO is a consistent strategy about web frontend wich includes both Javascript and WebAssembly related efforts. I can u

@nickbutcher
nickbutcher / LICENSE
Last active October 6, 2020 11:14
Fun with gradients and AnimatedVectorDrawables. Illustration by the wonderful https://twitter.com/VPoltrack
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.