Skip to content

Instantly share code, notes, and snippets.

@LouisCAD
LouisCAD / FusedLocationFlow.kt
Last active May 23, 2024 12:11
Create a Flow of location updates on Android (using kotlinx.coroutines), backed by Fused Location Provider from Google Play Services.
/*
* Copyright 2019 Louis Cognault Ayeva Derman. Use of this source code is governed by the Apache 2.0 license.
*/
import android.location.Location
import com.google.android.gms.location.LocationCallback
import com.google.android.gms.location.LocationRequest
import com.google.android.gms.location.LocationResult
import com.google.android.gms.location.LocationServices
import kotlinx.coroutines.CancellationException
@fs0c131y
fs0c131y / get_sqlcipher_password.js
Created January 27, 2019 20:57
Frida script to get the password of a sqlcipher database
/*
* get_sqlcipher_password.js
* Copyright (c) 2019 Elliot Alderson <[email protected]>
*
* Frida.re JS functions to get SQLCipher database passwords.
*
* Example usage:
* # frida -U -f in.gov.uidai.mAadhaarPlus -l get_sqlcipher_password.js --no-pause
*
*/
@danielocampo2
danielocampo2 / MultiDistinctBy.kt
Last active January 13, 2023 21:20
multiDistinctBy function for Kotlin: Like stdlib distinctBy but for multiple fields
fun <T, K> Iterable<T>.multiDistinctBy(vararg selectors: (T) -> K): List<T> {
require(selectors.isNotEmpty())
val set = HashSet<Int>()
val distinct = ArrayList<T>()
for (element in this) {
val key = selectors.fold(0) { sum, selector ->
sum.plus(selector(element)?.hashCode() ?: 0) }
if (set.add(key))
@tarasbilohan
tarasbilohan / blocked-sites-for-ublock.txt
Last active October 16, 2023 16:03
List of sites are blocked in Ukraine for uBlock Origin
kaspersky.ru
www.kaspersky.ru
drweb.ru
www.drweb.ru
avia.yandex.ru
www.avia.yandex.ru
auto.ru
www.auto.ru
audience.yandex.ru
www.audience.yandex.ru
@ilya-g
ilya-g / cancellationTest.kt
Last active December 21, 2018 06:42
Cancellation support interceptor
class JobCancellationInterceptor(val originalInterceptor: ContinuationInterceptor?) :
AbstractCoroutineContextElement(ContinuationInterceptor),
ContinuationInterceptor {
override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T> =
CancellableCheckContinuation(continuation).let {
originalInterceptor?.interceptContinuation(it) ?: it
}
class CancellableCheckContinuation<T>(val continuation: Continuation<T>) : Continuation<T> {
@elizarov
elizarov / CancellableHandlerContext.kt
Created April 24, 2017 08:15
Alternative implementation of HandlerContext for Android that continues coroutine with CancellationException when the job is complete (i.e. it was cancelled from outside)
public class CancellableHandlerContext(
private val handler: Handler
) : AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor, Delay
{
override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T> =
DispatchedContinuation(continuation)
override fun scheduleResumeAfterDelay(time: Long, unit: TimeUnit, continuation: CancellableContinuation<Unit>) {
handler.postDelayed(object : ResumeTask<Unit>(continuation) {
override fun resume() = continuation.resume(Unit)
@heiswayi
heiswayi / repo-reset.md
Created February 5, 2017 01:32
GitHub - Delete commits history with git commands

First Method

Deleting the .git folder may cause problems in our git repository. If we want to delete all of our commits history, but keep the code in its current state, try this:

# Check out to a temporary branch:
git checkout --orphan TEMP_BRANCH

# Add all the files:
git add -A
@nsk-mironov
nsk-mironov / AccountViewModel.kt
Created April 11, 2016 13:38
Databinding with DelegatedProperties
class AccountViewModel : ObservableModel by ObservableModelDelegate() {
@get:Bindable var name by property<CharSequence>("", BR.name)
@get:Bindable var authenticated by property(false, BR.authenticated)
@get:Bindable var avatar by property("", BR.avatar)
}
@neworld
neworld / howto.md
Last active July 10, 2024 11:24
How to make faster Android build without sacrificing new api lint check

Original solution sacrifices new api lint check.

Here my solution:

int minSdk = hasProperty('minSdk') ? minSdk.toInteger() : 16

apply plugin: 'com.android.application'

android {
 compileSdkVersion 23