Skip to content

Instantly share code, notes, and snippets.

View sxlijin's full-sized avatar
🎯
doing things

Samuel Lijin sxlijin

🎯
doing things
View GitHub Profile
@sxlijin
sxlijin / axum_server.after.rs
Created April 6, 2025 01:18
monolithic axum_server.rs - LLM demo for refactoring
use anyhow::Context;
use axum::{extract::State, response::IntoResponse, routing::get, Router};
use serde::Serialize;
use std::{net::SocketAddr, path::PathBuf};
use tokio::{net::TcpListener, sync::broadcast};
use tokio_stream::StreamExt;
// use tower_http::trace::TraceLayer;
use notify::{Event, EventKind, RecursiveMode, Watcher};
use tower_http::services::ServeDir;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
@sxlijin
sxlijin / rate_limiter.py
Created November 11, 2024 21:20
python rate limiting
class RateLimiter:
def __init__(
self, *, name: str, max_requests_per_period: int, period_duration_secs: int
):
self.__name = name
self.__max_requests_per_period = max_requests_per_period
self.__semaphore = asyncio.Semaphore(max_requests_per_period)
self.__period_duration_secs = period_duration_secs
@sxlijin
sxlijin / baml-openapi.json
Last active October 4, 2024 21:25
baml-openapi.json
{
"openapi": "3.0.0",
"info": {
"description": "baml-cli serve",
"version": "0.1.0",
"title": "baml-cli serve"
},
"servers": [
{
"url": "{address}",
@sxlijin
sxlijin / README.md
Created September 30, 2024 18:06
python subprocess uds notes

in one terminal:

python processor.py

in another terminal:

nc -U /tmp/my_unix_socket
-------------------------------------
Translated Report (Full Report Below)
-------------------------------------
Process: Python [4917]
Path: /opt/homebrew/*/Python.framework/Versions/3.12/Resources/Python.app/Contents/MacOS/Python
Identifier: org.python.python
Version: 3.12.4 (3.12.4)
Code Type: ARM-64 (Native)
Parent Process: Python [4908]
@sxlijin
sxlijin / episode-of-care.schema.txt
Last active July 8, 2024 23:38
fhir.schema.json, without cyclic type definitions
Answer in JSON using this schema:
{
// The list of medical conditions that were addressed during the episode of care.
diagnosis: [
{
// May be used to represent additional information that is not part of the basic definition of the element and that modifies the understanding of the element in which it is contained and/or the understanding of the containing element's descendants. Usually modifier elements provide negation or qualification. To make the use of extensions safe and managable, there is a strict set of governance applied to the definition and use of extensions. Though any implementer can define an extension, there is a set of requirements that SHALL be met as part of the definition of the extension. Applications processing a resource are required to check for modifier extensions.
//
// Modifier extensions SHALL NOT change the meaning of any elements on Resource or DomainResource (including cannot change the meaning of modifierExtension itself).
modifierExtension: str
@sxlijin
sxlijin / async-local-storage.test.ts
Created July 2, 2024 01:20
async local storage
it('test local trace async', async () => {
const s2 = new AsyncLocalStorage<string[]>()
s2.enterWith(['first'])
const localTraceAsync = <ReturnType, F extends (...args: any[]) => Promise<ReturnType>>(
name: string,
func: F,
): F => {
const funcName = name
@sxlijin
sxlijin / maturin.log
Created June 19, 2024 22:48
maturin license-file.workspace log
~/sandbox/python-repro is 📦 v0.1.0 via 🐍 v3.12.3 | [0] at 15:45:16
❯ poetry remove baml-py; RUST_LOG=maturin=debug poetry run maturin build --manifest-path ~/baml/engine/language_client_python/Cargo.toml && poetry add ~/baml/engine/target/wheels/baml_py-0.40.0-cp38-abi3-macosx_11_0_arm64.whl
Updating dependencies
Resolving dependencies... (0.1s)
Package operations: 0 installs, 0 updates, 1 removal
- Removing baml-py (0.40.0 /Users/sam/baml/engine/target/wheels/baml_py-0.40.0-cp38-abi3-macosx_11_0_arm64.whl)
@sxlijin
sxlijin / attempt2.rs
Created June 7, 2024 05:27
ruby-tokio-demo
use futures::{future, FutureExt};
use magnus::{
class, exception::runtime_error, function, method, prelude::*, Error, IntoValue, RModule,
};
//#[cfg(ruby_have_ruby_fiber_scheduler_h)]
use rb_sys::bindings::uncategorized::{
rb_fiber_current, rb_fiber_scheduler_block, rb_fiber_scheduler_current, rb_fiber_scheduler_get,
rb_fiber_scheduler_kernel_sleep, rb_fiber_scheduler_unblock,
};
use std::cell::RefCell;
@sxlijin
sxlijin / caps_lock-is-ctrl.json
Created June 5, 2024 19:52
karabiner-elements rules
{
"description": "In Terminal/VSCode, caps_lock is CTRL",
"manipulators": [
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.apple\\.Terminal",
"^com\\.googlecode\\.iterm2",
"^com\\.microsoft\\.VSCode"