Skip to content

Instantly share code, notes, and snippets.

View nhubbard's full-sized avatar
💭
🤖 Finding reasons to stay busy

Nicholas Hubbard nhubbard

💭
🤖 Finding reasons to stay busy
View GitHub Profile
@prachigauriar
prachigauriar / Slider+LogarithmicScale.swift
Last active April 11, 2024 16:26
SwiftUI Slider with Logarithmic Scale
extension Binding where Value == Double {
/// Returns a new version of the binding that scales the value logarithmically using the specified base. That is,
/// when getting the value, `log_b(value)` is returned; when setting it, the new value is `pow(base, newValue)`.
///
/// - Parameter base: The base to use.
func logarithmic(base: Double = 10) -> Binding<Double> {
Binding(
get: {
log10(self.wrappedValue) / log10(base)
},
@afollestad
afollestad / BroadcastReceiver.kt
Last active January 14, 2024 10:23
A Lifecycle components aware BroadcastReceiver DSL (Kotlin)
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import androidx.lifecycle.Lifecycle.Event.ON_DESTROY
import androidx.lifecycle.Lifecycle.Event.ON_START
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.OnLifecycleEvent
import android.content.BroadcastReceiver as StockReceiver