Skip to content

Instantly share code, notes, and snippets.

Striving for max efficiency.

Louis CAD LouisCAD

Striving for max efficiency.
Block or report user

Report or block LouisCAD

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
LouisCAD / FusedLocationFlow.kt
Last active Sep 9, 2019
Create a Flow of location updates on Android (using kotlinx.coroutines), backed by Fused Location Provider from Google Play Services.
View FusedLocationFlow.kt
* Copyright 2019 Louis Cognault Ayeva Derman. Use of this source code is governed by the Apache 2.0 license.
import android.location.Location
import kotlinx.coroutines.CancellationException
LouisCAD / !
Created Feb 28, 2019 — forked from Ribesg/!
How to use an iOS Framework in a Kotlin MPP library published to Maven
View !

This gist demonstrates how to build a Kotlin MPP library so that the iOS sourceSet depends on and uses an iOS Framework as a dependency.

Key ideas:

  • We use [Carthage] to retrieve/build the iOS Framework.
  • We use [cinterop] to create bindings allowing us to use the iOS Framework from Kotlin
  • We build and publish the library using ./gradlew publishToMavenLocal
  • We build and publish [klib] artifacts for both the arm64 and x86_64 architectures, you can easily add arm32 if you need.
  • Note that the publish process also publishes a cinterop klib artifact, allowing dependents to also know about the iOS Framework headers.

You can find a gist explaining how to use such library in an iOS app [here][ios-app].

View ConflatedBroadcastChannelDelegate.kt
inline operator fun <E> ConflatedBroadcastChannel<E>.getValue(
thisRef: Any?,
prop: KProperty<*>
): E = value
inline operator fun <E> ConflatedBroadcastChannel<E>.setValue(
thisRef: Any?,
prop: KProperty<*>,
LouisCAD / LifecycleCoroutines.kt
Last active Oct 15, 2019
CoroutineScope and Job integration with Lifecycle for Android. Meant to be used for your coroutines in lifecycle aware components. OUTDATED. See up to date implementation here:
View LifecycleCoroutines.kt
import android.arch.lifecycle.GenericLifecycleObserver
import android.arch.lifecycle.Lifecycle
import android.arch.lifecycle.Lifecycle.Event.ON_DESTROY
import android.arch.lifecycle.LifecycleOwner
import kotlinx.coroutines.experimental.CoroutineScope
import kotlinx.coroutines.experimental.Dispatchers
import kotlinx.coroutines.experimental.Job
fun Lifecycle.createJob(cancelEvent: Lifecycle.Event = ON_DESTROY): Job {
LouisCAD / Lol.kt
Last active Feb 14, 2019 — forked from npryce/layout.kt
Kotlin layout hack, up to the right margin (100 chars)
View Lol.kt
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
val <T> T.` `: T get() = this
LouisCAD / UsbPermissions.kt
Last active Nov 30, 2017 — forked from bj0/UsbPermissions.kt
Requesting permission to open UsbDevice in Kotlin using coroutines
View UsbPermissions.kt
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.hardware.usb.UsbDevice
import android.hardware.usb.UsbManager
import kotlinx.coroutines.experimental.CompletableDeferred
LouisCAD / GooglePlayServices.kt
Created Nov 23, 2017
Allows using Google Play Services Task API in Kotlin Coroutines, plus Play Services availability check made easier.
View GooglePlayServices.kt
import splitties.init.appCtx
import kotlin.coroutines.experimental.suspendCoroutine
val googleApiAvailability = GoogleApiAvailability.getInstance()!!
inline val playServicesAvailability get() = googleApiAvailability.isGooglePlayServicesAvailable(appCtx)
suspend fun Task<Void>.await() = suspendCoroutine<Unit> { continuation ->
LouisCAD /
Created Oct 8, 2017 — forked from erans/
Check if an Email address is Gmail or Google Apps for your domain
import sys
import re
import dns.resolver # Requires dnspython
email_host_regex = re.compile(".*@(.*)$")
gmail_servers_regex = re.compile("(|$", re.IGNORECASE)
def is_gmail(email):
""" Returns True if the supplied Email address is a Email or is a Google Apps for your domain - hosted Gmail address
Checks are performed by checking the DNS MX records """
LouisCAD / TextWatcher.kt
Last active Jun 4, 2018
EditText TextWatcher, without the override me again ceremony
View TextWatcher.kt
import android.text.Editable
import android.widget.EditText
import splitties.collections.forEachByIndex
import android.text.TextWatcher as AndroidTextWatcher
interface TextWatcher : AndroidTextWatcher {
override fun afterTextChanged(s: Editable) = Unit
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) = Unit
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) = Unit
LouisCAD / JobDispatcherReschedulerWorkaroundService.kt
Last active Jan 9, 2018
A fix for Firebase Job Dispatcher issue #6 ( You need to extend PersistedJobService instead of JobService for this to work, and call Jobs.schedulePresisted(tag)
View JobDispatcherReschedulerWorkaroundService.kt
import timber.log.Timber
* See [this issue](
class JobDispatcherReschedulerWorkaroundService : GcmTaskService() {
You can’t perform that action at this time.