View postal_counties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"AB13": "Aberdeenshire", | |
"AB14": "Aberdeenshire", | |
"AB15": "Aberdeenshire", | |
"AB21": "Aberdeenshire", | |
"AB24": "Aberdeenshire", | |
"AB99": "Aberdeenshire", | |
"AB30": "Kincardineshire", | |
"AB31": "Kincardineshire", | |
"AB32": "Aberdeenshire", |
View machine.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const INPUT = { INPUT: { actions: "input" } }; | |
const CLOSE = { CLOSE: "closed" }; | |
const SUGGEST = { SUGGEST: "suggesting" }; | |
const NOTIFY = { NOTIFY: "notifying" }; | |
const fetchMachine = Machine({ | |
initial: "closed", | |
context: { | |
suggestions: [], |
View cache.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
View iso-counties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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", |
View score_postcodes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => { |
View postcodesio.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
View outcodes.bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker pull idealpostcodes/postcodes.io.db | |
docker run -p 5432:5432 idealpostcodes/postcodes.io.db | |
psql -h 0.0.0.0 --username=postgres postgres -c "COPY (SELECT outcode FROM outcodes ORDER BY outcode) TO STDOUT WITH CSV DELIMITER ','" | pbcopy |
View postcodesio.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# Kindly provided by github/@digdilem | |
my $pc = "TQ13 9XT"; # Example postcode (Dartmoor National Park Visitor's Centre, Haytor) | |
use LWP; | |
use JSON qw( decode_json ); | |
my $ll_url = "https://api.postcodes.io/postcodes/$pc"; |
View extraction.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get raw dataset | |
wget https://s3.amazonaws.com/data.openaddresses.io/runs/554587/no/countrywide.zip | |
unzip countrywide.zip | |
# Extract street and postcode from CSV, get unique elements and stream to file | |
awk -F "\"*,\"*" '{print $4,$9}' countrywide/nl/countrywide.csv | uniq > nl-postcodes.txt |
View callbackify.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const callbackifyPromiseWithTimeout = function(promise, callback) { | |
if (callback) { | |
// Ensure callback is called outside of promise stack. | |
return promise.then(function(res) { | |
setTimeout(function() { callback(null, res) }, 0); | |
}, function(err) { | |
setTimeout(function() { callback(err, null); }, 0); | |
}); | |
} |
NewerOlder