Skip to content

Instantly share code, notes, and snippets.

View LouisCAD's full-sized avatar

Louis CAD LouisCAD

View GitHub Profile
@LouisCAD
LouisCAD / CursorCallback.java
Created December 20, 2016 10:42 — forked from NikolaDespotoski/CursorCallback.java
Cursor Diff Util callback.
import android.database.Cursor;
import android.support.annotation.Nullable;
import android.support.v7.util.DiffUtil;
/**
* Created by Nikola on 9/29/2016.
*/
public abstract class CursorCallback<C extends Cursor> extends DiffUtil.Callback {
private final C newCursor;
import android.annotation.SuppressLint
import android.content.ContentResolver
import android.database.Cursor
import android.net.Uri
/**
* @see ContentResolver.query
*/
@SuppressLint("Recycle")
@Suppress("NOTHING_TO_INLINE")
@LouisCAD
LouisCAD / gmail_email.py
Created October 8, 2017 19:08 — forked from erans/gmail_email.py
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("(.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 / UsbPermissions.kt
Last active November 30, 2017 20:12 — forked from bj0/UsbPermissions.kt
Requesting permission to open UsbDevice in Kotlin using coroutines
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 / JobDispatcherReschedulerWorkaroundService.kt
Last active January 9, 2018 06:11
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)
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() {
@LouisCAD
LouisCAD / TextWatcher.kt
Last active June 4, 2018 13:00
EditText TextWatcher, without the override me again ceremony
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
}
@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 / SelectableRelativeLayout.java
Created June 29, 2016 09:28
A selectable RelativeLayout that will show Android's selectableItemBackground on foreground (ripple on Lollipop+) when touched.
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
@LouisCAD
LouisCAD / Lol.kt
Last active February 14, 2019 06:21 — forked from npryce/layout.kt
Kotlin layout hack, up to the right margin (100 chars)
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 / installAll.gradle
Last active March 27, 2019 06:01
Installs all the release variants of a library to the local maven repository and bintray. Useful if you want to deploy an android library using productFlavors, and push all the flavors to bintray and jcenter. You may need to edit the info specific to my library in the pomConfig, pom and pkg closures. Example here: https://github.com/LouisCAD/Spl…
/*
* Copyright (c) 2017. Louis Cognault Ayeva Derman
*
* 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