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
@Takhion
Takhion / TwitterHandle.kt
Last active Feb 20, 2020 — forked from raulraja/TwitterHandle.kt
Type Refinements with Type Proofs in Kotlin
View TwitterHandle.kt
/* 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> = {
@Takhion
Takhion / ArcUtils.java
Last active Feb 12, 2020
Collection of methods to achieve better circular arc drawing, as Canvas.drawArc() is unreliable. See the related article: https://medium.com/p/9155f49166b8
View ArcUtils.java
/**
* ArcUtils.java
*
* Copyright (c) 2014 BioWink GmbH.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
View CloseableRefCallback.kt
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 / ExhaustiveWhen.kt
Last active Nov 19, 2019
Exhaustive `when` mapping in Kotlin
View ExhaustiveWhen.kt
@file:Suppress("PackageDirectoryMismatch") // root package looks great when importing, ie. `import exhaustive`
/**
* Allows requiring an exhaustive mapping in a `when` block when used with the [rangeTo] operator.
* @sample [exhaustive_when_example]
*/
@Suppress("ClassName") // lowercase because it should look like a keyword
object exhaustive {
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 / 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 / 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()
@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"
)
}
}
You can’t perform that action at this time.