Skip to content

Instantly share code, notes, and snippets.

@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):
@TimSC
TimSC / ucs2.py
Last active January 31, 2018 06:51
Encode to ucs-2 by using utf_16_be then checking for invalid results
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import print_function
import struct
def CheckUcs2BEIsValid(e, big_endian=True):
#UCS-2 is a fixed width encoding. Therefore, check that the
#variable width aspect of UTF-16 is not used.
if big_endian:
struct_code = ">H"
@TimSC
TimSC / minimal_pyside2.py
Last active October 9, 2020 11:16
Minimal pyside2 application
# The code is placed into public domain by anatoly techtonik
# Feel free to copy/paste wherever you like
# Absolutely minimal example of PySide2 application with window
from PySide2 import QtGui, QtWidgets
# Get entrypoint through which we control underlying Qt framework
app = QtWidgets.QApplication([])
@TimSC
TimSC / parseshp.py
Created December 13, 2017 23:41
Write shapefile to WKT text
import os
import shapefile
from shapely.geometry import Polygon
if __name__ == "__main__":
sf = shapefile.Reader("TM_WORLD_BORDERS-0.3.shp")
assert len(sf.shapes()) == len(sf.records())
fieldIndex = {}
@TimSC
TimSC / interpolategpx.py
Created November 22, 2017 01:55
Interpolate missing positions in gpx
import xml.etree.ElementTree as ET
import dateutil.parser
from datetime import timedelta
class Interpolate(object):
def __init__(self, knownWpts):
self.knownWpts = knownWpts[:]
self.knownWpts.sort()
#for wpt in self.knownWpts: