Skip to content

Instantly share code, notes, and snippets.

View zchee's full-sized avatar
😩
want to Go knowledge...

Koichi Shiraishi zchee

😩
want to Go knowledge...
View GitHub Profile
@karpathy
karpathy / microgpt.py
Last active August 13, 2026 12:02
microgpt
"""
The most atomic way to train and run inference for a GPT in pure, dependency-free Python.
This file is the complete algorithm.
Everything else is just efficiency.
@karpathy
"""
import os # os.path.exists
import math # math.log, math.exp
# Claude Code CLI Environment Variables
# This file lists all environment variables used in v2.1.202 with explanations
## Anthropic API & Authentication
ANTHROPIC_API_KEY - Primary API key for Anthropic's Claude API; used as an auth source (source "ANTHROPIC_API_KEY") when no OAuth token is configured
ANTHROPIC_AUTH_TOKEN - Alternative bearer token for Anthropic services; sent as Authorization: Bearer and takes priority over ANTHROPIC_API_KEY, also used with gateway mode
ANTHROPIC_BASE_URL - Custom base URL for the Anthropic API; overrides the default api.anthropic.com endpoint (a non-api.anthropic.com host marks the client as non-first-party)
ANTHROPIC_BETAS - Comma-separated list of beta feature headers appended (trimmed, non-empty) to the internal beta flags on API requests
ANTHROPIC_CUSTOM_HEADERS - Custom HTTP headers for API requests, parsed as newline-separated "Key: Value" pairs
@yamanahlawat
yamanahlawat / upgrade_pyproject.py
Last active April 2, 2026 08:44
Upgrade all packages using uv
"""
Script to automatically update uv.lock and then update pyproject.toml dependencies.
Prerequisites:
1. Python 3.11+ (for tomllib)
2. tomli-w package (`pip install tomli-w`)
3. uv installed and available in PATH
Usage:
Run this script: `python upgrade_pyproject.py`
@saagarjha
saagarjha / path_hook.mm
Created October 17, 2022 18:57
Some code I used to help write FB11698739. Very rough and posted as-is: don't copy things blindly from the internet, but that applies doubly so here!
// clang path_hook.mm -shared -ldl -g -framework Foundation path_hook.o -L/usr/lib/swift
#include <cassert>
#include <cstdint>
#include <dlfcn.h>
#include <mach/arm/vm_param.h>
#include <mach/kern_return.h>
#include <mach/mach_init.h>
#include <mach/vm_map.h>
#include <mach/vm_prot.h>
@LinusHenze
LinusHenze / iOS_16_Launch_Constraints.txt
Created June 15, 2022 16:30
Description of the Launch Constraints introduced in iOS 16
iOS 16 introduced launch constraints, which can be used to constraint the launch of an application.
There are three types of constraints:
Self Constraints, which the launched application itself must meet
Parent Constraints, which the parent process must meet
Responsible Constraints, which the "responsible process" must meet (I assume that the responsible process is the process that asked launchd to launch a service)
Additionally, the TrustCache format was updated (see below) to support assigning each binary a "Constraint Category", which forces Self and Parent Constraints.
Note that Self, Parent and Responsible Constraints can also be set by the process performing the launch and they can be included in the code signature, in the new blob type 0xFADE8181. In both cases, the constraints are DER encoded (just like the DER entitlements).
Constraint Categories (from TrustCache, new in version 2):
@R167
R167 / main.go
Created March 22, 2022 05:50
Test golang bookmarks SDK
package main
import (
"fmt"
"encoding/json"
"github.com/slack-go/slack"
)
@ibireme
ibireme / kpc_demo.c
Last active April 20, 2026 19:55
A demo shows how to read Intel or Apple M1 CPU performance counter in macOS.
// =============================================================================
// XNU kperf/kpc demo
// Available for 64-bit Intel/Apple Silicon, macOS/iOS, with root privileges
//
//
// Demo 1 (profile a function in current thread):
// 1. Open directory '/usr/share/kpep/', find your CPU PMC database.
// M1 (Pro/Max/Ultra): /usr/share/kpep/a14.plist
// M2 (Pro/Max): /usr/share/kpep/a15.plist
// M3: /usr/share/kpep/as1.plist
/*
* NAME: injectaddr.so
*
* SYSOPSIS:
* % gcc -shared -fPIC injectaddr.c -ldl -o injectaddr.so
*
* -- inject 1s delay, then connect to 127.0.0.1:8888
* % LD_PRELOAD=injectaddr.so \
* curl http://d1000.p8888.4127-0-0-1.inject.example.com/
*
@theevilbit
theevilbit / screenshot.m
Last active January 13, 2026 21:40
Make a screenshot on macOS using Objective-C
/*
Compile:
gcc -framework Foundation -framework AppKit screenshot.m -o screenshot
*/
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
int main(void) {
@edmundsmith
edmundsmith / langfeatures.md
Created November 22, 2021 14:42
Things I wish $Lang had

Things I wish $Lang had

Sometimes, when programming, I notice that I'm missing some useful features, or when reading I think 'this would be really useful to be part of $Lang'.

Explicit order-invariance and synchronisation points

C compilers are part of why C is hard. They re-order statements based on what appears to be a magic black box. Understanding what's in that black box is much harder than it should be. Many statements (or expressions) in programming act completely independently of each other, and thus their order of execution should not matter. Meanwhile, other statements can depend on the execution of a previous statement (/expression). It would be nice to see the execution dependency graph explicitly and syntactically laid out, rather than being inferred from analysis or assuming every statement to induce a synchronisation point.

Some languages get part of this right. Haskell's laziness means order of execution doesn't need to match the order it's written down, and its purity means that orde