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 /
Last active Sep 27, 2019
Split a quoted string by delimiter using python
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 / 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 /
Created Nov 10, 2018
Find non existent referenced objects in osm osc change file
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 /
Last active Nov 10, 2018
Download osc diffs using custom pycrocosm api method
#Download osc diffs using custom pycrocosm api method
#Released under CC0 license
import requests
import datetime
import os
import gzip
def DownloadDiffs(epoch =, 9, 27),
TimSC /
Last active Sep 23, 2018
Sync freestreetmap replication data
import os
import requests
if __name__=="__main__":
interval = "day"
pth = "/home/tim/replicatefsm"
#Check what already exists
fiList = os.listdir(pth)
TimSC /
Last active Sep 18, 2018
Equalize histogram using numpy/python
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 /
Created Jun 17, 2018
Filter National Statistics Office Postcode data set
import csv
# Filtering file
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)
TimSC /
Last active May 13, 2018
OS Codepoint file reader, Released under the CC0 license.
#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
def ReadCodePoint(fi, callback):
TimSC /
Last active May 9, 2018
Simple python web server to control access to a single file (GET/PUT)
#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
import BaseHTTPServer as httpserver
TimSC / fileexist.php
Created May 5, 2018
File exist testing
View fileexist.php
$fiLi = glob("/home/tim/Desktop/test/*.pdf");
$i = array_rand($fiLi);
throw RuntimeError("File said not to exist");
You can’t perform that action at this time.