Skip to content

Instantly share code, notes, and snippets.

# Now Playing for Übersicht
# v0.7.1
#
# For more info:
# http://github.com/levifig/now-playing.widget
#
# Levi Figueira
# http://levifig.com
#
# ==================================
@lub0s
lub0s / functions.md
Last active September 19, 2017 07:40
Kotlin chaining functions

Extension functions:

Returns/Receiver R (return value) this (target)
(T) let also
T.() run apply

Keybase proof

I hereby claim:

  • I am lupajz on github.
  • I am lupajz (https://keybase.io/lupajz) on keybase.
  • I have a public key ASAzXw_SNd4o6ZPu4517fl2xS_1uelcYedY9WiRT3T5_xgo

To claim this, I am signing this object:

@lub0s
lub0s / ordinal.kt
Created April 17, 2018 16:22
ordinal of sealed class subclass
sealed class Event {
object One : Event()
object Two : Event()
data class Three(val int: Int) : Event()
}
inline fun <reified T : Any> T.ordinal() =
T::class.java.superclass.classes.indexOfFirst { sub -> sub == this@ordinal::class.java }
fun testOrdinal() {
@lub0s
lub0s / RoundedBottomSheetDialogFragment.kt
Created May 22, 2018 14:04 — forked from ArthurNagy/RoundedBottomSheetDialogFragment.kt
Rounded modal bottom sheet as seen in new Google products(Tasks, News, etc.)
package com.your.package
import android.app.Dialog
import android.os.Bundle
import com.your.package.R
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
/**
* BottomSheetDialog fragment that uses a custom
@lub0s
lub0s / AndroidViewInvalidation.md
Created September 11, 2018 13:43 — forked from jieyu/AndroidViewInvalidation.md
Describe how View.invalidate() is processed in Android to refresh a widget.

How View.invalidate() is processed in Android

This document is based on the code of android-4.1.1_r6 (Jelly Bean).

First, the invalidate() call will be propagated back to the root of the view hierarchy. During the propagation, the system determines the dirty area that needs to be redrawn. The propagation will eventually reach ViewRootImpl.

frameworks/base/core/java/android/view/View.java

10219   void invalidate(boolean invalidateCache) {

... ...

@lub0s
lub0s / AutoClearedValue.kt
Last active April 18, 2019 14:26
A lazy property that gets cleaned up when the fragment is destroyed.
/**
* A lazy property that gets cleaned up when the fragment is destroyed.
*
* Accessing this variable in a destroyed fragment will throw NPE.
*/
class AutoClearedValue<T : Any> : ReadWriteProperty<Fragment, T>, LifecycleObserver {
private var _value: T? = null
override fun getValue(thisRef: Fragment, property: KProperty<*>): T =
_value ?: throw IllegalStateException("Trying to call an auto-cleared value outside of the view lifecycle.")

tmux cheatsheet

As configured in my dotfiles.

start new:

tmux

start new with session name:

@lub0s
lub0s / interface.kt
Last active January 5, 2020 21:38
Code with interface
interface Listener {
fun performNewAction(actionId: String)
fun performOldAction()
}
class Presenter {
var listenerRef: Listener? = null
fun display() {