Skip to content

Instantly share code, notes, and snippets.

@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;
@TimSC
TimSC / pitch.py
Created July 11, 2017 12:58
Analyse pitch in gpx file
import math
import xml.etree.ElementTree as ET
import matplotlib.pyplot as plt
from pyo5m import OsmData
if __name__=="__main__":
tree = ET.parse("/home/tim/Desktop/CampingMapping/20170709.gpx")
root = tree.getroot()
prevPos = None
@TimSC
TimSC / opencv-compile-deb-notes.txt
Last active April 14, 2017 19:03
Notes on compiling OpenCV on Ubunut/Mint
http://unix.stackexchange.com/questions/46122/how-can-i-create-a-deb-package-with-my-compiled-opencv-build
Inspired by https://launchpad.net/~sbadia/+archive/ubuntu/opencv
Interesting: https://github.com/sbadia/opencv-deb
In CMakeCache.txt
//Enable to build Debian packages
CPACK_BINARY_DEB:BOOL=ON
@TimSC
TimSC / nthfile.py
Created March 31, 2017 21:21
Extract every nth file
import sys
import os
import shutil
if __name__ == "__main__":
if len(sys.argv) < 4:
print ("Usage: {} src_folder dst_folder ith_frame".format(sys.argv[0]))
exit(0)
ithFrame = int(sys.argv[3])
@TimSC
TimSC / resizepics.py
Last active April 7, 2018 11:42
Resize a folder of pictures using exiftool
#sudo apt install libimage-exiftool-perl
from __future__ import print_function
from PIL import Image
import sys
import os
if __name__ == "__main__":
if len(sys.argv) < 4:
print ("Usage: {} src_folder dst_folder target_size".format(sys.argv[0]))
exit(0)
@TimSC
TimSC / masshash.py
Last active March 24, 2017 18:18
Hash files under working folder recursively for hard drive read test.
#Hash files under working folder recursively
#for hard drive read test.
#Released as CC0
from __future__ import print_function
import hashlib
import os
import time
if __name__=="__main__":
while True:
@TimSC
TimSC / quicksort.h
Last active March 7, 2017 08:55
Quicksort in C++ with templates
//By Tim Sheerman-Chase, 2017
//This code may be used under the CC0 license.
#ifndef QUICKSORT_H
#define QUICKSORT_H
#include <iostream>
#include <vector>
#include <cstdlib>
#include <time.h>