Skip to content

Instantly share code, notes, and snippets.

View missinglink's full-sized avatar

Peter Johnson missinglink

View GitHub Profile
@missinglink
missinglink / geojson-custom-replacer.js
Last active April 22, 2024 23:54
Custom `JSON.stringify` replacer which provides the object path and depth
// decorator
function replacerWithPath (fn) {
let paths = new Map()
return function (key, value) {
let path = paths.get(this) || '$'
if (key) path += Array.isArray(this) ? `[${key}]` : `.${key}`
let v = fn(key, value, path)
if (v === Object(v)) paths.set(v, path)
return v
}
@missinglink
missinglink / canonicalize.js
Last active April 22, 2024 23:35
Output a canonical normalised GeoJSON string which will hash deterministically
const geojson = {
'id': -99,
'type': -6,
'properties': -5,
'geometry': -4,
'coordinates': -3,
'bbox': -2
}
// GeoJSON Feature/Geometry
@missinglink
missinglink / formula-one.js
Last active February 28, 2024 15:21
compute the cartesian product of formula one team/player scores
// copy->paste into the browser console and wait
// note: sorted with the highest points last
const csv = (text) =>
text
.trim()
.split('\n')
.map((r) => {
const c = r.split(',').map((c) => c.trim())
return {
@missinglink
missinglink / conversions.go
Created January 20, 2024 21:51
Convert golang S2 geometries to Simple Features
package spatial
import (
"fmt"
"strconv"
"github.com/golang/geo/s2"
"github.com/peterstace/simplefeatures/geom"
)
@missinglink
missinglink / tcpdump.sh
Last active October 13, 2023 13:22
log all UDP packets starting with a byte sequence
sudo tcpdump -X -v 'udp[8:4] = 0x03050b11'
@missinglink
missinglink / codes.json
Last active September 6, 2023 13:07
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 April 12, 2023 20:29
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.