Skip to content

Instantly share code, notes, and snippets.

@davepeck
davepeck / python314.tmLanguage.json
Created May 15, 2025 21:47
TextMate (JSON-format) grammar for Python 3.14, with support for t-string syntax
{
"displayName": "Python 3.14",
"name": "python314",
"patterns": [
{
"include": "#statement"
},
{
"include": "#expression"
}
@davepeck
davepeck / retirement.html
Created December 12, 2024 18:33
Retirement Progress Webpage -- built in ~1 minute using ChatGPT's new Canvas UI
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Progress to Retirement</title>
<style>
body {
font-family: "Helvetica Neue", sans-serif;
@davepeck
davepeck / FIREHOSE.md
Last active May 16, 2025 12:49
Zero-dependency Python script to decode the Bluesky firehose

Zero-dependency Python script to decode the Bluesky Firehose

This is a pure Python implementation of code necessary to decode the Bluesky Firehose's low-level binary data format.

It does not depend on any third-party libraries for decoding; we implement DAG_CBOR and CARv1 decoding ourselves.

To run this, install Astral's UV.

Then:

@davepeck
davepeck / RESOLVE.md
Last active March 22, 2025 03:54
A Tiny Python script to convert Bluesky handles to DIDs, and DIDs to handles

A command-line script to convert between Bluesky DIDs and handles

This small Python script makes it easy to convert from ATProto DIDs to their associated handles and back again:

$ ./resolve.py handle @davepeck.org
did:plc:caznr5mgvjft4mu4p2vpttfx
$ ./resolve.py did did:plc:caznr5mgvjft4mu4p2vpttfx
davepeck.org
@davepeck
davepeck / JETSTREAM.md
Last active June 5, 2025 13:06
Tiny Python script to access the Bluesky Jetstream (MIT License)

Jetstream command-line utility

Connect to the Bluesky Jetstream, emitting one JSON line per message received.

To use, make sure you have Astral's UV installed.

Then, run it as:

$ uv run https://gist.githubusercontent.com/davepeck/5484fc026a2e8269cf1ead00fff0ef8f/raw/ab4b06145d01f16c216ca3135da2945abdaf0010/jetstream.py
@davepeck
davepeck / bq.py
Last active January 5, 2024 17:20
Toying around with a very naive python BigQuery query builder + related utilities
"""BigQuery utilities."""
import datetime
import typing as t
from abc import ABC, abstractmethod
from google.cloud import bigquery
from google.cloud.bigquery import query
type QueryParamValue = str | int | float | datetime.date | datetime.datetime | t.Sequence[ # noqa: E501
@davepeck
davepeck / well-known-redirect.js
Created January 25, 2023 22:04
My first cloudfront edge function
// note that a lot of code choices here are due to the fact that cloudfront edge uses
// a hilariously backwards version of javascript:
//
// "const", you say? what's that?!
// deal with the painful structure that cloudfront edge functions use for query params
function getURLSearchParamsString(obj) {
var str = [];
for (var param in obj) {
if (obj[param].multiValue) {
@davepeck
davepeck / game_of_life_copilot.py
Last active January 24, 2023 17:17
Game of life, python CLI, entirely written by GitHub Copilot (I only wrote the comments!)
import time
from random import random
from typing import Set, Tuple
# Set the default BOARD_SIZE to 40
BOARD_SIZE = 40
def init_board_with_n_gliders(n: int) -> Set[Tuple[int, int]]:
"""Initialize a board with n gliders."""
@davepeck
davepeck / validate-css.mjs
Last active April 24, 2022 20:44
Example of how to run vscode's built-in CSS validations from the command-line. Use `node validate-css.mjs *.css`.
import fs from "fs";
import url from "url";
import { getCSSLanguageService } from "vscode-css-languageservice";
import { TextDocument } from "vscode-languageserver-textdocument";
/** Human-readable names for the potential diagnostic severities returned. */
const severities = { 1: "ERR", 2: "WARN", 3: "INFO", 4: "HINT" };
/** Format a position in a given file. */
@davepeck
davepeck / Today's Wordle Solution.md
Last active January 8, 2022 00:25
Compute today's wordle solution

It's pretty simple. Example usage:

>  python3 wordle.py
banal