Skip to content

Instantly share code, notes, and snippets.

View Takhion's full-sized avatar

Eugenio Marletti Takhion

View GitHub Profile
@Takhion
Takhion / TwitterHandle.kt
Last active February 20, 2020 15:44 — forked from raulraja/TwitterHandle.kt
Type Refinements with Type Proofs in Kotlin
/* Coming up ~ April 2020 */
package test
import arrow.*
inline class TwitterHandle
@Suppress("NON_PUBLIC_PRIMARY_CONSTRUCTOR_OF_INLINE_CLASS")
private constructor(val handle: String) {
companion object : Refined<String> {
override val validate: String.() -> Map<String, Boolean> = {
interface Cleanup {
fun registerForCleanup(onCleanup: () -> Unit): Closeable
}
class CloseableRefCallback<T : Cleanup>(
private val callback: T.() -> Unit
) : Closeable {
private val resourceRef = AtomicReference<Pair<T, Closeable>?>(null)
@Takhion
Takhion / sort-commits-for-github.sh
Created November 9, 2019 17:22 — forked from findepi/sort-commits-for-github.sh
sort commits for GitHub's sake
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 11:20
[Kotlin/Native] 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 20:06
Convert Java files to Kotlin without the IDE
// 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 April 10, 2019 13:33
Expose `ViewModel.clear()`
@file:Suppress("PackageDirectoryMismatch")
package android.arch.lifecycle
fun ViewModel.clear() = clear()
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 December 20, 2022 09:12
Kotlin `Pair` nested destructuring
@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 April 3, 2019 17:36
Kotlin generics are 🍌🍌🍌
// ...stuff...
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf(
"-Xnew-inference",
"-Xallow-kotlin-package"
)
}
}