Skip to content

Instantly share code, notes, and snippets.

@chalup
chalup / RedBlackTree.kt
Created August 30, 2018 10:29
Red-black tree implementation in Kotlin based on "Purely Functional Data Structures" book
sealed class RedBlackTree<E : Comparable<E>> {
enum class Color { R, B }
companion object {
fun <T : Comparable<T>> emptyTree(): RedBlackTree<T> = Empty as RedBlackTree<T>
}
object Empty : RedBlackTree<Nothing>()
data class Tree<E : Comparable<E>>(
val color: Color,
@chalup
chalup / kotlin-checklist.md
Last active October 3, 2016 16:00
Kotlin use checklist

[✓] Proguard - nothing blows up spectacularly during assemble gradle task

[✓] Proguard - make sure the primary dex file does not become bloated because of Kotlin

[✓] Proguard - stacktraces from Kotlin code can be easily deobfuscated

[✓] Proguard - stacktraces from Java code which is called from Kotlin code can be easily deobfuscated

[✓] compilation time - app can be built in finite amount of time (sidenote: this is quite tricky to assess - the compilation time might be a non-linear function of Kotlin code size; think hard if we can somehow make sure we won't have this issue in few months)

@chalup
chalup / build.gradle
Created November 13, 2015 08:41
Define custom lint configuration in gradle
android {
lintOptions {
lintConfig file("lint.xml")
}
}
@chalup
chalup / lint.xml
Created November 13, 2015 08:40
Increase severity of lint checks
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="NewApi" severity="fatal"/>
<issue id="MissingSuperCall" severity="fatal"/>
<issue id="UnusedResources" severity="fatal"/>
</lint>
@chalup
chalup / optics.py
Created September 1, 2015 13:05
OPTICS implementation
import math
import numpy as np
from sklearn.neighbors import BallTree
class Optics:
def __init__(self, eps, min_pts):
self.eps = eps
self.min_pts = min_pts
@chalup
chalup / java8wat.java
Created April 16, 2015 09:02
This code compiles on JDK6, but fails on JDK8 with Error:(23, 14) java: reference to put is ambiguous both method put(Java8Wat.Parcelable) in Java8Wat.Bundle and method put(java.io.Serializable) in Java8Wat.Bundle match
import java.io.Serializable;
public class Java8Wat {
interface Parcelable {
}
static class Bundle implements Parcelable {
public void put(Parcelable parcelable) {
}
@chalup
chalup / MultiUriCursorWrapper.java
Created August 13, 2014 18:57
CursorWrapper which a) allows setting multiple notification Uris on a Cursor and b) sets the "dirty" state after ContentResolver notification and dispatches change on ContentObserver registration
package com.futuresimple.base.provider;
import com.google.common.collect.Iterables;
import android.content.ContentResolver;
import android.database.ContentObservable;
import android.database.ContentObserver;
import android.database.Cursor;
import android.database.CursorWrapper;
import android.net.Uri;
@chalup
chalup / GagSsl.java
Created January 30, 2014 11:30
Get OkHttpClient which ignores all SSL errors.
private static OkHttpClient getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
package com.futuresimple.base.util;
import com.google.common.base.Predicate;
import com.google.common.collect.AbstractIterator;
import com.google.common.collect.Iterators;
import com.google.common.collect.PeekingIterator;
import java.util.Iterator;
public abstract class SkipWhile {
@chalup
chalup / propertyhelper.h
Created August 19, 2013 10:20
Abominable helper for defining Qt properties.
#ifndef PROPERTYHELPER_H
#define PROPERTYHELPER_H
#define PROPERTY_HELPER(type,name,getter,setter,signal) \
public: \
type getter() const { return p_##name; } \
void setter(type value) { \
if (p_##name == value) return; \
p_##name = value; \
emit signal(value); \