Skip to content

Instantly share code, notes, and snippets.

View simonw's full-sized avatar

Simon Willison simonw

View GitHub Profile
@simonw
simonw / a-yubikey-dvorak-karabiner.md
Last active July 22, 2022 17:05
How I got a Yubikey working with a Dvorak keyboard and Karabiner-Elements

How I got a Yubikey working with a Dvorak keyboard and Karabiner-Elements

I needed to set up a new Yubikey device, which plugs into my Mac laptop via USB-C and injects one-time codes by pretending to be a keyboard.

Problem: I use Dvorak... so the Yubikey codes were coming through incorrectly and failing to work.

https://superuser.do/2014/10/22/yubikey-support-for-non-qwerty-keyboard-layouts-on-mac-os-x/ has a recipe for fixing this using Karabiner. But... those instructions are for an older Karabiner which is configured using XML files.

The latest Karabiner - Karabiner-Elements - uses a JSON configuration instead.

@simonw
simonw / Dockerfile
Created October 29, 2018 20:52
Lightweight Dockerfile for running a Python 3 webapp under the Zeit 100MB limit
FROM alpine:edge
RUN apk add --update \
python3 \
python3-dev \
build-base \
&& python3 -m ensurepip \
&& rm -r /usr/lib/python*/ensurepip \
&& pip3 install --upgrade pip setuptools \
&& pip3 install starlette uvicorn \
We can't make this file beautiful and searchable because it's too large.
gbifid datasetkey occurrenceid kingdom phylum class order family genus species infraspecificepithet taxonrank scientificname countrycode locality publishingorgkey decimallatitude decimallongitude coordinateuncertaintyinmeters coordinateprecision elevation elevationaccuracy depth depthaccuracy eventdate day month year taxonkey specieskey basisofrecord institutioncode collectioncode catalognumber recordnumber identifiedby license rightsholder recordedby typestatus establishmentmeans lastinterpreted mediatype issue
1837837577 f93694b5-e994-4c07-a95f-90b14d5cf5e7 urn:catalog:CMNH:Birds:74925 Animalia Chordata Aves Passeriformes Emberizidae Zonotrichia Zonotrichia albicollis SPECIES Zonotrichia albicollis (J.F.Gmelin, 1789) CA Municipal District of Bonnyville, Cold Lake 9c252ec3-7333-4cf8-a997-5441fcbad8dd 54.60115 -110.199233 2016-06-19T00:00:00Z 19 6 2016 5231140 5231140 PRESERVED_SPECIMEN CMNH Birds 74925 CC0_1_0 Andrew W. Jones, Benjamin M. Winger, Courtney L. Brennan NATIVE 2018-07-07T17:06:15.491Z
@simonw
simonw / sqlite_progress.py
Last active January 18, 2021 04:45
Updating SQLite using a custom function and a click-powered progress bar
import click
import sqlite3
import dateparser
count = 0
c = sqlite3.connect("tweets.db")
with click.progressbar(
length=c.execute("select count(*) from tweets").fetchone()[0],
@simonw
simonw / fivethirtyeight-vega.json
Created June 24, 2018 00:51
Vega demo using CSV from fivethirtyeight.datasettes.com
{
"data": {
"url": "https://fivethirtyeight.datasettes.com/fivethirtyeight/twitter-ratio%2Fsenators.csv?_size=max&_sort_desc=replies",
"format": {
"type": "csv"
}
},
"mark": "bar",
"encoding": {
"x": {
@simonw
simonw / vega-view-update.md
Created June 24, 2018 00:21
How to update an existing vega view with new fetched data

How to update an existing vega view with new fetched data

This took quite a bit of figuring out because the web is littered with Vega 2 examples but Vega 3 is a bit different.

https://vega.github.io/vega/docs/api/view/#view_change

var spec = {
  data: {"url": "https://fivethirtyeight.datasettes.com/fivethirtyeight-45d758d/most-common-name%2Fsurnames.json?_shape=array"},
  mark: "bar",
@simonw
simonw / hackable-python-packages.md
Created June 15, 2018 15:03
Installing hackable Python packages

Installing hackable Python packages

This is a handy recipe for installing a Python package in a way that makes it easy to modify locally:

Assuming you have a virtualenv in venv/:

source venv/bin/activate
pip install -e git+git@github.com:simonw/datasette-cluster-map#egg=datasette-cluster-map

This will install code from that GitHub repository in the venv/src/ folder and set it up so changes you make there will be visible to other code in that virtual environment.

@simonw
simonw / rbenv.md
Created June 7, 2018 01:14
Notes on using rbenv to install a gem application without needing root

Notes on using rbenv to install a gem application without needing root

I don't like running sudo gem install X - here's how I installed a gem packaged app without it.

Install rbenv using homebrew

brew install rbenv

Download Ruby 2.5.1 using it

@simonw
simonw / rough-results.md
Created June 4, 2018 21:17
Very rough benchmarking of Sanic v.s. Uvicorn

Really basic load test

I ran Apache Bench like so:

ab -n 1000 -c 100 'http://127.0.0.1:8000/'

uvicorn

Server Software:        uvicorn
Server Hostname: 127.0.0.1