Skip to content

Instantly share code, notes, and snippets.

@hansenji
hansenji / FlowLifecycleExt.kt
Created December 31, 2020 19:18
Collect flows tied to the Lifecycle
class LifecycleGroup(val lifecycleOwner: LifecycleOwner) {
/**
* Recommended for the majority of use cases
* The crucial difference from [collect] is that when the original flow emits a new value, [block] for previous
* value is cancelled.
**/
inline fun <T> Flow<T>.collectLatestWhenStarted(crossinline block: suspend (T) -> Unit): Job {
return lifecycleOwner.lifecycleScope.launchWhenStarted {
[email protected] {
block(it)
@oskar456
oskar456 / wgcf.py
Last active February 17, 2024 12:47
Cloudflare WARP linux client (using wg-quick for actual tunnel setup)
#!/usr/bin/env python3
import subprocess
import json
import os
from pathlib import Path
import requests
from requests.compat import urljoin
@objcode
objcode / ConcurrencyHelpers.kt
Last active October 29, 2024 12:03
Helpers to control concurrency for one shot requests using Kotlin coroutines.
/* Copyright 2019 The Android Open Source Project
*
* 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
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@jaredrummler
jaredrummler / SearchViewStyle.java
Last active May 22, 2020 22:48
Customize the SearchView in an ActionBar for Android
/*
* Copyright (C) 2015 Jared Rummler <[email protected]>
*
* 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