Skip to content

Instantly share code, notes, and snippets.

View Yazazzello's full-sized avatar
🤔
Focusing

Yazazzello Yazazzello

🤔
Focusing
  • Netherlands, Noord-Holland
  • 01:36 (UTC -12:00)
View GitHub Profile
@ologe
ologe / PreferenceExtensions.kt
Last active November 13, 2024 21:10
Android shared preference observer using kotlin coroutines (1.3.0)
inline fun <reified T> SharedPreferences.observeKey(key: String, default: T): Flow<T> = channelFlow {
send(getItem(key, default))
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, k ->
if (key == k) {
trySend(getItem(key, default))
}
}
registerOnSharedPreferenceChangeListener(listener)
@chibatching
chibatching / FlowThrottleDebounce.kt
Last active November 8, 2024 00:44
Throttle and Debounce on Flow Kotlin Coroutines
fun <T> Flow<T>.throttle(waitMillis: Int) = flow {
coroutineScope {
val context = coroutineContext
var nextMillis = 0L
var delayPost: Deferred<Unit>? = null
collect {
val current = SystemClock.uptimeMillis()
if (nextMillis < current) {
nextMillis = current + waitMillis
@Odepax
Odepax / build.gradle
Created March 3, 2018 21:24
Gradle + Kotlin + Spek + Jacoco (March 2018)
//
// [ INFO ]
//
// Date: 2018-03-03
// Works on: [ ? Linux ] [ Y Windows ] [ ? MacOSX ]
// Gradle: 4.6.0
// Kotlin: 1.2.30
// Spek: 1.1.5
// JUnit Platform: 1.0.0
// Jacoco: 0.8.0
@lovubuntu
lovubuntu / Sha256.kt
Created November 24, 2017 15:58
function to generate Sha-256 in Kotlin
Class Hasher {
fun hash(): String {
val bytes = this.toString().toByteArray()
val md = MessageDigest.getInstance("SHA-256")
val digest = md.digest(bytes)
return digest.fold("", { str, it -> str + "%02x".format(it) })
}
}
@nickbutcher
nickbutcher / MainActivity.java
Last active August 20, 2021 16:15
A quick sample of the new physics-based animation library added in Support Library 25.3.0 docs: https://developer.android.com/reference/android/support/animation/package-summary.html output: https://twitter.com/crafty/status/842055117323026432
/*
* Copyright 2017 Google Inc.
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@passsy
passsy / KIntent.kt
Last active March 28, 2023 06:51
Kotlin extension functions to start a generic Activity
package com.pascalwelsch.extensions
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
/**
* Extensions for simpler launching of Activities
@jemshit
jemshit / proguard-rules.pro
Last active February 18, 2025 12:50
Proguard Rules for Android libraries
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
-keepclassmembers class fqcn.of.javascript.interface.for.webview {
public *;
}
### RxJava, RxAndroid (https://gist.github.com/kosiara/487868792fbd3214f9c9)
-keep class rx.schedulers.Schedulers {
public static <methods>;
@mcguinness
mcguinness / umbrella
Created August 23, 2016 03:58 — forked from quinncomendant/umbrella
OpenDNS umbrella start/stop script for Mac OS X. This makes it easy to turn umbrella off temporarily, or get its status.
#!/usr/bin/env bash
# Quinn Comendant <[email protected]>
# https://gist.github.com/quinncomendant/3be731567e529415d5ee
# Since 25 Jan 2015
# Version 1.1
CMD=$1;
if [[ `id -u` = 0 ]]; then
@strooooke
strooooke / AppBarBoundFabBehavior.java
Last active May 28, 2021 03:12
FAB behavior that lets FAB scroll out towards the bottom in sync with AppBarLayout scrolling out towards the top
/**
* Behavior for FABs that does not support anchoring to AppBarLayout, but instead translates the FAB
* out of the bottom in sync with the AppBarLayout collapsing towards the top.
* <p>
* Extends FloatingActionButton.Behavior to keep using the pre-Lollipop shadow padding offset.
*/
public class AppBarBoundFabBehavior extends FloatingActionButton.Behavior {
public AppBarBoundFabBehavior(Context context, AttributeSet attrs) {
super();