Skip to content

Instantly share code, notes, and snippets.

Tim Sheerman-Chase TimSC

Block or report user

Report or block TimSC

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@TimSC
TimSC / splitquoted.py
Last active Sep 27, 2019
Split a quoted string by delimiter using python
View splitquoted.py
from __future__ import unicode_literals
from __future__ import print_function
def SplitQuoted(inStr, delim=','):
if '"' in delim or '\\' in delim:
raise ValueError("Delimiter not supported")
l = len(inStr)
@TimSC
TimSC / shapelib_example.cpp
Last active Feb 11, 2019
Basic usage of shapelib
View shapelib_example.cpp
//By Tim Sheerman-Chase, released under CC0
//Compile: g++ shapelib_example.cpp -lshp -o shapelib_example
#include <iostream>
#include <vector>
#include <string>
#include "shapefil.h"
using namespace std;
int main(int argc, const char **argv)
@TimSC
TimSC / checkosc.py
Created Nov 10, 2018
Find non existent referenced objects in osm osc change file
View checkosc.py
from pyo5m import OsmData
import requests
if __name__=="__main__":
#
osc = OsmData.OsmChange()
osc.LoadFromOscXml(open("bad_changeset.osc", "rb"))
refNodes, refWays, refRelations = set(), set(), set()
@TimSC
TimSC / pycrocosm-diffs.py
Last active Nov 10, 2018
Download osc diffs using custom pycrocosm api method
View pycrocosm-diffs.py
#Download osc diffs using custom pycrocosm api method
#Released under CC0 license
import requests
import datetime
import os
import gzip
def DownloadDiffs(epoch = datetime.date(2016, 9, 27),
dt=datetime.timedelta(1),
@TimSC
TimSC / syncfsm.py
Last active Sep 23, 2018
Sync freestreetmap replication data
View syncfsm.py
import os
import requests
if __name__=="__main__":
interval = "day"
pth = "/home/tim/replicatefsm"
#Check what already exists
fiList = os.listdir(pth)
@TimSC
TimSC / equalize_histogram.py
Last active Sep 18, 2018
Equalize histogram using numpy/python
View equalize_histogram.py
import numpy as np
def EqualizeHistogram(a, bins):
a = np.array(a)
hist, bins2 = np.histogram(a, bins=bins)
#Compute CDF from histogram
cdf = np.cumsum(hist, dtype=np.float64)
cdf = np.hstack(([0], cdf))
cdf = cdf / cdf[-1]
@TimSC
TimSC / natstats-postcode.py
Created Jun 17, 2018
Filter National Statistics Office Postcode data set
View natstats-postcode.py
import csv
# Filtering file https://data.gov.uk/dataset/7ec10db7-c8f4-4a40-8d82-8921935b4865/national-statistics-postcode-lookup-uk
if __name__=="__main__":
reader = csv.DictReader(open("/home/tim/Downloads/National_Statistics_Postcode_Lookup_UK.csv"))
out = csv.DictWriter(open("natstats-po-postcodes.csv", "wt"), reader.fieldnames)
out.writeheader()
@TimSC
TimSC / codepoint.py
Last active May 13, 2018
OS Codepoint file reader, Released under the CC0 license.
View codepoint.py
#OS Codepoint file reader, by Tim Sheerman-Chase 2018
#Released under the CC0 license.
import zipfile
import csv
import os
import io
#Get Code point open from https://www.ordnancesurvey.co.uk/business-and-government/products/code-point-open.html
def ReadCodePoint(fi, callback):
@TimSC
TimSC / fileserv.py
Last active May 9, 2018
Simple python web server to control access to a single file (GET/PUT)
View fileserv.py
#To write: curl http://localhost:8000/ --upload-file test.xml
#and to read: curl http://localhost:8000/
from __future__ import print_function
from __future__ import unicode_literals
import sys
if sys.version_info[0] >= 3:
import http.server as httpserver
import socketserver
else:
import BaseHTTPServer as httpserver
@TimSC
TimSC / fileexist.php
Created May 5, 2018
File exist testing
View fileexist.php
<?php
$fiLi = glob("/home/tim/Desktop/test/*.pdf");
while(true)
{
$i = array_rand($fiLi);
if(!file_exists($fiLi[$i]))
throw RuntimeError("File said not to exist");
}
You can’t perform that action at this time.