Skip to content

Instantly share code, notes, and snippets.

View missinglink's full-sized avatar

Peter Johnson missinglink

View GitHub Profile
@missinglink
missinglink / codes.json
Last active June 12, 2025 00:43
ISO 3166 Country Code to ISO 639 'Official Language Codes' for each country
{
"AD": "ca",
"AE": "ar-AE,fa,en,hi,ur",
"AF": "fa-AF,ps,uz-AF,tk",
"AG": "en-AG",
"AI": "en-AI",
"AL": "sq,el",
"AM": "hy",
"AN": "nl-AN,en,es",
"AO": "pt-AO",
@missinglink
missinglink / javascript-trailing-zero-bits.js
Last active May 1, 2024 00:35
Javascript trailing zero bits
class Bitwise {
static trailingZeros8(b) {
let lsb = (b & -b)
if(lsb === 0) { return 8 }
return 31 - Math.clz32(lsb)
}
static trailingZeros64(a) {
for(let i=7; i>=0; i--) {
let z = Bitwise.trailingZeros8(a[i])
if(z < 8) { return ((7-i) * 8) + z }
@missinglink
missinglink / configure.js
Last active December 13, 2022 22:57
Generate Osmium configurations and a runnable shell script to recursively cut the OSM planet file down to produce regional extracts
const fs = require('fs')
const path = require('path')
const fetch = require('node-fetch') // npm i node-fetch@2
// Usage: node configure.js planet-v1.20.osm.pbf daylight
// A file named 'extract.sh' will be generated along with the `./configs` and `./extracts` directories
// first argument is the input .pbf file
const inputFile = process.argv[2]
if (!fs.existsSync(inputFile)) { throw new Error('input file not found') }
@missinglink
missinglink / geonames.hsts.tsv
Created November 9, 2021 14:53
extract of the HSTS features from geonames
We can't make this file beautiful and searchable because it's too large.
3041129 Sant Vicenç d’Enclar Sant Vicenc d'Enclar Castell de Sant Vicenc,Castell de Sant Vicens,Castell de Sant Vicenç,Sant Vicenc d'Enclar,Sant Vicenç d’Enclar 42.49571 1.49372 S HSTS AD 07 0 1184 Europe/Andorra 2020-06-10
8225419 Qaşr aḑ Ḑiyāfah Qasr ad Diyafah H.H. The Ruler's Guesthouse,H.H. The Ruler’s Guesthouse,Qasr ad Diyafah,Qaşr aḑ Ḑiyāfah,qsr aldyaft,قصر الضيافة 25.2412 55.26796 S HSTS AE 03 0 6 Asia/Dubai 2012-04-06
8469451 Bayt ash Shaykh ‘Ubayd Bin Thānī Bayt ash Shaykh `Ubayd Bin Thani Bayt ash Shaykh `Ubayd Bin Thani,Bayt ash Shaykh ‘Ubayd Bin Thānī,House of Sheikh Obaid Bin Thani,byt alshykh ʿbyd bn thany,بيت الشيخ عبيد بن ثاني 25.26859 55.29059 S HSTS AE 03 0 4 Asia/Dubai 2020-06-12
8469455 Murabba‘at ash Shindaghah Murabba`at ash Shindaghah Al-Shindagha Square Fort,Murabba`at ash Shindaghah,Murabba‘at ash Shindaghah,mrbʿt alshndght,مربعة الشندغة 25.26525 55.29031 S HSTS AE 03 0 4 Asia/Dubai 2020-06-12
8469463 Al Burj al Gharbī Al Burj al Gharbi Al Burj al Gharbi,Al Burj
@missinglink
missinglink / brunswick-street.geojson
Last active September 30, 2023 22:06
Brunswick Street extract from AUS G-NAF data
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@missinglink
missinglink / gnaf-sqlite.sh
Last active October 21, 2021 08:56
generate a SQLite import script for the AUS G-NAF dataset
#!/bin/bash
# ref: https://github.com/data61/gnaf/blob/master/gnaf-db/src/main/script/createGnafDb.sh
# input dir
DATA_DIR="/data/gnaf/G-NAF/G-NAF AUGUST 2021"
EXTRAS_DIR="/data/gnaf/G-NAF/Extras"
# fast import pragmas
echo '.output /dev/null'
echo 'PRAGMA main.foreign_keys=OFF;'
@missinglink
missinglink / errors.txt
Created September 29, 2021 17:57
whosonfirst geometry validation errors 29/10/2021
85632505|meso|0|Self-intersection[-69.31 -28.27]|POINT(-69.31 -28.27)
85632793|quattroshapes-reversegeo|-1||
85632793|quattroshapes|-1||
85681583||0|Self-intersection[144.652483533911 -40.3811760786903]|POINT(144.652484 -40.381176)
85770383|quattroshapes|0|Ring Self-intersection[147.317205739621 -42.9812372030377]|POINT(147.317206 -42.981237)
85775753|quattroshapes|0|Ring Self-intersection[150.501708984 -23.3725138223999]|POINT(150.501709 -23.372514)
85781949|quattroshapes|0|Ring Self-intersection[117.927246094 -35.0344943317]|POINT(117.927246 -35.034494)
85632475|meso|0|Self-intersection[88.906686 22.921783]|POINT(88.906686 22.921783)
85801287|quattroshapes|0|Ring Self-intersection[4.47143554686997 50.8891740489]|POINT(4.471436 50.889174)
85929283|quattroshapes|0|Ring Self-intersection[23.3294677734 42.6622413763001]|POINT(23.329468 42.662241)
@missinglink
missinglink / Install-darwin-brew-s2geometry.txt
Last active September 8, 2021 22:08
install s2geometry (c++ libs) on mac with brew / plus hello world s2geometry example
# based on: https://s2geometry.io/about/platforms
# note: set -DOPENSSL_ROOT_DIR instead of -DOPENSSL_INCLUDE_DIR
brew install gflags glog openssl
brew install cmake
# Download Googletest release 1.8.0 and unpack it in a directory of your choosing.
# (Take note of this directory as you will need to point CMake to it.)
# https://github.com/google/googletest/releases/tag/release-1.8.0
@missinglink
missinglink / featureCollectionSandwich.sh
Last active March 3, 2020 10:32
Convert a stream of geojson features to a feature collection
#!/bin/bash
featureCollectionSandwich() {
echo '{ "type": "FeatureCollection", "features":'
cat - | jq -s .
echo '}'
}
@missinglink
missinglink / timeseries.js
Created January 29, 2020 12:44
functions for computing time windows for data series
const interval = {
millisecond: 1,
second: 1000,
minute: 1000 * 60,
hour: 1000 * 60 * 60,
day: 1000 * 60 * 60 * 24
}
const period = 'day'
const d1 = truncate(new Date('2020-01-01 22:22:22'), period)