Skip to content

Instantly share code, notes, and snippets.

View udalov's full-sized avatar

Alexander Udalov udalov

View GitHub Profile
@udalov
udalov / get-jar-from-gradle-dependency.gradle
Created January 4, 2021 15:32
get-jar-from-gradle-dependency.gradle
// Usage: gradle -b get-jar-from-gradle-dependency.gradle
apply plugin: 'java'
repositories {
mavenCentral()
jcenter()
}
dependencies {
@udalov
udalov / download-old-kotlin-compilers
Last active September 3, 2023 22:12
download-old-kotlin-compilers
#!/usr/bin/env bash
set -e
if uname | grep -q Darwin; then
# Use Homebrew's coreutils on macOS (run `brew install coreutils`).
TOUCH=gtouch
STAT=gstat
else
TOUCH=touch
@udalov
udalov / bootstrap-ir.py
Last active September 12, 2019 14:34
Test compilation of the Kotlin project with JVM IR
#!/usr/bin/env python3
import atexit, os, re, shutil, subprocess, sys, time
from pathlib import Path
def to_str(buf):
return "".join(map(chr, buf))
def dump_stdout_stderr(f, result):
f.write("=== STDOUT ===\n\n")
@udalov
udalov / loadOriginName.kt
Last active March 1, 2018 17:03
Load name of the original anonymous/synthetic class which was copied during inline (KT-21320)
import org.jetbrains.kotlin.serialization.jvm.*
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
fun loadOriginName(className: String) {
val metadata = Class.forName(className).declaredAnnotations
.filter { it.annotationClass.qualifiedName == "kotlin.Metadata" }
.single() as Metadata
if (metadata.k == 3 && metadata.d1.isNotEmpty()) {
// Synthetic classes generated for lambdas/coroutines
@udalov
udalov / getKType.kt
Last active March 16, 2021 21:54
DEPRECATED example how to obtain KType instance from reified T. Please use "typeOf" since 1.3.40!
import java.lang.reflect.*
import kotlin.reflect.KClass
import kotlin.reflect.KType
import kotlin.reflect.KTypeProjection
import kotlin.reflect.KVariance
import kotlin.reflect.full.createType
// --- Interface ---
inline fun <reified T : Any> getKType(): KType =
@udalov
udalov / spec-sealed-data.md
Created March 28, 2016 11:31
Spec: sealed + data

Summary

Allow data classes as sealed class subclasses.

sealed class Base {
    data class Derived(...) : Base()
}

Motivation / use cases

@udalov
udalov / keybase.md
Created February 21, 2016 11:09
KeyBase auth

Keybase proof

I hereby claim:

  • I am udalov on github.
  • I am udalov (https://keybase.io/udalov) on keybase.
  • I have a public key whose fingerprint is 40BF FCAA AA01 B591 916C AAB6 8DA6 620F 79E0 B972

To claim this, I am signing this object:

@udalov
udalov / api.kt
Last active August 29, 2015 14:23
Sketch of a more type-safe reflection API for Kotlin
@file:suppress("UNCHECKED_CAST", "BASE_WITH_NULLABLE_UPPER_BOUND", "UNUSED_PARAMETER")
interface KElement
// Class, package, type
interface KDeclarationContainer : KElement {
val allMembers: Collection<KElement>
}
class A { void foo() {} }
class a { }
public class Main {
public static void main(String[] args) {
new A().foo();
}
}
@udalov
udalov / gist:5017161
Created February 22, 2013 22:41
libsndfile usage
#include <cstdio>
#include <vector>
#include <sndfile.h>
using namespace std;
int main() {
SF_INFO sfinfo;
const int BUF_LEN = 2048;