Skip to content

Instantly share code, notes, and snippets.

View MazyNoc's full-sized avatar

Mikael Alfredsson MazyNoc

View GitHub Profile
@MazyNoc
MazyNoc / LifecycleAwareAdapter.kt
Last active February 4, 2022 21:58
A RecyclerView adapter that respects both the RecyclerViews attach and detach view, and an external LifecycleOwner.
import android.util.Log
import android.view.View
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LifecycleRegistry
import androidx.recyclerview.widget.RecyclerView
import app.BuildConfig
@jszakmeister
jszakmeister / loose-labels.clj
Last active July 21, 2026 15:03
Paul Heckbert's loose labeling (nice numbers) algorithm.
(import 'java.lang.Math)
;; This implementation comes from the "Nice Numbers for Graph Labels" in
;; Graphics Gems by Andrew S. Glassner. This is Paul Heckbert's algorithm
;; though.
(defn ^double nice-num [^double x round]
(let [exp (Math/floor (Math/log10 x))
f (/ x (Math/pow 10. exp))
nf (if round