Skip to content

Instantly share code, notes, and snippets.

View matpag's full-sized avatar
🐧
Noot-Nooting around

MatPag matpag

🐧
Noot-Nooting around
View GitHub Profile
@Robyer
Robyer / maven-publish-helper-usage.gradle
Last active May 14, 2024 05:41
Gradle script for publishing Android library with sources and javadoc to Maven repository using maven-publish plugin.
// You can use maven-publish-helper.gradle script without changes and even share it between multiple
// modules. Just place the maven-publish-helper.gradle file in the root directory of your project,
// then apply it at the bottom of your module's build.gradle file like this:
// ...content of module's build.gradle file...
apply from: '../maven-publish-helper.gradle'
publishing {
publications {
@JoseAlcerreca
JoseAlcerreca / EventObserver.kt
Created April 26, 2018 12:14
An Observer for Events, simplifying the pattern of checking if the Event's content has already been handled.
/**
* An [Observer] for [Event]s, simplifying the pattern of checking if the [Event]'s content has
* already been handled.
*
* [onEventUnhandledContent] is *only* called if the [Event]'s contents has not been handled.
*/
class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> {
override fun onChanged(event: Event<T>?) {
event?.getContentIfNotHandled()?.let { value ->
onEventUnhandledContent(value)
@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
@tadfisher
tadfisher / AndroidUpdaterState.kt
Created June 1, 2022 18:00
In-app updates for Jetpack Compose
package com.mercury.app.updater
import android.app.Activity
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.ActivityResult
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.IntentSenderRequest
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
@Karn
Karn / LogController.kt
Last active October 18, 2023 14:59
An example implementation of a process to write logs to disk asynchronously using RxJava
typealias LogElement = Triple<String, Int, String?>
object LogController {
private var flush = BehaviorSubject.create<Long>()
private var flushCompleted = BehaviorSubject.create<Long>()
private var LOG_LEVELS = arrayOf("", "", "VERBOSE",
"DEBUG",
"INFO",
@ElfSundae
ElfSundae / git-checkout-all-branches.sh
Last active September 19, 2023 23:10
Git checkout all remote branches
#!/bin/bash
remote=origin ; for brname in `git branch -r | grep $remote | grep -v /master | grep -v /HEAD | awk '{gsub(/^[^\/]+\//,"",$1); print $1}'`; do git branch --track $brname $remote/$brname || true; done 2>/dev/null
@erics
erics / executeGitInGradle.txt
Last active June 2, 2023 20:40
execute git command in gradle
def getGitCommand = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'log','--date=local','--name-status','--after="2018.07.19"'
standardOutput = stdout
}
return stdout.toString().trim()
}
task prinGitLog{
@dlimpid
dlimpid / string-md5.kt
Created July 7, 2017 09:34
Get MD5 hash of the string (of length 32, with leading zeros) in Kotlin
import java.math.BigInteger
import java.security.MessageDigest
fun String.md5(): String {
val md = MessageDigest.getInstance("MD5")
return BigInteger(1, md.digest(toByteArray())).toString(16).padStart(32, '0')
}
@xian
xian / build.gradle
Last active January 12, 2023 11:41
Download Robolectric dependencies for hermetic build
def robolectricVersion = '3.3'
def androidSdkVersions = [
'4.1.2_r1-robolectric-0',
'4.2.2_r1.2-robolectric-0',
'4.3_r2-robolectric-0',
'4.4_r1-robolectric-1',
'5.0.0_r2-robolectric-1',
'5.1.1_r9-robolectric-1',
'6.0.0_r1-robolectric-0',
@cbeyls
cbeyls / ContentLoadingProgressBar.java
Last active December 20, 2021 22:16
ContentLoadingProgressBar implemented The Right Way™
package be.digitalia.common.widgets;
import android.content.Context;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ProgressBar;
/**
* ContentLoadingProgressBar implements a ProgressBar that waits a minimum time to be