Skip to content

Instantly share code, notes, and snippets.

View simonw's full-sized avatar

Simon Willison simonw

View GitHub Profile
@simonw
simonw / configuring_cors_s3.md
Last active June 29, 2021 08:03
Configuring CORS on Amazon S3 for direct image upload from JavaScript
@simonw
simonw / washington-post-school-shootings-datasette.md
Last active April 21, 2018 05:03
How I created a Datasette instance for the Washington Post school shootings database

Here's the Datasette instance: https://washington-post-school-shootings.now.sh - using data from https://github.com/washingtonpost/data-school-shootings

$ wget https://raw.githubusercontent.com/washingtonpost/data-school-shootings/master/school-shootings-data.csv

I manually edited the first line of the CSV file, renaming the lat column to latitude and the long column to longitude. This is needed to get the datasette-cluster-map plugin to work correctly.

Then I created the SQLite database using csvs-to-sqlite, specifing specific fields that should be added to a full-text search index:

$ csvs-to-sqlite school-shootings-data.csv school-shootings-data.db \

-f school_name -f district_name -f city -f state -f county

@simonw
simonw / awesomplete-ajax.html
Created April 27, 2018 06:47
Awesomplete ajax example.
<link rel="stylesheet" href="http://leaverou.github.io/awesomplete/awesomplete.css">
<script src="http://leaverou.github.io/awesomplete/awesomplete.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
const input = document.querySelector('input.blah');
const awesomplete = new Awesomplete(input);
input.addEventListener("awesomplete-selectcomplete", (ev) => console.log(ev.text));
input.addEventListener('keyup', (e) => {
var code = (e.keyCode || e.which);
if (code === 37 || code === 38 || code === 39 || code === 40 || code === 27 || code === 13) {
@simonw
simonw / git_json_to_sqlite.py
Created May 17, 2018 23:05
Script for converting the output of https://github.com/tarmstrong/git2json to SQLite
import json
import os
import sqlite3
def init_db(filename):
if os.path.exists(filename):
return
conn = sqlite3.connect(filename)
@simonw
simonw / installing-presto-cli.md
Created May 29, 2018 18:16
Installing the Presto command-line tool

Installing the Presto command-line tool

I had to install Java to get presto working

brew cask install java

From https://prestodb.io/docs/current/installation/cli.html I did:

wget https://repo1.maven.org/maven2/com/facebook/presto/presto-cli/0.202/presto-cli-0.202-executable.jar

mv presto-cli-0.202-executable.jar presto

@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
@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 / 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 / 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 / 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": {