Skip to content

Instantly share code, notes, and snippets.

View twiceyuan's full-sized avatar

twiceYuan twiceyuan

View GitHub Profile
@paulotaylor
paulotaylor / OpenAIRealtimeWebSocket.kt
Last active November 19, 2024 06:28
Simple Kotlin OpenAI Websocket implementation of the Realtime API
import android.util.Log
import io.ktor.util.decodeBase64Bytes
import io.ktor.util.encodeBase64
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import okhttp3.WebSocket
import okhttp3.WebSocketListener
import okio.ByteString
import org.json.JSONArray
@hansvdam
hansvdam / gist:8b9269390e16fa0bf394d7656bec1ea5
Last active October 31, 2024 01:21
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 December 2, 2024 10:13
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)
}
}
}
@aarondewindt
aarondewindt / docker.service
Last active March 5, 2025 18:55
Setup docker on the steamdeck
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target docker.socket firewalld.service containerd.service time-set.target
Wants=network-online.target containerd.service
Requires=docker.socket
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
@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.