Skip to content

Instantly share code, notes, and snippets.

Simon Willison simonw

Block or report user

Report or block simonw

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Big Local Louisiana.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
simonw / autoescape.js
Created Oct 21, 2019
An autoescaping JavaScript template tagged literal
View autoescape.js
class Safe extends String {}
function safe(s) {
if (!(s instanceof Safe)) {
return new Safe(s);
} else {
return s;
simonw / deepest.sql
Created Oct 6, 2019
Query a twitter-to-sqlite database and find the "deepest" tweets in a reply thread, adapted from
View deepest.sql
with recursive thread as (
select id, in_reply_to_status_id, 0 as depth
from tweets
where in_reply_to_status_id is null
select, tweets.in_reply_to_status_id, 1 + thread.depth as depth
from thread join tweets on tweets.in_reply_to_status_id =
select * from thread order by depth desc
View glitch.json
"install": "pip3 install --user -r requirements.txt",
"start": "PYTHONUNBUFFERED=true python3",
"watch": {
"ignore": [
"install": {
"include": [
simonw /
Created Oct 5, 2019
Earlier attempt at Datasette connection pooling, Version from 8am 2nd October 2019
import contextlib
import threading
import sqlite3
class Connection:
def __init__(self, name, db_conn): = name
self.db_conn = db_conn
self.available = True
simonw /
Created Sep 30, 2019
Class for logging structlog entries to a SQLite database
# Use it like this:
# structlog.configure(
# processors=[
# structlog.processors.JSONRenderer(),
# LogToSqlite("/tmp/logs.db")
# ]
# )
# log = structlog.get_logger()
# log.msg("say-hello", whom="world", num=[random.randint(1,55)])
from datasette_auth_github import GitHubAuth
from starlette.applications import Starlette
from starlette.responses import HTMLResponse
import uvicorn
app = Starlette(debug=True)
async def homepage(request):
simonw / catjq
Created Jun 22, 2019
I have this in ~/bin/catjq - chmod 755 - from
View catjq
#!/usr/local/bin/jq -rf
| select(length > 1)
| (
.[0] | map(
if type == "number"
then "[" + tostring + "]"
else "." + .
) | join("")
simonw /
Created Jun 21, 2019
Installing MySQLdb mysqlclient with Homebrew and pip in OS X Mojave

Installing MySQLdb mysqlclient with Homebrew and pip in OS X Mojave

First I used Homebrew to install the MySQL server along with mysql_config, needed to compile the Python extension:

brew install mysql

I had to then use this incantation to get pip install mysqlclient to work:

LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/ pip install mysqlclient
simonw / example-Locations.xml
Last active Jul 21, 2019
Convert Locations.kml (pulled from an iPhone backup) to SQLite
View example-Locations.xml
<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="">
<name>2015-12-18 19:12:32 Source: WhatsApp</name>
You can’t perform that action at this time.