Skip to content

Instantly share code, notes, and snippets.

View cblanc's full-sized avatar
🐇

Christopher Blanchard cblanc

🐇
View GitHub Profile
@cblanc
cblanc / postcodesio.sh
Created October 22, 2019 10:47
Various commands to run on postcodes.io.db docker container
# Start docker container
docker run -p 5432:5432 -e POSTGRES_USER=postcodesio -e POSTGRES_DB=postcodesiodb -e POSTGRES_PASSWORD=password idealpostcodes/postcodes.io.db
# Generate postcode list
psql -h 0.0.0.0 -p 5432 --username postcodesio postcodesiodb -t -A -F"," -c "SELECT postcode FROM postcodes ORDER BY postcode" > postcodes.csv
import * as fs from "fs";
import * as path from "path";
import * as csv from "fast-csv";
interface NumberScore {
scores: number[];
remainingString: string;
}
const extractNumbers = (input: string): NumberScore => {
@cblanc
cblanc / iso-counties.json
Created June 22, 2020 14:46
GB ISO Codes <-> Postcodes.io
{
"Buckinghamshire": "GB-BKM",
"Cambridgeshire": "GB-CAM",
"Cumbria": "GB-CMA",
"Derbyshire": "GB-DBY",
"Devon": "GB-DEV",
"Dorset": "GB-DOR",
"East Sussex": "GB-ESX",
"Essex": "GB-ESS",
"Gloucestershire": "GB-GLS",
@cblanc
cblanc / cache.ts
Created December 28, 2020 05:59
Autocomplete Cache
import { Client } from "@ideal-postcodes/core-browser";
import { AddressSuggestion, Address } from "@ideal-postcodes/api-typings";
export class ApiCache {
private client: Client;
private cache: Record<string, AddressSuggestion[]>;
private prefix = "!";
constructor(client: Client) {
this.client = client;
@cblanc
cblanc / machine.js
Created January 4, 2021 04:52
Generated by XState Viz: https://xstate.js.org/viz
const INPUT = { INPUT: { actions: "input" } };
const CLOSE = { CLOSE: "closed" };
const SUGGEST = { SUGGEST: "suggesting" };
const NOTIFY = { NOTIFY: "notifying" };
const fetchMachine = Machine({
initial: "closed",
context: {
suggestions: [],
{
"AB13": "Aberdeenshire",
"AB14": "Aberdeenshire",
"AB15": "Aberdeenshire",
"AB21": "Aberdeenshire",
"AB24": "Aberdeenshire",
"AB99": "Aberdeenshire",
"AB30": "Kincardineshire",
"AB31": "Kincardineshire",
"AB32": "Aberdeenshire",