Skip to content

Instantly share code, notes, and snippets.

View twiceyuan's full-sized avatar

twiceYuan twiceyuan

View GitHub Profile
@hansvdam
hansvdam / gist:8b9269390e16fa0bf394d7656bec1ea5
Last active March 12, 2024 06:51
sample openai curl with function calling
curl --location 'https://api.openai.com/v1/chat/completions' \
--header 'Content-Type: application/json' \
-u :$OPENAI_API_KEY \
--data '{
"messages": [
{
"role": "system",
"content": "The current date and time is 2023-07-22T13:57:34+02:00. Be very presumptive when guessing the values of function parameters."
},
{
@bennyhuo
bennyhuo / init.gradle.kts
Last active April 29, 2024 15:53
How to config mirrors for repositories in Gradle without changing the source code of your project?
fun RepositoryHandler.enableMirror() {
all {
if (this is MavenArtifactRepository) {
val originalUrl = this.url.toString().removeSuffix("/")
urlMappings[originalUrl]?.let {
logger.lifecycle("Repository[$url] is mirrored to $it")
this.setUrl(it)
}
}
}
@mirmilad
mirmilad / debounce.kt
Last active June 21, 2023 22:46
Simple debounce extension for LiveData by using Coroutines
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
fun <T> LiveData<T>.debounce(duration: Long = 1000L, coroutineScope: CoroutineScope) = MediatorLiveData<T>().also { mld ->
val source = this
class SingleLiveEvent<T> : MutableLiveData<T>() {
private val observers = CopyOnWriteArraySet<ObserverWrapper<T>>()
@MainThread
override fun observe(owner: LifecycleOwner, observer: Observer<T>) {
val wrapper = ObserverWrapper(observer)
observers.add(wrapper)
super.observe(owner, wrapper)
}
@hackjutsu
hackjutsu / .leptonrc
Last active December 7, 2022 01:01
[Template for .leptonrc] This is a template for Lepton's configuration file. Please place it on your home directory. #lepton
{
"theme": "light",
"autoUpdate": false,
"snippet": {
"expanded": true,
"newSnippetPrivate": false,
"sorting": "updated_at",
"sortingReverse": true
},
"editor" : {
import functools
def log(func):
@functools.wraps(func)
def wrapper(*args):
print(u"request body: {}".format(args[0]))
response = func(*args)
print u"response body: {}".format(response)
return response
@konrad-kaminski
konrad-kaminski / CountDownLatch.kt
Last active July 14, 2022 23:50
CountDownLatch naive implementation
/*
* Copyright 2016-2017 JetBrains s.r.o.
*
* 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
@douglasselph
douglasselph / AndroidEasySetLangCountry
Created March 15, 2017 21:13
The following allows you to very easily flip between languages and country on Android.
The following allows you to very easily flip between languages and country on Android.
This will IMMEDIATELY cause the change without even needing to shut down the target testing app.
(That is, the currently displayed page will reloaded.)
You first need to install this APP on the phone:
https://play.google.com/store/apps/details?id=net.sanapeli.adbchangelanguage&hl=en
Then to flip copy and paste one of the lines below in a terminal.
@arvi
arvi / OkHttpStack.java
Created November 30, 2016 05:03 — forked from NightlyNexus/OkHttpStack.java
OkHttp 3 implementation of Volley's HttpStack
/*
* Copyright (C) 2016 Eric Cochran
*
* 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
@mengdd
mengdd / ProcessUtils
Created November 10, 2016 02:46
method to check if is on main process
import android.app.ActivityManager;
import android.content.Context;
import android.os.Process;
import android.util.Log;
import java.util.List;
public class ProcessUtils {