Skip to content

Instantly share code, notes, and snippets.

@TimSC
TimSC / pysync.py
Created November 20, 2017 15:59
Invoke rsync using python/cron
#!/usr/bin/env python
import subprocess
import fcntl
import os
if __name__=="__main__":
lockFina = "docslock"
fullLockFina = os.path.join(os.path.dirname(os.path.realpath(__file__)), lockFina)
@TimSC
TimSC / getchangesets.py
Created October 18, 2017 20:49
Download a range of changesets from an OSM map server
import urllib2
import xml.etree.ElementTree as ET
import sys
import time
if __name__=="__main__":
top = ET.Element('osm')
i = 1000000001
running = True
@TimSC
TimSC / dumpmumps.m
Last active September 29, 2017 09:57
Trying to dump Mumps data
dumpusers; Dump users functionality
xmlEscapeApostrophe(string) ; Private ; Escape apostrophe
;
n out,x,c
;
s out=""
f x=1:1:$l(string) d
. s c=$e(string,x)
. i "'"[c s out=out_"'" q
@TimSC
TimSC / moose.py
Created September 9, 2017 18:24
Affine warp to straighen moose
from skimage.transform import PiecewiseAffineTransform, warp
from skimage.io import imread, imshow, imsave
import numpy as np
if __name__=="__main__":
img = imread("IMG_3785.JPG")
pw = PiecewiseAffineTransform()
@TimSC
TimSC / dkkchart.py
Created September 4, 2017 19:01
DGK Color Tools DKK chart
#In LAB colour space, DGK Color Tools DKK chart
img = np.zeros((18, 1, 3))
img[0,0,:] = [100, 0, 0] #White
img[1,0,:] = [73, 0, 0] #Grey 4
img[2,0,:] = [62, 0, 0] #Grey 3
img[3,0,:] = [50, 0, 0] #Grey 2
img[4,0,:] = [38, 0, 0] #Grey 1
img[5,0,:] = [0, 0, 0] #Black
img[6,0,:] = [52, 74, 54] #Red
@TimSC
TimSC / streambuf.i
Created September 1, 2017 06:43
Using std::streambuf from Python SWIG
%inline %{
//Based on http://swig.10945.n7.nabble.com/Using-std-istream-from-Python-tp3733p3735.html
//Add this to your SWIG interface file
class CPyOutbuf : public std::streambuf
{
public:
CPyOutbuf(PyObject* obj) {
m_PyObj = obj;
Py_INCREF(m_PyObj);
m_Write = PyObject_GetAttrString(m_PyObj, "write");
@TimSC
TimSC / vectorvsset.cpp
Created August 31, 2017 15:08
Profiling tests to see if vector or sets are faster at sorting
//g++ -std=c++11 -Wall vectorvsset.cpp -g -pg -o vectorvsset
//https://stackoverflow.com/questions/24968258/which-is-approach-is-faster-vector-inserted-then-sorted-or-set
#include <time.h>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
void GenRandom(vector<int32_t> &original)
@TimSC
TimSC / renamesubstr.py
Created August 11, 2017 10:46
Rename files and folders by replacing substring
import os
if __name__ == "__main__":
fiList = list(os.listdir("."))
for fina in fiList:
print fina
os.rename(fina, fina.replace("3.0", "3.3"))
@TimSC
TimSC / blog-integration.html
Last active August 4, 2017 21:59
Integrate blog feed into static page with javascript
<p>This is a test page - please return to the <a href="https://portsmouth.greenparty.org.uk">home page</a> to continue</p>
<div id="posts">Loading...</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript" src="https://portsmouth.greenparty.org.uk/assets/js/local_parties/portsmouth/wpapi/wpapi.js"></script>
<script type="text/javascript">// <![CDATA[
var wp = new WPAPI({endpoint: 'https://greenpompey.org.uk/shades-of-green/wp-json'});
var blogName = "Shades of Green"
wp.posts().get(function( err, data ) {
@TimSC
TimSC / testggl.cpp
Last active July 26, 2017 19:47
Testing union function of boost::geometry
#include <iostream>
#include <string>
using namespace std;
// boost::geometry
#include <boost/geometry.hpp>
#include <boost/geometry/algorithms/intersection.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
typedef boost::geometry::model::d2::point_xy<double> Point;