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
@ZacSweers
ZacSweers / WeakMutableSet.kt
Created Oct 25, 2019
A weak Set & MutableSet implementation in Kotlin.
View WeakMutableSet.kt
/*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the "License"). You may not use this file except
* in compliance with the License.
*
* You can obtain a copy of the license at
* glassfish/bootstrap/legal/CDDLv1.0.txt or
* https://glassfish.dev.java.net/public/CDDLv1.0.html.
* See the License for the specific language governing
View InlineMask.kt
// Code generated by moshi-kotlin-codegen. Do not edit.
package com.squareup.moshi.kotlin.codgen
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import com.squareup.moshi.internal.Util
import java.lang.NullPointerException
@ZacSweers
ZacSweers / After.kt
Created Sep 8, 2019
Missing/null property before/after
View After.kt
// Code generated by moshi-kotlin-codegen. Do not edit.
package com.squareup.moshi.kotlin.codgen
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import com.squareup.moshi.internal.Util
import java.lang.NullPointerException
View SmokeTestTypeJsonAdapter.kt
// Code generated by moshi-kotlin-codegen. Do not edit.
package com.squareup.moshi.kotlin.codgen
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonDataException
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import com.squareup.moshi.internal.Util
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
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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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/Single.java:135: error: [NullAway] passing @Nullable parameter 'null' where @NonNull is required
return RxJavaPlugins.onAssembly(new SingleAmb<T>(null, sources));
^
(see http://t.uber.com/nullaway )
/Users/zsweers/dev/java/contributing/RxJava/src/main/java/io/reactivex/Single.java:163: error: [NullAway] passing @Nullable parameter 'null' where @NonNull is required
@ZacSweers
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
import java.io.FileOutputStream
import java.io.IOException
fun AtomicFile.source() = openRead().source()
@ZacSweers
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 com.google.common.truth.Truth.assertThat
import org.junit.Test
inline fun <T> guard(receiver: T?, block: () -> Nothing): T {
if (receiver == null) {
block()
}
return receiver
}
You can’t perform that action at this time.