Skip to content

Instantly share code, notes, and snippets.

View gatspy's full-sized avatar

CG.gatspy gatspy

View GitHub Profile
@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
@chenshengzhi
chenshengzhi / git_ssh_proxy.md
Last active October 26, 2025 08:36
git ssh 代理设置

仅为 GitHub 设置代理

git 代理

设置 git config --global http.https://git.521000.best.proxy socks5://127.0.0.1:1086
设置完成后, ~/.gitconfig 文件中会增加以下条目:

[http "https://github.com"]
    proxy = socks5://127.0.0.1:1086
@nihlton
nihlton / persisted-timeboxed-redux-store.js
Last active July 2, 2020 13:50
Persist Redux in localStorage, with an expiration schedule for each store key.
import { getInitialState, syncLocalStorageWithRedux } from './util-localStorage'
const reduxStorageKey = 'my-application:'
const ONE_SECOND = 1000
const ONE_MINUTE = ONE_SECOND * 60
const ONE_HOUR = ONE_MINUTE * 60
const ONE_DAY = ONE_HOUR * 24
const ONE_YEAR = ONE_DAY * 365
// create a white list. key is the redux store key, and lifeSpan is
@fnky
fnky / ANSI.md
Last active November 8, 2025 14:52
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@niwatly
niwatly / GsonUtils.kt
Last active June 26, 2023 19:34
Gson Utils by Kotlin
//convert gson String to Map<K, V>. Crash when invalid structure found
inline fun <reified K, reified V> String.toMapByGson(): Map<K, V> = if (isNotEmpty()) {
Gson().fromJson<HashMap<K, V>>(this, TypeToken.getParameterized(HashMap::class.java, K::class.java, V::class.java).type)
} else {
mapOf<K, V>()
}
//convert gson String to List<T>. Crash when invalid structure found
inline fun <reified T> String.toListByGson(): List<T> = if (isNotEmpty()) {
Gson().fromJson<List<T>>(this, TypeToken.getParameterized(ArrayList::class.java, T::class.java).type)
@salmoni
salmoni / goQueryTest.go
Last active October 13, 2024 12:20
Parsing HTML in Go/Golang using goQuery to extract data from only one of multiple tables. Demonstrates nested Find statements.
package main
import (
"fmt"
"log"
"strings"
"github.com/PuerkitoBio/goquery"
)
@YumaInaura
YumaInaura / 00_README.md
Last active July 30, 2025 15:49
Golang — Understanding channel, buffer, blocking, deadlock and happy groutines.

Golang — Understanding channel, buffer, blocking, deadlock and happy groutines.

I was so confused to understand behaviior of Golang channels, buffer, blocking, deadlocking and groutines.

I read Go by Example topics.

@Godofbrowser
Godofbrowser / axios.refresh_token.1.js
Last active October 17, 2025 18:32 — forked from culttm/axios.refresh_token.js
Axios interceptor for refresh token when you have multiple parallel requests. Demo implementation: https://github.com/Godofbrowser/axios-refresh-multiple-request
// for multiple requests
let isRefreshing = false;
let failedQueue = [];
const processQueue = (error, token = null) => {
failedQueue.forEach(prom => {
if (error) {
prom.reject(error);
} else {
prom.resolve(token);
@LouisCAD
LouisCAD / LifecycleCoroutines.kt
Last active July 3, 2022 11:47
CoroutineScope and Job integration with Lifecycle for Android. Meant to be used for your coroutines in lifecycle aware components. OUTDATED. See up to date implementation here: https://github.com/LouisCAD/Splitties/tree/master/modules/lifecycle-coroutines
import android.arch.lifecycle.GenericLifecycleObserver
import android.arch.lifecycle.Lifecycle
import android.arch.lifecycle.Lifecycle.Event.ON_DESTROY
import android.arch.lifecycle.LifecycleOwner
import kotlinx.coroutines.experimental.CoroutineScope
import kotlinx.coroutines.experimental.Dispatchers
import kotlinx.coroutines.experimental.Job
import kotlinx.coroutines.experimental.android.Main
fun Lifecycle.createJob(cancelEvent: Lifecycle.Event = ON_DESTROY): Job {
@piruin
piruin / AndroidThread.kt
Created October 30, 2017 09:41
Kotlin's Extension for Easy Handler Thread
package org.tanrabad.survey.larvaecam
import android.app.Fragment
import android.content.Context
import android.os.AsyncTask
import android.os.Handler
import android.os.Looper
import android.view.View
inline fun Context.runOnWorkerThread(crossinline task: () -> Unit) {