Skip to content

Instantly share code, notes, and snippets.

View gatspy's full-sized avatar

CG.gatspy gatspy

View GitHub Profile
@shirakaba
shirakaba / README.md
Last active November 17, 2023 00:52
GUI-based debugging of iOS/macOS Rust projects in Xcode

Here's how to get your environment set up to:

  1. Develop iOS and Android apps using Rust.
  2. Enable GUI debugging of Rust projects in Xcode.

If you just want to enable GUI debugging of macOS Rust projects in Xcode, I'm not actually sure whether you need cargo-mobile at all. But one benefit of installing it is that it automatically installs rust-xcode-plugin for you, giving you syntax highlighting of Rust sources in Xcode.

Prerequisites

cargo-mobile

@gmk57
gmk57 / CoroutineTimer.kt
Last active April 30, 2024 09:36
Coroutine-based solution for delayed and periodic work
/**
* Coroutine-based solution for delayed and periodic work. May fire once (if [interval] omitted)
* or periodically ([startDelay] defaults to [interval] in this case), replacing both
* `Observable.timer()` & `Observable.interval()` from RxJava.
*
* In contrast to RxJava, intervals are calculated since previous run completion; this is more
* convenient for potentially long work (prevents overlapping) and does not suffer from queueing
* multiple invocations in Doze mode on Android.
*
* Dispatcher is inherited from scope, may be overridden via [context] parameter.
//
// ContentView.swift
// Moon
//
// Created by Tanner W. Stokes on 8/9/20.
//
import SwiftUI
struct ContentView: View {
@rnyrnyrny
rnyrnyrny / logger.go
Last active October 23, 2023 05:28
log using uber zap and lumberjack
// NOTE
// This gist was created long time ago.
// According to zap's doc, now we can use zapcore.AddSync to directly add lumberjack as a zap sync
// see https://github.com/uber-go/zap/blob/master/FAQ.md#does-zap-support-log-rotation
// So I wrote a new gist if anyone is interested:
// https://gist.github.com/rnyrnyrny/a6dc926ae11951b753ecd66c00695397
// 下面的代码已经过时了,现在直接用zapcore.AddSync就行,参考zap文档
// thanks to:
@chibatching
chibatching / FlowThrottleDebounce.kt
Last active March 7, 2024 00:02
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
@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 May 6, 2024 10:54
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 December 31, 2023 00:13
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 22, 2023 03:58
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.