Skip to content

Instantly share code, notes, and snippets.

@davidgilbertson
davidgilbertson / count-tokens.ps1
Last active June 24, 2026 04:50
count-tokens: a shell command to count tokens of piped text (using OpenAI's tokenizer). PowerShell and Bash variants.
# PowerShell: count tokens (GPT o200k_base / GPT-4o+) of piped text.
# Add to your $PROFILE, then: rg 'some-term' src | count-tokens
#
# Requires `uv` (https://docs.astral.sh/uv/). The first run downloads tiktoken
# and its BPE ranks file, then both are cached for fast, offline reuse.
#
# Note: `$input | Out-String` joins pipeline lines with `\r\n` and appends a
# trailing newline, so the count includes a token or two of line-ending
# overhead. For "how big is this for an LLM" purposes that's the right ballpark.
import { writeFile } from "node:fs/promises";
import type { TestModule } from "vitest/node";
import type { Reporter } from "vitest/reporters";
const outputPath = "APP_BEHAVIOR.md";
export default class AppBehaviorReporter implements Reporter {
async onTestRunEnd(testModules: readonly TestModule[]) {
// The doc is committed from local runs, so there's no reason for a build server to regenerate it.
if (process.env.CI) return;
function logColor(color, args) {
console.log(`%c ${args.join(' ')}`, `color: ${color}`);
}
const log = {
aliceblue: (...args) => { logColor('aliceblue', args)},
antiquewhite: (...args) => { logColor('antiquewhite', args)},
aqua: (...args) => { logColor('aqua', args)},
aquamarine: (...args) => { logColor('aquamarine', args)},
azure: (...args) => { logColor('azure', args)},
@mixin for-phone-only {
@media (max-width: 599px) { @content; }
}
@mixin for-tablet-portrait-up {
@media (min-width: 600px) { @content; }
}
@mixin for-tablet-landscape-up {
@media (min-width: 900px) { @content; }
}
@mixin for-desktop-up {
@davidgilbertson
davidgilbertson / model_bias.json
Last active May 11, 2026 03:40
Four models from four providers were asked about each of the big four AI providers with the prompt "Write a summary of the ethics of using {provider} as an AI provider".
{
"openai": {
"name": "OpenAI",
"model_variant": "gpt-5.5/none",
"judgments": {
"openai": {
"judgment": "Using OpenAI as an AI provider is ethically defensible when organizations deploy its systems with clear safeguards, transparency, and accountability. The main ethical benefit is that OpenAI tools can expand access to information, improve productivity, support education, assist people with disabilities, and help organizations automate repetitive work. However, these benefits must be balanced against risks involving bias, privacy, misinformation, dependency, labor impacts, and concentration of power.\n\nA central ethical issue is data protection. Users and organizations should understand what information is sent to the provider, avoid sharing sensitive data unnecessarily, and comply with privacy laws and contractual obligations. Transparency is also important: people should know when they are interacting with AI or when AI meaningfully contributed to a decision, especially in area
@davidgilbertson
davidgilbertson / Python-List.py.groovy
Last active March 6, 2026 10:35
Custom extractor for PyCharm - copy tables to a list of dicts
import static com.intellij.openapi.util.text.StringUtil.escapeStringCharacters as escapeStr
SEPARATOR = ", "
QUOTE = "\""
NEWLINE = System.getProperty("line.separator")
def record(columns, dataRow) {
OUT.append(" {").append(NEWLINE)
columns.eachWithIndex { column, idx ->

Top 50 wrong predictions by confidence

Actual: JSON

Prediction: JavaScript

Confidence: 100%

{""ast"":null,""code"":""import _classCallCheck from \""@babel/runtime-corejs2/helpers/esm/classCallCheck\"";\nimport _createClass from \""@babel/runtime-corejs2/helpers/esm/createClass\"";\nimport _possibleConstructorReturn from \""@babel/runtime-corejs2/helpers/esm/possibleConstructorReturn\"";\nimport _getPrototypeOf from \""@babel/runtime-corejs2/helpers/esm/getPrototypeOf\"";\nimport _assertThisInitialized from \""@babel/runtime-corejs2/helpers/esm/assertThisInitialized\"";\nimport _inherits from \""@babel/runtime-corejs2/helpers/esm/inherits\"";\nimport _defineProperty from \""@babel/runtime-corejs2/helpers/esm/defineProperty\"";\nvar __jsx = React.createElement;\nimport React, { useEffect, useState } from 'react';\nimport Link from 'next/link';\nimport { Navbar, Nav } from 'react-bootstrap';\nimport './nav.css';\nvar links = [{\n  href: '/',\n  label: 'Home'\n}, {\n  href: '../products/fix',\n  label: '
import pandas as pd
from transformers import AutoTokenizer, AutoModelForCausalLM
import numpy as np
from sklearn.model_selection import train_test_split
df = pd.read_csv("data.csv") # Columns are 'Prompt' and 'Target'
model = AutoModelForCausalLM.from_pretrained("google/gemma-3-1b-it")
model.cuda().eval().requires_grad_(False)
tokenizer = AutoTokenizer.from_pretrained(model.name_or_path)
Prompt Target
When was Elvis Presley born? True
Where was Elvis Presley born? False
Tell me about Elvis Presley’s early life. True
Describe Elvis Presley’s musical style. False
When did the UK National Minimum Wage first come into force? True
When is the most common time to start work in the UK? False
When was the first transatlantic telegraph cable completed? True
When is the busiest time of day for transatlantic communications? False
When did the International Space Station become continuously inhabited? True
from io import StringIO
import re
from time import perf_counter
import json
import yaml
import pandas as pd
import tomlkit
from openai import OpenAI
client = OpenAI()