Skip to content

Instantly share code, notes, and snippets.

View simonw's full-sized avatar

Simon Willison simonw

View GitHub Profile
@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 / 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 / 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 / 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 / configuring_cors_s3.md
Last active June 29, 2021 08:03
Configuring CORS on Amazon S3 for direct image upload from JavaScript
@simonw
simonw / how-to-upgrade-heroku-postgresql.md
Last active May 30, 2025 04:49
How to upgrade a Heroku PostgreSQL database to a new plan

How to upgrade a Heroku PostgreSQL database to a new plan

I started a project on a Hobby Dev plan (free, limit 10,000 rows), and then later needed to upgrade it to Hobby Basic ($9/month, limit 10,000,000 rows).

After assigning the new database, I had two databases attached to the application. They looked something like this:

  • HEROKU_POSTGRESQL_OLIVE (postgresql-dimensional-3321) Old, free-tier (Hobby Dev) database
@simonw
simonw / all-the-trees.vl.json
Created March 28, 2018 18:35
Vega-Lite to visualize all the SF trees
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.1.json",
"width": 700,
"height": 800,
"data": {
"url": "http://127.0.0.1:8009/sf-trees-02c8ef1.jsono?sql=select+latitude%2C+longitude%2C+qSpecies.value as species+from+Street_Tree_List join qSpecies on qSpecies.id = Street_Tree_List.qSpecies+where+latitude+is+not+null and latitude > 37.7",
"format": {
"type": "json",
"property": "rows"
}
@simonw
simonw / trees-san-francisco.vl.json
Created March 27, 2018 22:38
Vega-lite visualization of the trees in one corner of San Francisco
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.1.json",
"width": 700,
"height": 800,
"data": {
"url": "https://san-francisco.datasettes.com/sf-trees-ebc2ad9.jsono?sql=select+latitude%2C+longitude%2C+qSpecies+from+Street_Tree_List+where+latitude+is+not+null and Latitude > 37.77 and Longitude < -122.45",
"format": {
"type": "json",
"property": "rows"
}
@simonw
simonw / population-gender.vl.json
Created March 26, 2018 17:53
Population by birth gender over time - based on example from https://vega.github.io/vega-lite/docs/stack.html#normalized
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"vconcat": [
{
"width": 600,
"height": 300,
"mark": "bar",
"data": {
"url": "data/population.json",
"format": {
@simonw
simonw / seattle-weather.vl.json
Created March 26, 2018 15:10
Some combined Seattle weather graphs - from following https://vega.github.io/vega-lite/tutorials/explore.html
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"data": {
"url": "data/seattle-weather.csv",
"format": {
"type": "csv"
}
},
"vconcat": [
{