Skip to content

Instantly share code, notes, and snippets.

Justas Medeišis justasm

Block or report user

Report or block justasm

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
justasm / AndroidDebounced.kt
Last active Aug 22, 2018
Debounced property delegate Android implementation
View AndroidDebounced.kt
import android.os.Handler
fun <T> debounced(initialValue: T, debounceMs: Long = 500L): Debounced<T> {
return AndroidDebounced(initialValue, debounceMs)
private class AndroidDebounced<T>(initialValue: T, private val debounceMs: Long) : Debounced<T> {
private val handler = Handler()
private var _value: T = initialValue
justasm / LegacyLineBreak.kt
Created Aug 14, 2018
Soft-hyphen (U+00AD) support for API <21
View LegacyLineBreak.kt
* Copyright (C) 2006 The Android Open Source Project
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
justasm / CenterVerticalDrawableSpan.kt
Created Jun 19, 2018
Image / drawable span that is vertically centered relative to its surrounding text
View CenterVerticalDrawableSpan.kt
private abstract class CenterVerticalDrawableSpan : ReplacementSpan() {
abstract fun getDrawable(): Drawable?
private var drawableRef: WeakReference<Drawable>? = null
private val cachedDrawable: Drawable?
get() = drawableRef?.get() ?: getDrawable()?.also { drawableRef = WeakReference(it) }
override fun getSize(paint: Paint, text: CharSequence,
justasm / LayoutExtensions.kt
Last active Nov 4, 2017
Android View Kotlin extension for a one-shot callback after layout
View LayoutExtensions.kt
fun View.afterLayout(block: View.() -> Unit) {
val originalVto = viewTreeObserver
originalVto.addOnPreDrawListener(object : ViewTreeObserver.OnPreDrawListener {
override fun onPreDraw(): Boolean {
if (originalVto.isAlive) originalVto.removeOnPreDrawListener(this)
return true
justasm / LazyMutable.kt
Created Aug 8, 2017
Kotlin Lazy for mutable values
View LazyMutable.kt
@file:Suppress("RedundantVisibilityModifier", "NOTHING_TO_INLINE")
import kotlin.reflect.KProperty
public interface LazyMutable<T> {
public var value: T
public fun isInitialized(): Boolean
public inline operator fun <T> LazyMutable<T>.getValue(thisRef: Any?, property: KProperty<*>): T {
justasm / app_build.gradle
Created Mar 9, 2017
Kotlin Android Extensions with Android library module
View app_build.gradle
apply plugin: ''
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.kxt"
minSdkVersion 15
justasm /
Created Aug 15, 2016
Picasso CircleTransformation
import com.squareup.picasso.Transformation;
public class CircleTransformation implements Transformation {
justasm /
Created Feb 21, 2016
Legacy VTK file loader. Decodes POLYDATA datasets from binary or ASCII VTK files to vertex, index and normal float buffers.
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;
import java.util.ArrayList;
justasm /
Last active Apr 21, 2019
OkHttp 3 non-persistent CookieJar with an ACCEPT_ALL policy
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.HttpUrl;
justasm /
Last active Aug 29, 2015
Android detecting horizontal swipe gestures. Designed for use in layout parent for top-level back navigation, but easily made more flexible.
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.ViewConfiguration;
import android.widget.RelativeLayout;
You can’t perform that action at this time.