Skip to content

Instantly share code, notes, and snippets.

View simonw's full-sized avatar

Simon Willison simonw

View GitHub Profile
@simonw
simonw / default_permissions.py
Created October 13, 2022 21:02
Alternative version of default_permissions.py in datasette suitable for debugging
from datasette import hookimpl
from datasette.utils import actor_matches_allow
@hookimpl(tryfirst=True)
def permission_allowed(datasette, actor, action, resource):
print("permission_allowed actor=", actor, "action=", action, resource)
async def inner():
result = await _permission_allowed(datasette, actor, action, resource)()
@simonw
simonw / README.md
Last active September 16, 2022 02:20

Alaska ranked choice data

I took the JSON from https://www.elections.alaska.gov/election-results/e/ and loaded it into SQLite.

But... I had to drop the single most interesting table - CvrExport - because at over 300MB it was too big to fit in a Gist!

So this database could be a lot more interesting.

@simonw
simonw / README.md
Last active September 15, 2022 15:35
Code from https://remusao.github.io/posts/python-dbm-module.html modified to add primary keys

Code from https://remusao.github.io/posts/python-dbm-module.html modified to add primary keys.

The change I made to the original script was to add a primary key, like this:

CREATE TABLE store(key TEXT PRIMARY KEY, value TEXT)

Here are the results before I made that change:

sqlite (this is with executemany)

Took 0.032 seconds, 3.19541 microseconds / record

@simonw
simonw / KeyValueStore.md
Created September 14, 2022 03:10
iPhone /MediaAnalysis/mediaanalysis.db KeyValueStore table

This is the contents of the KeyValueStore table in MediaAnalysis/mediaanalysis.db on my iPhone.

id key value
2595488 FaceAnalysisVersion 11
2595489 LatestFaceAnalysisVersionTimestamp 658412515
2595494 EmbeddingAnalysisVersion 6
2595495 LatestEmbeddingAnalysisVersionTimestamp 658412515
3025301 FaceAnalysisCompleteTimestamp 664464796
3095768 TotalTimeRunningWithoutPendingAnalysisInLatestVersion 15571
File NRE ID Transcription Category Notes Timestamp mp3
1 Platform Platform ID 0:00:00 https://github.com/matteason/scotrail-announcements-june-2022/raw/main/announcements/0001.mp3
2 A trolley service Passenger information 0:00:02 https://github.com/matteason/scotrail-announcements-june-2022/raw/main/announcements/0002.mp3
3 WBQ Warrington Bank Quay Destination 0:00:05 https://github.com/matteason/scotrail-announcements-june-2022/raw/main/announcements/0003.mp3
4 South West Trains service to Train operating company Bit of a detour 0:00:07 https://github.com/matteason/scotrail-announcements-june-2022/raw/main/announcements/0004.mp3
5 South West Trains service to Train operating company 0:00:10 https://github.com/matteason/scotrail-announcements-june-2022/raw/main/announcements/0005.mp3
6 BTH Bath Spa Destination 0:00:14 https://github.com/matteason/scotrail-announcements-june-2022/raw/main/announcements/0006.mp3
7 Midland Main Line Train Operating Company Stopped existing in 2007! 0:00:16 https://gi
@simonw
simonw / README.md
Last active August 30, 2023 12:52
-- Example from https://www.sqlite.org/lang_with.html#outlandish_recursive_query_examples
CREATE TABLE mandelbrot AS WITH RECURSIVE
xaxis(x) AS (VALUES(-2.0) UNION ALL SELECT x+0.05 FROM xaxis WHERE x<1.2),
yaxis(y) AS (VALUES(-1.0) UNION ALL SELECT y+0.1 FROM yaxis WHERE y<1.0),
m(iter, cx, cy, x, y) AS (
SELECT 0, x, y, 0.0, 0.0 FROM xaxis, yaxis
UNION ALL
SELECT iter+1, cx, cy, x*x-y*y + cx, 2.0*x*y + cy FROM m
WHERE (x*x + y*y) < 4.0 AND iter<28
),
@simonw
simonw / packages.txt
Created August 9, 2022 18:56
List of packages on a fresh Ubuntu Docker image after installing python3-pip - using apt list --installed
adduser/jammy,now 3.118ubuntu5 all [installed]
apt/jammy-updates,now 2.4.6 amd64 [installed]
base-files/jammy-updates,now 12ubuntu4.2 amd64 [installed]
base-passwd/jammy,now 3.5.52build1 amd64 [installed]
bash/jammy,now 5.1-6ubuntu1 amd64 [installed]
binutils-common/jammy,now 2.38-3ubuntu1 amd64 [installed,automatic]
binutils-x86-64-linux-gnu/jammy,now 2.38-3ubuntu1 amd64 [installed,automatic]
binutils/jammy,now 2.38-3ubuntu1 amd64 [installed,automatic]
bsdutils/jammy,now 1:2.37.2-4ubuntu3 amd64 [installed]
build-essential/jammy,now 12.9ubuntu3 amd64 [installed,automatic]
@simonw
simonw / packages.txt
Created August 9, 2022 18:55
Full list of "apt list --installed" packages on GitHub Actions ubuntu worker
accountsservice/focal-updates,focal-security,now 0.6.55-0ubuntu12~20.04.5 amd64 [installed,automatic]
acl/focal,now 2.2.53-6 amd64 [installed]
adduser/focal,now 3.118ubuntu2 all [installed,automatic]
adoptium-ca-certificates/now 1.0.0-1 all [installed,local]
adoptopenjdk-11-hotspot/now 11.0.11+9-3 amd64 [installed,local]
adoptopenjdk-8-hotspot/now 8u292-b10-3 amd64 [installed,local]
adwaita-icon-theme/focal-updates,now 3.36.1-2ubuntu0.20.04.2 all [installed,automatic]
alsa-topology-conf/focal,now 1.2.2-1 all [installed,automatic]
alsa-ucm-conf/focal-updates,now 1.2.2-1ubuntu0.13 all [installed,automatic]
ant-optional/focal,now 1.10.7-1 all [installed]
@simonw
simonw / Dockerfile
Created July 25, 2022 00:27
redbean-on-fly
# Copied from https://github.com/kissgyorgy/redbean-docker/blob/master/Dockerfile-multistage
FROM alpine:latest as build
ARG DOWNLOAD_FILENAME=redbean-original-2.0.8.com
RUN apk add --update zip bash
RUN wget https://redbean.dev/${DOWNLOAD_FILENAME} -O redbean.com
RUN chmod +x redbean.com