Skip to content

Instantly share code, notes, and snippets.

@TimSC
TimSC / equalize_histogram.py
Last active April 10, 2020 21:34
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
TimSC / natstats-postcode.py
Created June 17, 2018 07:46
Filter National Statistics Office Postcode data set
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 12:46
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 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 09:57
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
else:
import BaseHTTPServer as httpserver
@TimSC
TimSC / fileexist.php
Created May 5, 2018 03:54
File exist testing
<?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");
}
@TimSC
TimSC / seamless.py
Created March 16, 2018 03:53
Funky seamless texture generator
#Funky seamless texture generator
#By Tim Sheerman-Chase (c) 2018
#Released under CC0 license
from __future__ import print_function
from PIL import Image
import argparse
if __name__=="__main__":
@TimSC
TimSC / msgpack-rpc-server.cpp
Last active March 8, 2018 08:17
Simple msgpack-rpc server, based on Boost ASIO
//simple msgpack-rpc server, based on Boost ASIO
//Based on http://www.boost.org/doc/libs/1_35_0/doc/html/boost_asio/tutorial/tutdaytime3/src.html
//msgpack-rpc based on https://github.com/msgpack-rpc/msgpack-rpc/blob/master/spec.md
//Build with: g++ -std=c++11 server.cpp -lboost_system -o server
#include <iostream>
#include <string>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
@TimSC
TimSC / average_image.py
Created February 21, 2018 20:44
Calculate average image in python
from __future__ import print_function
import os
from scipy.misc import imread, imsave
import numpy as np
if __name__=="__main__":
total = None
fiLi = os.listdir(".")
@TimSC
TimSC / opencart_user_api.php
Last active November 28, 2022 14:06
Example for using opencart user API
<?php
// User API usage in OpenCart 3.0.2.0
// http://sv2109.com/en/article/opencart-api-system
// Patches from https://forum.opencart.com/viewtopic.php?t=186063 need to be applied to 3.0.2.0
$apiKey = "foobar34y3yl34myl3erwhyl34yl3k4ynpwgen"; //Whatever you put in System -> Users -> API
@TimSC
TimSC / osmbbox.py
Last active February 12, 2018 10:35
Test OSM bbox functionality
from __future__ import print_function
import sys
import requests
from requests.auth import HTTPBasicAuth
import xml.etree.ElementTree as ET
PY3 = sys.version_info > (3, 0)
if PY3:
raw_input = input
def GetChangesetBbox(cid):