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
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 com.google.android.gms.location.LocationCallback
import com.google.android.gms.location.LocationRequest
import com.google.android.gms.location.LocationResult
import com.google.android.gms.location.LocationServices
import kotlinx.coroutines.CancellationException
@LouisCAD
LouisCAD / !README.md
Created Feb 28, 2019 — forked from Ribesg/!README.md
How to use an iOS Framework in a Kotlin MPP library published to Maven
View !README.md

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
@Suppress("NOTHING_TO_INLINE")
inline operator fun <E> ConflatedBroadcastChannel<E>.getValue(
thisRef: Any?,
prop: KProperty<*>
): E = value
@Suppress("NOTHING_TO_INLINE")
inline operator fun <E> ConflatedBroadcastChannel<E>.setValue(
thisRef: Any?,
prop: KProperty<*>,
@LouisCAD
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: https://github.com/LouisCAD/Splitties/tree/master/modules/lifecycle-coroutines
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
import kotlinx.coroutines.experimental.android.Main
fun Lifecycle.createJob(cancelEvent: Lifecycle.Event = ON_DESTROY): Job {
@LouisCAD
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
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
package com.my.app
import android.app.PendingIntent
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
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 com.google.android.gms.common.GoogleApiAvailability
import com.google.android.gms.tasks.Task
import splitties.init.appCtx
import kotlin.coroutines.experimental.suspendCoroutine
val googleApiAvailability = GoogleApiAvailability.getInstance()!!
inline val playServicesAvailability get() = googleApiAvailability.isGooglePlayServicesAvailable(appCtx)
@JvmName("awaitVoid")
suspend fun Task<Void>.await() = suspendCoroutine<Unit> { continuation ->
@LouisCAD
LouisCAD / gmail_email.py
Created Oct 8, 2017 — forked from erans/gmail_email.py
Check if an Email address is Gmail or Google Apps for your domain
View gmail_email.py
import sys
import re
import dns.resolver # Requires dnspython
email_host_regex = re.compile(".*@(.*)$")
gmail_servers_regex = re.compile("(.google.com.|.googlemail.com.)$", re.IGNORECASE)
def is_gmail(email):
""" Returns True if the supplied Email address is a @gmail.com Email or is a Google Apps for your domain - hosted Gmail address
Checks are performed by checking the DNS MX records """
@LouisCAD
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
LouisCAD / JobDispatcherReschedulerWorkaroundService.kt
Last active Jan 9, 2018
A fix for Firebase Job Dispatcher issue #6 (https://github.com/firebase/firebase-jobdispatcher-android/issues/6). You need to extend PersistedJobService instead of JobService for this to work, and call Jobs.schedulePresisted(tag)
View JobDispatcherReschedulerWorkaroundService.kt
import com.google.android.gms.gcm.GcmTaskService
import com.google.android.gms.gcm.TaskParams
import com.example.androidapp.jobs.Jobs
import com.example.androidapp.jobs.tagsOfScheduledJobs
import timber.log.Timber
/**
* See [this issue](https://github.com/firebase/firebase-jobdispatcher-android/issues/6).
*/
class JobDispatcherReschedulerWorkaroundService : GcmTaskService() {
You can’t perform that action at this time.