Skip to content

Instantly share code, notes, and snippets.

Zac Sweers ZacSweers

Block or report user

Report or block ZacSweers

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
View KotlinTypes.kt
fun String.extension(): String = removePrefix("hello")
val lambda: (String) -> String = { it.removePrefix("hello") }
val lambdaWithReceiver: String.() -> String = { removePrefix("hello") }
fun function(arg: (String) -> String) {
fun function2(arg: String.() -> String) {
ZacSweers / BlurrinessDetection.kt
Last active Jun 11, 2019
Demo implementation of client-side image blurriness detection on Android using renderscript.
View BlurrinessDetection.kt
* Copyright (c) 2018. Uber Technologies
* 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
* Unless required by applicable law or agreed to in writing, software
View RxJavaErrors (with nullaway)
> Task :compileJava
warning: [options] bootstrap class path not set in conjunction with -source 1.6
warning: [options] source value 1.6 is obsolete and will be removed in a future release
warning: [options] target value 1.6 is obsolete and will be removed in a future release
warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
/Users/zsweers/dev/java/contributing/RxJava/src/main/java/io/reactivex/ error: [NullAway] passing @Nullable parameter 'null' where @NonNull is required
return RxJavaPlugins.onAssembly(new SingleAmb<T>(null, sources));
(see )
/Users/zsweers/dev/java/contributing/RxJava/src/main/java/io/reactivex/ error: [NullAway] passing @Nullable parameter 'null' where @NonNull is required
ZacSweers / OkioAtomicFile.kt
Created Sep 16, 2018
Okio/AtomicFile interop kotlin extensions
View OkioAtomicFile.kt
import android.util.AtomicFile
import okio.Buffer
import okio.Sink
import okio.sink
import okio.source
fun AtomicFile.source() = openRead().source()
ZacSweers / GuardTest.kt
Last active Sep 14, 2018
Demo of how the Nothing type in Kotlin can allow a Swift-style guard function
View GuardTest.kt
import org.junit.Test
inline fun <T> guard(receiver: T?, block: () -> Nothing): T {
if (receiver == null) {
return receiver
Scheduler asyncMainThreadScheduler = AndroidSchedulers.from(Looper.getMainLooper(), true);
RxAndroidPlugins.setInitMainThreadSchedulerHandler(callable -> asyncMainThreadScheduler);
// Or if the default scheduler is already initialiazed
RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler -> asyncMainThreadScheduler);
View AsyncMessagingExample.kt
val asyncMainThreadScheduler = AndroidSchedulers.from(Looper.getMainLooper(), true)
RxAndroidPlugins.setInitMainThreadSchedulerHandler { asyncMainThreadScheduler }
// Or if the default scheduler is already initialiazed
RxAndroidPlugins.setMainThreadSchedulerHandler { asyncMainThreadScheduler }
View Complex.kt
@JsonClass(generateAdapter = true)
data class Foo<T>(
@Json(name = "barString") val bar: String,
val defaultValue: Int = 0,
val nullableString: String?,
val typeParam: T? = null,
val tList: List<T>
// Generated by Moshi Kotlin Code Gen
View Simple.kt
// Sample JSON
// { "bar": "hello world" }
// The Foo class
@JsonClass(generateAdapter = true)
data class Foo(
val bar: String
// Generated by Moshi Kotlin Code Gen


To keep the arguments and examples to the point there are few helpful rules:

  • No abstract examples/arguments. These cause the discussion to lose focus and make examples harder to follow. The example/argument must be traceable to a real-world problem - ___ is intended to solve real problems, not imaginary ones.
  • Examples must show the full complexity of the problem domain. Simplified examples trivialize the problems and the solutions intended to solve those simplified examples may not work for the complex problems.
  • Examples of problematic ___ code must be the “best way” of writing the code in ___ - if it can be improved then the improved version should be used instead.
  • Arguments must be straight to the point and as concise as possible.
  • Arguments should take the point of view of an average programmer - not the über-programmer who doesn’t make design mistakes.
You can’t perform that action at this time.