Skip to content

Instantly share code, notes, and snippets.

View boxabirds's full-sized avatar
:shipit:

Julian Harris boxabirds

:shipit:
View GitHub Profile
@boxabirds
boxabirds / .zshrc-uv
Last active March 17, 2025 02:16
uvshell and uvinstall pipenv emulations
# pipenv is extremely slow but it's very easy to use.
# here are two wrapper scripts to emulate pipenv shell and pipenv install
# add to your .zshrc file
# emulate pipenv shell
function uvshell() {
if [[ -d .venv ]]; then
source .venv/bin/activate || { echo "Failed to activate virtual env"; return 1; }
else
@boxabirds
boxabirds / Node_modules-RAM-disk.md
Created January 25, 2025 03:03
node_modules on Mac RAM disk

Deepseek r1 says this

Key Clarifications

  1. APFS Global Kernel Lock (vfs-layer lock):

    • Not fully bypassed: Even with a RAM disk formatted as APFS, macOS's global I/O lock still technically exists. However, because RAM disk operations are orders of magnitude faster than disk I/O, contention for this lock is drastically reduced. This makes the lock effectively irrelevant for most workflows, as operations complete before significant contention occurs.
    • Not the same as Linux: macOS lacks a true tmpfs equivalent, so while a RAM disk helps, it’s not as seamless as Linux’s in-memory filesystem.
  2. RAM Disk Format:

    • macOS RAM disks can be formatted as HFS+ or APFS. While APFS is the default, formatting as HFS+ might slightly reduce lock contention (though benchmarks vary). Either way, the speed of RAM mitigates lock-related bottlenecks.
@boxabirds
boxabirds / gist:2892a2bc4aa3c087b8e8d31564572073
Created December 29, 2024 22:04
Coding Agent prompt for review & retrospective documentation
At this point I want you to create a design doc that describes the following things. The things below are to be made into separate .md files in a doc/ directory.
mermaid diagrams showing the key objects and their relationships
mermaid sequence diagram showing key interactions for the main use cases
summarise the agent journey so far: review the entire chat history and highlight the things that were easy to implement (one prompt => feature) and things that were very hard to implement
following this, create a maintenance guide whose sole objective is to help the next contributors to the code base. It should explain the frameworks and services used, the components, and notes on anything about the implementation that may not be obvious to someone even if they have experience with the framework used.
finally summarise areas that need to be developed to turn this into a proper product that can be supported, maintained and expanded.E.g. logging, telemetry, security considerations etc.
@boxabirds
boxabirds / sample.txt
Created December 15, 2024 12:13
sqlc column name mapping question
SQL:
-- name: GetRecentPostsByTags :many
-- $1: TagNames
SELECT DISTINCT p.id, p.created_at, t.name AS tag_name
FROM posts p
JOIN post_tags pt ON p.id = pt.post_id
JOIN tags t ON pt.tag_id = t.id
WHERE t.name = ANY($1::text[]) AND p.created_at < $2
ORDER BY p.created_at DESC
@boxabirds
boxabirds / increment-version-patch.js
Created November 22, 2024 13:49
Autobump version patch (node script for bumping the version patch)
// track every build with a unique number
// e.g. in package.json … "build": "node scripts/increment-version-patch.js && <your normal build script>"
const fs = require('fs');
const path = require('path');
const packageJsonPath = path.join(__dirname, '..', 'package.json');
const packageJson = require(packageJsonPath);
// Split version into major, minor, and patch
const [major, minor, patch] = packageJson.version.split('.').map(Number);
@boxabirds
boxabirds / estimator.js
Created October 22, 2024 20:50
Google Gemini cost estimator (node)
const {GoogleGenerativeAI} = require('@google/generative-ai');
/**
* Estimates the cost of a Gemini API invocation based on token usage.
*
* @param {Object} usageMetadata - The usage metadata from the API response.
* @param {number} usageMetadata.promptTokenCount - The number of tokens in the input prompt.
* @param {number} usageMetadata.candidatesTokenCount - The number of tokens in the output.
* @returns {number} The estimated cost of the invocation in USD.
*
* Pricing information:
@boxabirds
boxabirds / img2alt.py
Created August 6, 2024 12:15
Generate alt tags for images (using llava)
import os
import requests
from bs4 import BeautifulSoup
import argparse
import base64
import json
def download_image(url, save_path):
response = requests.get(url)
if response.status_code == 200:
@boxabirds
boxabirds / main.go
Created June 22, 2024 19:52
Whisper.cpp go demo
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
whisper "github.com/ggerganov/whisper.cpp/bindings/go"
)
@boxabirds
boxabirds / openai-fixed-seed-demo.go
Created May 28, 2024 11:15
Demo of how fixing the seed with OpenAI's API gives deterministic results.
// Demo of how you can fix the seed with OpenAI and you'll get deterministic output.
// this is only for a given system fingerprint
package main
import (
"context"
"flag"
"fmt"
"io"
"log"
@boxabirds
boxabirds / image-captioning-ollama-llava.go
Created May 26, 2024 22:08
Demo of using ollama + llava to create extremely detailed image captions from an image
// this is a demo that connects to ollama and
// Prerequisites:
// - ollama
// - open weights model "llava" 1.6 or greater
package main
import (
"bytes"
"encoding/base64"
"encoding/json"