Skip to content

Instantly share code, notes, and snippets.

Christophe Beyls cbeyls

Block or report user

Report or block cbeyls

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
@cbeyls
cbeyls / BinaryTrees.kt
Created Aug 18, 2019
Kotlin implementation of the binary-trees benchmark from The Computer Language Benchmarks Game
View BinaryTrees.kt
/**
* The Computer Language Benchmarks Game
* https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
*
* based on Jarkko Miettinen's Java program
* contributed by Christophe Beyls
*/
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
@cbeyls
cbeyls / Parcelers.kt
Created Jun 18, 2019
Kotlin Parcelize extensions
View Parcelers.kt
package be.digitalia.sample
import android.os.Parcel
import kotlinx.android.parcel.Parceler
import java.math.BigDecimal
import java.math.BigInteger
import java.util.*
inline fun <T> Parcel.readNullable(reader: () -> T) =
if (readInt() != 0) reader() else null
View DogRiddle.kt
sealed class Animal {
// Cats are simple. A cat is a cat.
object Cat : Animal()
sealed class Dog : Animal() {
abstract val breed: String?
class DogWithBreed(override val breed: String) : Dog()
@cbeyls
cbeyls / LiveDataFactory.java
Created Apr 27, 2019
A Factory providing utility LiveData instances
View LiveDataFactory.java
package be.digitalia.common.livedata;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import androidx.annotation.NonNull;
import androidx.lifecycle.LiveData;
import java.util.concurrent.TimeUnit;
@cbeyls
cbeyls / ComputableLiveData.java
Created Mar 11, 2018
A LiveData class that can be invalidated & computed on demand (based on an internal architecture components class)
View ComputableLiveData.java
package be.digitalia.arch.lifecycle;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.MutableLiveData;
import android.os.AsyncTask;
import android.support.annotation.MainThread;
import android.support.annotation.NonNull;
import android.support.annotation.VisibleForTesting;
import android.support.annotation.WorkerThread;
@cbeyls
cbeyls / ViewLifecycleFragment.java
Last active Jul 11, 2018
Fragment providing separate lifecycle owners for each created view hierarchy.
View ViewLifecycleFragment.java
package be.digitalia.archcomponentsfix.fragment;
import android.arch.lifecycle.Lifecycle.Event;
import android.arch.lifecycle.LifecycleOwner;
import android.arch.lifecycle.LifecycleRegistry;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;
@cbeyls
cbeyls / SuspendIntentService.kt
Created Aug 6, 2017
An Intent Service processing work in order from a Kotlin coroutine running on the main thread.
View SuspendIntentService.kt
package be.digitalia.common.services
import android.app.Service
import android.content.Intent
import android.os.Message
import kotlinx.coroutines.experimental.android.UI
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.channels.LinkedListChannel
import kotlinx.coroutines.experimental.launch
@cbeyls
cbeyls / KotlinFunctions.md
Last active Jul 8, 2019
Comparison of Kotlin functions: also, apply, let, run, with
View KotlinFunctions.md
Function Function type Target passed as Returns
also Extension it Target
apply Extension this Target
let Extension it Block return value
run Extension this Block return value
with Regular this Block return value
@cbeyls
cbeyls / ParcelableUtils.kt
Last active Aug 12, 2019
Kotlin Parcelable utilities
View ParcelableUtils.kt
package be.digitalia.sample
import android.os.Parcel
import android.os.Parcelable
import java.math.BigDecimal
import java.math.BigInteger
import java.util.*
interface KParcelable : Parcelable {
@cbeyls
cbeyls / FragmentArgumentDelegate.kt
Last active Oct 16, 2018 — forked from yanngx/FragmentArgumentDelegate.kt
Fragment arguments without hassle !
View FragmentArgumentDelegate.kt
package be.brol
import android.os.Binder
import android.os.Bundle
import android.os.Parcelable
import android.support.v4.app.BundleCompat
import android.support.v4.app.Fragment
import kotlin.reflect.KProperty
/**
You can’t perform that action at this time.