Skip to content

Instantly share code, notes, and snippets.

@li2
li2 / gist:f32b90da96e6c1dba1c1e2221c295904
Created January 9, 2024 22:55
Ktor headers case-insensitive, set append
View gist:f32b90da96e6c1dba1c1e2221c295904
headers {
set("header-abc", "abc")
set("header-ABC", "ABC")
append("header-xyz", "xyz")
append("header-XYZ", "XYZ")
}
2024-01-10 11:53:39.983 [outine#6] INFO io.ktor.client.HttpClient
- REQUEST: https://ktor.io/docs/welcome.html
METHOD: HttpMethod(value=GET)
@li2
li2 / MyAndroidApplication.kt
Created August 20, 2023 22:46 — forked from sebaslogen/MyAndroidApplication.kt
Finish all opened activities in my Android app (also across different tasks)
View MyAndroidApplication.kt
class MainApplication : Application() {
private val createdActivities = mutableListOf<WeakReference<Activity>>()
override fun onCreate() {
super.onCreate()
registerActivityLifecycleCallbacks(activityLifecycleCallbacks())
}
fun closeAllActivities() {
@li2
li2 / README.md
Last active March 28, 2023 23:48
Rfw demo
View README.md

dart run encode.dart alert.rfwtxt alert.rfw

@li2
li2 / aws-iot-provisioning-mvn-command.sh
Created May 14, 2021 11:08
AWS IoT FleetProvisioningSample mvn command
View aws-iot-provisioning-mvn-command.sh
mvn exec:java -Dexec.mainClass="identity.FleetProvisioningSample" \
-Dexec.args="--endpoint {yourEndpoint}.iot.ap-southeast-2.amazonaws.com \
--rootca {yourRootCaPath}.pem \
--cert {yourCertPath}.pem.crt \
--key {yourPrivateKeyPath}.pem.key \
--templateName {yourTemplateName}
--templateParameters {\"serialNumber\":Mac21}" -e -X
@li2
li2 / Android Privacy Policy
Last active June 13, 2020 06:47 — forked from alphamu/Android Privacy Policy Template
Privacy policy for Android apps
View Android Privacy Policy
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width'>
<title>Privacy Policy</title>
<style> body { font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; padding:1em; } </style>
</head>
<body>
<strong>Privacy Policy</strong> <p>
View queryTextChanges.kt
/**
* Return query text changes observable.
*
* - filter: to filter undesired text like blank text to avoid unnecessary API call.
* - debounce: to ignore the previous items in the given time and only emit the last one, to avoid too much API calls.
* - distinctUntilChanged: to avoid the duplicate API call.
*/
fun EditText.queryTextChanges(): Observable<String> {
return textChanges()
.map { it.toString() }
View ViewTest.kt
import org.junit.Assert.*
import org.junit.Before
import org.junit.Test
class ViewTest {
private lateinit var firstColour: Colour
private lateinit var secondColour: Colour
private lateinit var overlappedColour: Colour
View chart.kt
import kotlin.math.roundToInt
/**
* Colour in RGB, with each value between 0 – 255 (e.g. R=255, G=0, B=0 would imply a red chart)
*
* @throws IllegalArgumentException if one of the parameters [r], [g] and [b] is out of bound [0, 255]
*/
data class Colour(val r: Int, val g: Int, val b: Int) {
init {
if (r !in QUALIFIED_RANGE || g !in QUALIFIED_RANGE || b !in QUALIFIED_RANGE)
@li2
li2 / BluetoothCallback.java
Created October 29, 2018 02:39 — forked from joinAero/BluetoothCallback.java
Android - The bluetooth listener and profile proxy.
View BluetoothCallback.java
package cc.cubone.turbo.core.bluetooth;
/**
* Interface definition for a callback to be invoked when bluetooth state changed.
*/
public interface BluetoothCallback {
/**
* Called when the bluetooth is off.
*/
@li2
li2 / RxBroadcastReceiver.java
Created October 29, 2018 01:37 — forked from magillus/RxBroadcastReceiver.java
RxJava2.0 Broadcast Receiver for getting intent broadcasts as Observable<Intent>
View RxBroadcastReceiver.java
/**
* RxJava based broadcast reciever that registers its local BroadcastReceiver until end of subscription.
* Listens for update and passes Intent to the Stream (Subscriber).
*
* Copyright 2016 Mateusz Perlak - http://www.apache.org/licenses/LICENSE-2.0
* Created on 11/18/16.
*/
public class RxBroadcastReceiver implements ObservableOnSubscribe<Intent> {
protected final WeakReference<Context> contextWeakReference;