Skip to content

Instantly share code, notes, and snippets.

Eugenio Marletti Takhion

Block or report user

Report or block Takhion

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 sort-commits-for-github.sh
git rebase "$(git merge-base HEAD master)" -x 'git commit --amend -C HEAD --date="$(date -R)" && sleep 1.05'
@Takhion
Takhion / CallbackUtils.kt
Created May 26, 2019
[Kotlin/Native] CallbackUtils.kt
View CallbackUtils.kt
import kotlinx.cinterop.ObjCAction
import kotlinx.cinterop.StableRef
import platform.AppKit.NSControl
import platform.Foundation.NSSelectorFromString
import platform.darwin.NSObject
import platform.objc.OBJC_ASSOCIATION_RETAIN
import platform.objc.objc_setAssociatedObject
/**
* Specify a [callback][onAction] for an [NSControl] action, instead of setting
@Takhion
Takhion / ConvertJavaFilesToKotlin.kt
Created May 11, 2019
Convert Java files to Kotlin without the IDE
View ConvertJavaFilesToKotlin.kt
// adapted from https://github.com/JetBrains/kotlin/blob/0103c0d2fd8c9ae9e7f41898064407a6278c5831/j2k/tests/org/jetbrains/kotlin/j2k/AbstractJavaToKotlinConverterForWebDemoTest.kt
package me.eugeniomarletti
import com.intellij.codeInsight.ContainerProvider
import com.intellij.codeInsight.NullabilityAnnotationInfo
import com.intellij.codeInsight.NullableNotNullManager
import com.intellij.codeInsight.runner.JavaMainMethodProvider
import com.intellij.core.CoreApplicationEnvironment
import com.intellij.core.JavaCoreApplicationEnvironment
@Takhion
Takhion / 0_ViewModelHacks.kt
Last active Apr 10, 2019
Expose `ViewModel.clear()`
View 0_ViewModelHacks.kt
@file:Suppress("PackageDirectoryMismatch")
package android.arch.lifecycle
fun ViewModel.clear() = clear()
View RuntimeOnlyParcelable.kt
import android.app.Activity
import android.content.Intent
import android.os.Parcel
import android.os.Parcelable
import java.io.Closeable
import java.util.UUID
import java.util.concurrent.ConcurrentHashMap
/**
* A special [Parcelable] that carries an in-memory reference to any instance of type [T], which will obviously
@Takhion
Takhion / PairNestedDestructuring.kt
Last active Feb 16, 2019
Kotlin `Pair` nested destructuring
View PairNestedDestructuring.kt
@file:Suppress("NonAsciiCharacters")
package me.eugeniomarletti.util.destructuring.pair.nested
object NoDestructuring
typealias PairA<A> = Pair<A, *>
typealias PairB<B> = Pair<*, B>
//region nesting level: 1
@Takhion
Takhion / 0_build.gradle.kts
Last active Apr 3, 2019
Kotlin generics are 🍌🍌🍌
View 0_build.gradle.kts
// ...stuff...
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf(
"-Xnew-inference",
"-Xallow-kotlin-package"
)
}
}
@Takhion
Takhion / 1_property.kt
Created Sep 16, 2018
Kotlin property delegate utils
View 1_property.kt
import kotlin.properties.ReadOnlyProperty
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
private typealias GetValue<This, R> = (thisRef: This, property: KProperty<*>) -> R
private typealias SetValue<This, R> = (thisRef: This, property: KProperty<*>, value: R) -> Unit
inline fun <This, R> property(
crossinline getValue: GetValue<This, R>
) =
@Takhion
Takhion / MultiReceiver.kt
Created Jul 8, 2018
Multiple receivers in Kotlin
View MultiReceiver.kt
val sample: (X, Y, Z) -> Int = multiReceiver { { { x + y + z } } }
fun <A, B, C, R> multiReceiver(f: A.() -> B.() -> C.() -> R) = { a: A, b: B, c: C -> f(a)(b)(c) }
class X(val x: Int)
class Y(val y: Int)
class Z(val z: Int)
@Takhion
Takhion / RxFilterIsInstance.kt
Last active Jun 21, 2018 — forked from rock3r/RxFilterIsInstance.kt
Port Kotlin's awesome filterIsInstance() to RxJava — one call to filter by type and map-cast to that type
View RxFilterIsInstance.kt
package me.seebrock3r.extensions.reactivex
import io.reactivex.Flowable
import io.reactivex.Maybe
import io.reactivex.Observable
import io.reactivex.Single
@Suppress("UNCHECKED_CAST") // The cast happens after we filter by type so it's safe
inline fun <reified R> Flowable<*>.filterIsInstance(): Flowable<R> =
filter { it is R }
You can’t perform that action at this time.