Skip to content

Instantly share code, notes, and snippets.

@ochafik
Last active December 1, 2025 00:35
Show Gist options
  • Select an option

  • Save ochafik/a1ccb90267fc6558bb3aafbe90b64048 to your computer and use it in GitHub Desktop.

Select an option

Save ochafik/a1ccb90267fc6558bb3aafbe90b64048 to your computer and use it in GitHub Desktop.
Gist Index

Gist Index

@ochafik's gists

Last updated: 2025-12-01 00:35 UTC | Total: 273 gists | (61 public, 212 private)

By Language

Markdown (56)

C++ (32)

Scala (29)

Shell (22)

Python (20)

JavaScript (17)

HTML (15)

TypeScript (14)

Jupyter Notebook (10)

Dart (9)

OpenSCAD (9)

JSON (7)

Jinja (6)

Java (5)

Text (4)

C (3)

CMake (2)

OpenCL (2)

Other (2)

Dockerfile (1)

G-code (1)

Julia (1)

Maven POM (1)

SPARQL (1)

SQL (1)

TSX (1)

XML (1)

YAML (1)

All Gists

Gist Language Files Updated
Gist Index Markdown 2 2025-12-01
cox-oauth-diagnostic-commands.sh ๐Ÿ”’ Shell 1 2025-11-28
index.ts ๐Ÿ”’ TypeScript 1 2025-11-27
Pattern to reuse iframe-embed as an MCP App ๐Ÿ”’ TypeScript 1 2025-11-26
mcp_oauth_probe.py ๐Ÿ”’ Python 1 2025-11-25
MCP Elicitation Backfill w/ Claude API ๐Ÿ”’ JSON 5 2025-11-23
MCP-UI v2 Prototype ๐Ÿ”’ TypeScript 27 2025-11-21
Security / Deployment Oriented Products ๐Ÿ”’ Markdown 1 2025-11-21
MCP Apps capabilities negotiation ๐Ÿ”’ TypeScript 1 2025-11-21
MCP Calling Skill ๐Ÿ”’ Shell 3 2025-11-06
OpenAI Pizzas Node Server Fix ๐Ÿ”’ Markdown 2 2025-11-05
Chrome MCP Server ๐Ÿ”’ Shell 3 2025-10-29
Ad Skipper.md ๐Ÿ”’ Markdown 3 2025-10-27
mini MCP server ๐Ÿ”’ Python 1 2025-10-27
MCP TS Remove Passthrough Trick ๐Ÿ”’ TypeScript 1 2025-10-25
MCP Adventure ๐Ÿ”’ Markdown 3 2025-10-16
Micropilot: mini MCP client ๐Ÿ”’ Markdown 3 2025-10-15
llama-auto: use cached llama.cpp models to auto configure... ๐Ÿ”’ Markdown 3 2025-10-14
crun: to make, what npx is to npm and uvx to uv ๐Ÿ”’ Markdown 3 2025-10-14
MCP Continuation Backfill ๐Ÿ”’ Markdown 3 2025-10-13
http-as-stdio ๐Ÿ”’ Markdown 3 2025-10-10
stdio-as-http ๐Ÿ”’ Markdown 3 2025-10-10
MCP-UI Server - let the model create its own UIs. ๐Ÿ”’ JSON 5 2025-10-10
Callables for MCP TypeScript SDK ๐Ÿ”’ Markdown 3 2025-10-10
~/.claude/CLAUDE.md ๐Ÿ”’ Markdown 3 2025-10-04
Wikidata SPARQL to get all the statements / qualifiers ab... ๐Ÿ”’ SPARQL 1 2025-09-27
Multiverse MCP Server ๐Ÿ”’ Markdown 1 2025-09-24
Multiverse CLAUDE.md ๐Ÿ”’ Markdown 1 2025-09-24
GPT Researcher Deep Research Algo Analysis ๐Ÿ”’ Markdown 1 2025-09-23
llama.cpp agent example ๐Ÿ”’ Python 15 2025-09-07
WebTop ๐Ÿ”’ Shell 1 2025-09-01
MCP proxy options for antechamber ๐Ÿ”’ TypeScript 4 2025-09-01
MCP Proxy ๐Ÿ”’ TypeScript 2 2025-08-27
cc.md ๐Ÿ”’ Markdown 1 2025-08-04
OpenSCAD launch script to get blazingly fast nightly buil... Markdown 2 2025-07-04
Script to get the GGUF file from an Ollama image for use ... JavaScript 1 2025-06-17
JSON schema examples ๐Ÿ”’ Markdown 1 2025-06-10
Command R7B Thinking Prompt ๐Ÿ”’ Jinja 1 2025-03-17
GGUF template checker against original model ๐Ÿ”’ Python 1 2025-03-07
Partial json parser w/ healing support ๐Ÿ”’ C++ 2 2025-02-27
Generic partial parsing / oai compat stream diffs! ๐Ÿ”’ C++ 1 2025-02-26
Cline + llama.cpp ๐Ÿ”’ Markdown 1 2025-02-25
llama.cpp / ollama tool bench results ๐Ÿ”’ JSON 26 2025-02-23
test_tool_call benchmark results ๐Ÿ”’ Markdown 1 2025-02-10
llama.cpp DeepSeek R1 alternative chat template ๐Ÿ”’ Jinja 1 2025-02-03
PYTHON mode llama.cpp DeepSeek R1 alternative chat template ๐Ÿ”’ Jinja 1 2025-02-03
llama.cpp install script ๐Ÿ”’ Shell 1 2025-01-20
Comparing ollama's template w/ the original for Llama-3.3... ๐Ÿ”’ Jinja 2 2025-01-20
llama.cpp tool call stats eval ๐Ÿ”’ Python 1 2025-01-20
Build Piper TTS on MacOS ๐Ÿ”’ Shell 1 2025-01-17
RPi 5 llama.cpp + Piper TTS continuous hallucination stream ๐Ÿ”’ Shell 1 2025-01-14
llama.cpp Colab CUDA build ๐Ÿ”’ Shell 1 2025-01-14
Minja normalization logic as template ๐Ÿ”’ C++ 1 2024-12-30
Prototype Ruler Axes For OpenScad Web Playground ๐Ÿ”’ OpenSCAD 1 2024-12-25
Emscripten build of OpenSCAD w/ OneTBB + pthreads ๐Ÿ”’ Shell 1 2024-12-23
OpenSCAD Examples sped up by fast-csg feature OpenSCAD 9 2024-12-10
Tool call generic template: tests/chat/templates/generic.... ๐Ÿ”’ Jinja 1 2024-12-04
Knowledge Graph visitation as Gradient Descent! ๐Ÿ”’ Markdown 1 2024-11-19
crash repro for sqlite_lembed large inputs ๐Ÿ”’ C 2 2024-11-17
sqlite-vec + sqlite-lembed + sqlite-rembed in one neat pa... ๐Ÿ”’ Python 1 2024-11-15
Import a Wikidata JSON Dump to a nearly readable DuckDB f... ๐Ÿ”’ SQL 1 2024-11-12
Example of 10 wikidata items from the JSON dump ๐Ÿ”’ JSON 1 2024-11-12
transformers.js phi 3.5 ๐Ÿ”’ HTML 1 2024-11-06
SQLite-vec memory for RAG w/ DB migration builtin! ๐Ÿ”’ Python 1 2024-11-05
Maximilian Winter Memory System ๐Ÿ”’ Markdown 1 2024-11-03
ochafik.com.json AI index ๐Ÿ”’ JSON 1 2024-10-03
llama.cpp agent runner that allows local tools ๐Ÿ”’ Python 1 2024-10-02
Python -> FastAPI converter ๐Ÿ”’ Python 1 2024-10-02
Examples of non-trivial LLM chat templates ๐Ÿ”’ Jinja 2 2024-09-30
llama-server payloads ๐Ÿ”’ JSON 2 2024-09-14
Feature complete jinja C++11 implementation w/o deps for ... ๐Ÿ”’ C++ 3 2024-09-13
RAG Example - MediaPipe + hnswlib-wasm + Gemma 2b it + js... ๐Ÿ”’ HTML 3 2024-09-12
Mediapipe Embedding Test ๐Ÿ”’ HTML 1 2024-09-06
OpenSCAD 3D rendering just got an order of magnitude fast... ๐Ÿ”’ Markdown 1 2024-08-31
COMPLETE sheet macro for any LLMs ๐Ÿ”’ JavaScript 1 2024-08-19
generate_content_async_bug.ipynb ๐Ÿ”’ Jupyter Notebook 1 2024-08-08
Ideal Emscripten CMakeFile.txt ๐Ÿ”’ CMake 3 2024-07-08
Interactive Deps w/ Mermaid.js ๐Ÿ”’ HTML 1 2024-07-08
Emscripten OpenSCAD Updated Options ๐Ÿ”’ CMake 1 2024-07-02
3mf model that gives colors in PrusaSlicer and BambuStudio ๐Ÿ”’ XML 1 2024-06-20
WASM Docker Build of OpenSCAD ๐Ÿ”’ Other 1 2024-06-16
Multiple llama.cpp models under same endpoint ๐Ÿ”’ Markdown 2 2024-06-05
LlamaIndexTS Tutorial ๐Ÿ”’ JavaScript 1 2024-06-04
Alternative manifold3d python bindings for pyodide (wrapp... ๐Ÿ”’ Markdown 2 2024-06-03
Sandboxed iframe messaging example ๐Ÿ”’ HTML 2 2024-05-22
llama.cpp resampling fix test ๐Ÿ”’ Markdown 1 2024-05-21
llama.cpp quantization for the disk-poor ๐Ÿ”’ Markdown 1 2024-05-16
-financial-rag-llama3.ipynb ๐Ÿ”’ Jupyter Notebook 1 2024-05-03
RAG.py llama.cpp ๐Ÿ”’ Python 1 2024-05-02
Simple llama.cpp benchmark ๐Ÿ”’ JSON 4 2024-04-30
C grammar for llama.cpp converted from ANTLR's grammar ๐Ÿ”’ Markdown 2 2024-04-29
llama.cpp hyperfine commands ๐Ÿ”’ Shell 3 2024-04-28
Pending PR ๐Ÿ”’ Markdown 1 2024-04-26
llama.cpp: detect left recursion in grammars ๐Ÿ”’ C++ 1 2024-04-23
Heavy llama.cpp grammar copied from https://github.com/gg... ๐Ÿ”’ Markdown 4 2024-04-22
llama.cpp Grammar constrained post ๐Ÿ”’ Markdown 1 2024-04-12
llama.cpp OpenAI-compatible server w/ tools support for F... ๐Ÿ”’ Python 4 2024-03-25
llama.cpp tool usage / agent example ๐Ÿ”’ Python 2 2024-03-23
OpenAI tool call in chat completion ๐Ÿ”’ Shell 1 2024-03-22
llama.cpp + Pydantic w/ or w/o Instructor & OpenAI packages ๐Ÿ”’ Python 1 2024-03-19
Test llama.cpp + server + openai fastapi wrapper + instru... ๐Ÿ”’ Python 3 2024-03-11
Find tokens matching pattern in tokenizer.json ๐Ÿ”’ Text 1 2024-02-22
test-impact-of-lit-gpt-qa-training-set-tokenization-fix.i... ๐Ÿ”’ Jupyter Notebook 1 2024-02-19
Evaluate impact of lit-gpt Q&A fine-tuning tokenization f... ๐Ÿ”’ Python 1 2024-02-19
scad2py (OpenSCAD implementation in Python) ๐Ÿ”’ Python 4 2024-01-10
OpenSCAD + Manifold rendering time examples ๐Ÿ”’ OpenSCAD 45 2023-12-12
llama.cpp + RPi OpenCL (clvk --> Vulkan) ๐Ÿ”’ OpenCL 2 2023-12-06
Raspberry Pi 5 ML Setup (llama.cpp + Vulkan, etc) ๐Ÿ”’ Markdown 1 2023-11-30
Example C++ Transpiling of OpenSCAD ๐Ÿ”’ C++ 1 2023-11-21
Octree building / script-based rendering for OpenSCAD ๐Ÿ”’ Other 1 2023-11-21
llama-cpp-skip-unused-logits-computations.ipynb ๐Ÿ”’ Jupyter Notebook 1 2023-09-21
llama.cpp: Test skipping unused logits w/ TinyLlamas models ๐Ÿ”’ Markdown 1 2023-09-21
Open-Interpreter Demo ๐Ÿ”’ Jupyter Notebook 1 2023-09-12
llama-cpp-skip-unused-logits-computations.ipynb ๐Ÿ”’ Jupyter Notebook 1 2023-08-25
llama.cpp_ggml-vocab.bin.txt ๐Ÿ”’ Text 2 2023-08-23
CRASHES ggml-llama2.c.py.ipynb ๐Ÿ”’ Jupyter Notebook 1 2023-08-17
ggml-cffi-python.ipynb ๐Ÿ”’ Jupyter Notebook 1 2023-08-17
OLD - OO layer atop GGML's python bindings ๐Ÿ”’ Python 1 2023-08-12
llama2.c BATCH prompt eval + data extraction for visualiz... ๐Ÿ”’ C 1 2023-08-09
CGAL: convert between CGAL::CartesianCGAL::Gmpq and CGA... C++ 2 2023-07-26
falcon.cpp testing scripts (June 2023) ๐Ÿ”’ Markdown 2 2023-06-15
Falcon and OpenLLaMA Inference & Fine-Tuning w/ llama.cpp... ๐Ÿ”’ Markdown 1 2023-06-15
OLD README.md ๐Ÿ”’ Markdown 2 2023-06-14
install.ipynb ๐Ÿ”’ Jupyter Notebook 1 2023-06-07
install.ipynb ๐Ÿ”’ Jupyter Notebook 1 2023-06-07
StableDiffusion CoreML Mac M1/M2 ๐Ÿ”’ Markdown 1 2023-06-07
OpenSCAD branches benchmark script for https://github.com... ๐Ÿ”’ Markdown 2 2023-05-27
An OpenSCAD model that's heavy to evaluate (uses BOSL2 in... ๐Ÿ”’ Markdown 2 2023-05-23
OpenSCAD STL Export - float conversions w/ double-convers... ๐Ÿ”’ C++ 1 2023-05-21
OpenSCAD parallel.h w/ TBB directly ๐Ÿ”’ C++ 1 2023-05-20
URL Shortener Stub ๐Ÿ”’ Dockerfile 4 2023-03-22
OpenSCAD Manifold rejects / deleted code ๐Ÿ”’ C++ 1 2023-03-17
Performance benchmark script for Manifold ๐Ÿ”’ Shell 1 2023-03-14
OpenSCAD Tree Flatterning: push transforms down and bubbl... ๐Ÿ”’ C++ 2 2023-02-26
OctreeBuilder.h ๐Ÿ”’ OpenSCAD 4 2023-02-24
CGAL SINGLETON Numeric ๐Ÿ”’ C++ 1 2023-02-23
List Tabs Browser Extension (Chrome) ๐Ÿ”’ JavaScript 5 2023-02-10
ChatGPT Chrome Extension Experiment ๐Ÿ”’ JavaScript 4 2023-02-09
Color change bug for PrusaSlicer / BambuStudio ๐Ÿ”’ Text 1 2023-01-26
Bambulab AMS Savings - OpenSCAD model for simple multicol... ๐Ÿ”’ G-code 2 2023-01-25
Export Tweets w/ unofficial API ๐Ÿ”’ Julia 5 2022-11-15
Glitch.me cache for Mastodon with domain rewrite ๐Ÿ”’ Markdown 3 2022-11-12
BridJ JNI trampolines using modern C++ (Variadic macros +... ๐Ÿ”’ C++ 3 2022-11-03
BridJ Docker cross-build image ๐Ÿ”’ Shell 1 2022-11-02
List all the files belonging to all the (apt) packages on... ๐Ÿ”’ Shell 2 2022-10-01
tryadactyl OpenSCAD hyperfine timing script ๐Ÿ”’ Shell 1 2022-09-30
Python: list iOS RAW Photos that can be deleted or downgr... ๐Ÿ”’ Python 1 2022-09-21
OpenSCAD++: C++ API to write OpenSCAD programs in C++ ๐Ÿ”’ C++ 1 2022-09-02
TypedFunction: a pure-JS typed function that can be seria... ๐Ÿ”’ JavaScript 1 2022-08-09
Google Spreadsheet Apps Script to Create / Update Calenda... ๐Ÿ”’ JavaScript 1 2022-08-04
OpenSCAD slicing utility to use dual-extruder printers wi... ๐Ÿ”’ Markdown 2 2022-08-03
DFT.java Java 1 2022-05-04
OpenSCAD Eigen Vector Hybrid v2 ๐Ÿ”’ C++ 2 2022-03-23
Test eigen api + possible dynamic lazy wrapper for OpenSCAD ๐Ÿ”’ C++ 1 2022-03-18
Optimized OpenSCAD Vector w/ Eigen types ๐Ÿ”’ C++ 2 2022-03-18
BOSL2 Smooth Skin + Turtle for OpenSCAD ๐Ÿ”’ Markdown 2 2022-03-16
URL encode of json ๐Ÿ”’ JavaScript 1 2022-03-15
Bezier Turtle for BOSL2 / OpenSCAD ๐Ÿ”’ OpenSCAD 1 2022-03-15
CGAL Number that wraps another with an interval, for a ma... ๐Ÿ”’ C++ 1 2022-03-05
Draft ideas re/ pluggable CSG engines in OpenSCAD ๐Ÿ”’ C++ 1 2022-03-02
Repro test case for suspicion of T-junctions in CGAL core... ๐Ÿ”’ C++ 1 2022-03-01
fast-csg-remesh VERBOSE_REMESHING ๐Ÿ”’ C++ 1 2022-03-01
scalable_map.h: pair->flat_map->unordered_map as growth d... ๐Ÿ”’ C++ 1 2022-02-23
WIP CGAL Cached Number for Kernels ๐Ÿ”’ C++ 3 2022-02-23
CGAL corefinement visitor to remesh the remains of split ... ๐Ÿ”’ C++ 5 2022-02-21
OpenSCAD.js TS definitions brainstorming ๐Ÿ”’ TypeScript 1 2022-02-18
Building OpenSCAD with remeshing to fix fast-csg's perfor... Markdown 1 2022-02-13
Repro instructions for a CGAL compilation bug that starte... Markdown 3 2022-02-05
Build an optimized OpenSCAD locally on MacOS X (checkout ... Markdown 2 2022-02-03
Github workflow for CGAL versions testing in OpenSCAD (or... ๐Ÿ”’ YAML 1 2022-02-02
MeshroomCL OpenCL kernels extracted from its Windows64 bi... ๐Ÿ”’ Markdown 4 2022-02-02
colmap + CUDA on a remote VM w/ GPU ๐Ÿ”’ Markdown 1 2022-02-02
Unicode block art in Bash for animated progress indicator... ๐Ÿ”’ Shell 4 2022-02-01
Wrapper around wg show that uses pivpn configuration na... Shell 1 2021-12-28
RGB QR code experimentation ๐Ÿ”’ Markdown 2 2021-12-01
Complete echo + create w/ brotli support ๐Ÿ”’ HTML 5 2021-11-29
Decompress from data uri ๐Ÿ”’ Text 1 2021-11-29
Hardlink: access devices from anywhere, securely. ๐Ÿ”’ Shell 1 2021-08-16
README.md Markdown 2 2021-08-11
Static page that displays URL #hash content safely. Ideal... Markdown 2 2021-08-06
Static page that displays URL #hash content safely (Also,... ๐Ÿ”’ HTML 2 2021-08-06
CGAL ApproxDouble Kernel: pushing naive inexact operation... ๐Ÿ”’ C++ 1 2021-02-25
OpenSCAD Minkowski benchmarks ๐Ÿ”’ Markdown 2 2021-02-24
OpenSCAD Epick minkowski ๐Ÿ”’ C++ 1 2021-02-23
CGAL corefinement vs. potentially-invalid inputs vs. atte... Markdown 2 2021-02-22
CGAL nef/polyhedron/surface mesh CSG operation tests ๐Ÿ”’ C++ 5 2021-02-20
Check edge cases of CGAL::Polygon_mesh_processing::corefi... C++ 1 2021-02-20
Surface_mesh version of CGALHybridPolyhedron ๐Ÿ”’ C++ 2 2021-02-19
CGAL::Polyhedron_3 repair code with CGAL::Polygon_mesh_pr... C++ 1 2021-02-19
An OpenSCAD model of scalemail (source included below) th... OpenSCAD 4 2021-02-14
The ultimate union of CGAL::{Polyhedron_3,Nef_polyhedron_... ๐Ÿ”’ C++ 2 2021-02-02
Experiment w/ fast-union heuristic to break local overlap... C++ 3 2021-01-30
OpenSCAD benchmarking utility (compares various features ... Shell 1 2021-01-30
OpenSCAD Chainmail benchmark for fast-union evaluation OpenSCAD 1 2021-01-30
Some stress test for lazier unions OpenSCAD 1 2021-01-30
OpenSCAD file with an irregular pattern OpenSCAD 1 2021-01-29
https://www.waveshare.com/servo-driver-hat.htm ๐Ÿ”’ Python 1 2020-11-18
Flat buffers in dart... with idiomatic but inefficient bu... ๐Ÿ”’ Dart 1 2020-02-24
dart:js doesn't unwrap IntersectionObserver Dart 1 2020-02-04
dart:js IntersectionObserver unwrapping bug Dart 1 2020-02-04
Overload - preload links! ๐Ÿ”’ HTML 5 2019-08-02
Angular TypeScript -> React ๐Ÿ”’ TSX 1 2018-10-18
Deconstruct ECMAScript 6 Proxy-based Lenses ๐Ÿ”’ HTML 1 2018-03-08
Confusables Unicode characters demo ๐Ÿ”’ JavaScript 3 2018-02-07
es6 proxy sandbox ๐Ÿ”’ HTML 1 2018-01-11
Web bot with voice recognition & synthesis ๐Ÿ”’ HTML 2 2017-11-27
Typer demo: adds TypeScript types to JavaScript code, in ... ๐Ÿ”’ HTML 1 2017-02-05
Copy of github.com/ochafik/typer for the purpose of exami... ๐Ÿ”’ TypeScript 9 2017-02-03
Infer missing typescript types ๐Ÿ”’ TypeScript 5 2017-02-02
dom abduction ๐Ÿ”’ HTML 1 2016-12-22
Opinion(Burkini รฉtรฉ 2016): Dรฉlit de terrorisme vestimenta... Markdown 1 2016-10-15
Mutable -> Immutable transition library ๐Ÿ”’ TypeScript 1 2016-10-10
TypeScript protobufs ๐Ÿ”’ TypeScript 2 2016-10-05
ES6 Proxy-based Sandbox in TypeScript ๐Ÿ”’ TypeScript 1 2016-09-06
Nested property access notation for types ๐Ÿ”’ Markdown 1 2016-09-03
burkini.md ๐Ÿ”’ Markdown 1 2016-08-26
example.ts ๐Ÿ”’ TypeScript 4 2016-06-21
Dart Development Server Python 1 2016-06-18
null-inference ๐Ÿ”’ JavaScript 3 2016-03-15
ES6 destructuring in DDC ๐Ÿ”’ JavaScript 3 2016-03-15
generics.js ๐Ÿ”’ JavaScript 2 2016-02-18
gistfile1.txt ๐Ÿ”’ Shell 1 2015-12-15
TestOpenCLDataTransfers.java Java 1 2015-12-15
Macro Extensions Plugin Input / Output with macro body Scala 2 2015-12-13
Macro Extensions Plugin Input / Output Scala 2 2015-12-13
Runtime Extension Plugin Scala 2 2015-12-13
Scala 2.9 Extensions.scala Scala 1 2015-12-13
Scala 2.10 Extensions.scala Scala 1 2015-12-13
Example of simplified macro definition that could be made... Scala 1 2015-12-13
Ideas on how to extend Scalaxy/Compilets to support untyp... Scala 1 2015-12-13
TransformBeforeTyper.scala Scala 1 2015-12-13
SomeAssert.java Java 2 2015-12-13
TediousAssertMessage.scala Scala 1 2015-12-13
ScalaxyDebugAssert.scala Scala 1 2015-12-13
build.sbt Scala 1 2015-12-13
StringInterpolatedAssertMessage.scala Scala 1 2015-12-13
move_ddc_runtime_js_to_dart.sh Shell 1 2015-12-13
gistfile1.scala Scala 1 2015-12-12
gistfile1.scala Scala 1 2015-12-12
gistfile1.scala Scala 1 2015-12-12
gistfile1.scala Scala 1 2015-12-12
gistfile1.scala Scala 1 2015-12-12
an_example.scala Scala 2 2015-12-12
Beans factory implementation Scala 1 2015-12-12
Beans setters Scala 1 2015-12-12
Beans factory example Scala 1 2015-12-12
angular2 code size ๐Ÿ”’ Shell 1 2015-10-22
test.scala ๐Ÿ”’ Scala 1 2015-10-07
gistfile1.scala Scala 1 2015-10-04
DFT2.java Java 1 2015-09-24
DiscreteFourierTransformProgram.java Java 1 2015-09-24
DiscreteFourierTransformProgram.c C 1 2015-09-24
DiscreteFourierTransformProgram.cl OpenCL 1 2015-09-24
pom.xml Maven POM 1 2015-09-24
es6_runtime.js JavaScript 3 2015-09-18
skygular HTML 1 2015-09-04
test.dart ๐Ÿ”’ Dart 1 2015-08-29
needle ๐Ÿ”’ JavaScript 5 2015-08-29
dart_jvm_test.dart ๐Ÿ”’ Dart 14 2015-08-29
Simple example of async/await transform for Dart's dev_co... Dart 2 2015-08-29
Reduction.scala ๐Ÿ”’ Scala 3 2015-08-29
dart parser.scala ๐Ÿ”’ Scala 1 2015-08-29
opencl tuples dart ๐Ÿ”’ Dart 1 2015-08-29
OpenCL Tuples in Scala ๐Ÿ”’ Scala 1 2015-08-29
Dart Closure Placeholders ๐Ÿ”’ Dart 2 2015-08-29
transformer.dart ๐Ÿ”’ Dart 1 2015-08-29
Scala OpenCL AnyVal wrappers ๐Ÿ”’ Scala 3 2015-08-29
ScalaCL v3 unit test ๐Ÿ”’ Scala 2 2015-08-29
Diagrammed Assertions for JavaScript / ES6 !!! ๐Ÿ”’ JavaScript 3 2015-08-29
Poor man's Proxy polyfill JavaScript 1 2015-08-29
gistfile1.scala ๐Ÿ”’ Scala 9 2015-08-29
designer HTML 1 2015-08-29
Experiment on Closure Compiler's function types (behaviou... JavaScript 1 2015-08-27

How to Update

This index is generated by the index.ts script in this gist.

Run locally:

# Requires: deno, gh CLI (authenticated)
GITHUB_TOKEN=$(gh auth token) GIST_ID=a1ccb90267fc6558bb3aafbe90b64048 \
  deno run --allow-net --allow-env \
  https://gist.githubusercontent.com/ochafik/a1ccb90267fc6558bb3aafbe90b64048/raw/index.ts

Options:

  • DRY_RUN=1 - Preview without updating
  • INCLUDE_PRIVATE=0 - Exclude private gists

Generated by gist-indexer

#!/usr/bin/env -S deno run --allow-net --allow-env
/**
* Gist Indexer - A self-contained script that generates a markdown index of your GitHub gists.
*
* This script lives in a gist and updates its own README.md with an index of all your gists.
*
* Usage:
* GITHUB_TOKEN=ghp_xxx GIST_ID=abc123 deno run --allow-net --allow-env index.ts
*
* Or with gh CLI:
* GITHUB_TOKEN=$(gh auth token) GIST_ID=abc123 deno run --allow-net --allow-env index.ts
*
* Environment variables:
* GITHUB_TOKEN - GitHub Personal Access Token with 'gist' scope (required)
* GIST_ID - ID of the gist to update (required for self-update)
* DRY_RUN - Set to '1' to print markdown without updating (optional)
* INCLUDE_PRIVATE - Set to '1' to include private gists (optional, default: true)
*/
// ============================================================================
// Types
// ============================================================================
interface GistFile {
filename: string;
type: string;
language: string | null;
raw_url: string;
size: number;
}
interface GistOwner {
login: string;
html_url: string;
}
interface Gist {
id: string;
html_url: string;
description: string | null;
public: boolean;
created_at: string;
updated_at: string;
files: Record<string, GistFile>;
owner: GistOwner;
}
interface Config {
token: string;
gistId: string | null;
dryRun: boolean;
includePrivate: boolean;
}
// ============================================================================
// Configuration
// ============================================================================
function getConfig(): Config {
const token = Deno.env.get("GITHUB_TOKEN");
if (!token) {
console.error("Error: GITHUB_TOKEN environment variable is required");
console.error("Get one at: https://github.com/settings/tokens/new?scopes=gist");
Deno.exit(1);
}
return {
token,
gistId: Deno.env.get("GIST_ID") || null,
dryRun: Deno.env.get("DRY_RUN") === "1",
includePrivate: Deno.env.get("INCLUDE_PRIVATE") !== "0",
};
}
// ============================================================================
// GitHub API Client
// ============================================================================
const API_BASE = "https://api.github.com";
const API_VERSION = "2022-11-28";
async function fetchWithAuth(url: string, token: string, options: RequestInit = {}): Promise<Response> {
const headers = new Headers(options.headers);
headers.set("Authorization", `Bearer ${token}`);
headers.set("Accept", "application/vnd.github+json");
headers.set("X-GitHub-Api-Version", API_VERSION);
return fetch(url, { ...options, headers });
}
async function fetchAllGists(token: string): Promise<Gist[]> {
const allGists: Gist[] = [];
let page = 1;
const perPage = 100;
console.error("Fetching gists...");
while (true) {
const url = `${API_BASE}/gists?per_page=${perPage}&page=${page}`;
const response = await fetchWithAuth(url, token);
if (!response.ok) {
const error = await response.text();
throw new Error(`Failed to fetch gists: ${response.status} ${error}`);
}
const gists: Gist[] = await response.json();
if (gists.length === 0) {
break;
}
allGists.push(...gists);
console.error(` Fetched page ${page}: ${gists.length} gists (total: ${allGists.length})`);
if (gists.length < perPage) {
break;
}
page++;
}
return allGists;
}
async function updateGistReadme(token: string, gistId: string, content: string): Promise<void> {
const url = `${API_BASE}/gists/${gistId}`;
const response = await fetchWithAuth(url, token, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
files: {
"README.md": { content },
},
}),
});
if (!response.ok) {
const error = await response.text();
throw new Error(`Failed to update gist: ${response.status} ${error}`);
}
console.error("Successfully updated gist README.md");
}
// ============================================================================
// Markdown Generator
// ============================================================================
function getGistName(gist: Gist): string {
// Use description if available, otherwise first filename
if (gist.description && gist.description.trim()) {
// Truncate long descriptions
const desc = gist.description.trim();
return desc.length > 60 ? desc.substring(0, 57) + "..." : desc;
}
const files = Object.keys(gist.files);
return files[0] || "Untitled";
}
function getGistLanguage(gist: Gist): string {
// Get the primary language from files
const languages = Object.values(gist.files)
.map((f) => f.language)
.filter((l): l is string => l !== null);
if (languages.length === 0) return "Other";
// Count occurrences and return the most common
const counts = languages.reduce((acc, lang) => {
acc[lang] = (acc[lang] || 0) + 1;
return acc;
}, {} as Record<string, number>);
return Object.entries(counts).sort((a, b) => b[1] - a[1])[0][0];
}
function formatDate(isoDate: string): string {
const date = new Date(isoDate);
return date.toISOString().split("T")[0]; // YYYY-MM-DD
}
function escapeMarkdown(text: string): string {
return text.replace(/([[\]|])/g, "\\$1");
}
function groupByLanguage(gists: Gist[]): Map<string, Gist[]> {
const groups = new Map<string, Gist[]>();
for (const gist of gists) {
const lang = getGistLanguage(gist);
if (!groups.has(lang)) {
groups.set(lang, []);
}
groups.get(lang)!.push(gist);
}
// Sort each group by updated_at descending
for (const [, gistList] of groups) {
gistList.sort((a, b) => new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime());
}
// Sort languages by count (descending), then alphabetically
return new Map(
[...groups.entries()].sort((a, b) => {
const countDiff = b[1].length - a[1].length;
if (countDiff !== 0) return countDiff;
return a[0].localeCompare(b[0]);
})
);
}
function generateMarkdown(gists: Gist[], username: string, selfGistId: string | null): string {
const now = new Date().toISOString().replace("T", " ").substring(0, 16) + " UTC";
const publicCount = gists.filter((g) => g.public).length;
const privateCount = gists.length - publicCount;
const lines: string[] = [];
// Header
lines.push("# Gist Index");
lines.push("");
lines.push(`> [@${username}](https://gist.github.com/${username})'s gists`);
lines.push("");
// Stats
const stats = [`**Last updated:** ${now}`, `**Total:** ${gists.length} gists`];
if (privateCount > 0) {
stats.push(`(${publicCount} public, ${privateCount} private)`);
}
lines.push(stats.join(" | "));
lines.push("");
// Group by language
const grouped = groupByLanguage(gists);
lines.push("## By Language");
lines.push("");
for (const [language, langGists] of grouped) {
lines.push(`### ${language} (${langGists.length})`);
lines.push("");
for (const gist of langGists) {
const name = escapeMarkdown(getGistName(gist));
const visibility = gist.public ? "" : " ๐Ÿ”’";
const fileCount = Object.keys(gist.files).length;
const fileInfo = fileCount > 1 ? ` (${fileCount} files)` : "";
lines.push(`- [**${name}**](${gist.html_url})${visibility}${fileInfo}`);
}
lines.push("");
}
// Full table
lines.push("## All Gists");
lines.push("");
lines.push("| Gist | Language | Files | Updated |");
lines.push("|------|----------|-------|---------|");
// Sort all gists by updated_at descending
const sortedGists = [...gists].sort(
(a, b) => new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime()
);
for (const gist of sortedGists) {
const name = escapeMarkdown(getGistName(gist));
const visibility = gist.public ? "" : " ๐Ÿ”’";
const lang = getGistLanguage(gist);
const fileCount = Object.keys(gist.files).length;
const updated = formatDate(gist.updated_at);
lines.push(`| [${name}](${gist.html_url})${visibility} | ${lang} | ${fileCount} | ${updated} |`);
}
lines.push("");
// Usage section
lines.push("---");
lines.push("");
lines.push("## How to Update");
lines.push("");
lines.push("This index is generated by the `index.ts` script in this gist.");
lines.push("");
lines.push("**Run locally:**");
lines.push("```bash");
lines.push("# Requires: deno, gh CLI (authenticated)");
if (selfGistId) {
lines.push(`GITHUB_TOKEN=$(gh auth token) GIST_ID=${selfGistId} \\`);
lines.push(` deno run --allow-net --allow-env \\`);
lines.push(` https://gist.githubusercontent.com/${username}/${selfGistId}/raw/index.ts`);
} else {
lines.push("GITHUB_TOKEN=$(gh auth token) GIST_ID=<your-gist-id> \\");
lines.push(" deno run --allow-net --allow-env index.ts");
}
lines.push("```");
lines.push("");
lines.push("**Options:**");
lines.push("- `DRY_RUN=1` - Preview without updating");
lines.push("- `INCLUDE_PRIVATE=0` - Exclude private gists");
lines.push("");
// Footer
if (selfGistId) {
lines.push(
`*Generated by [gist-indexer](https://gist.github.com/${username}/${selfGistId})*`
);
} else {
lines.push("*Generated by gist-indexer*");
}
lines.push("");
return lines.join("\n");
}
// ============================================================================
// Main
// ============================================================================
async function main() {
const config = getConfig();
// Fetch all gists
const allGists = await fetchAllGists(config.token);
if (allGists.length === 0) {
console.error("No gists found!");
return;
}
// Get username from first gist
const username = allGists[0].owner.login;
console.error(`Found ${allGists.length} gists for @${username}`);
// Filter based on config
let gists = allGists;
if (!config.includePrivate) {
gists = allGists.filter((g) => g.public);
console.error(`Filtered to ${gists.length} public gists`);
}
// Exclude self from the list (optional - uncomment if desired)
// if (config.gistId) {
// gists = gists.filter((g) => g.id !== config.gistId);
// }
// Generate markdown
const markdown = generateMarkdown(gists, username, config.gistId);
if (config.dryRun) {
console.log(markdown);
console.error("\n[DRY RUN] Would update gist with above content");
return;
}
if (!config.gistId) {
console.log(markdown);
console.error("\n[INFO] No GIST_ID provided. Set GIST_ID to auto-update your gist.");
return;
}
// Update the gist
await updateGistReadme(config.token, config.gistId, markdown);
console.error(`Updated: https://gist.github.com/${username}/${config.gistId}`);
}
// Run
main().catch((err) => {
console.error("Error:", err.message);
Deno.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment