Skip to content

Instantly share code, notes, and snippets.

@TimSC
TimSC / resize-images.py
Last active January 15, 2018 02:24
Resize all images in a folder using python and PIL.
import os, sys
from PIL import Image
if __name__ == "__main__":
fiList = os.listdir(sys.argv[1])
fiList = fiList[:]
fiList.sort()
if len(sys.argv) < 3:
print "Usage: {0} /src/folder /dest/folder [target-size]".format(sys.argv[0])
@TimSC
TimSC / osmgrid.py
Created November 11, 2014 19:21
Draw OS grid squares in OSM format
#!/usr/bin/env python
#Draw OS grid squares in OSM format
from ostn02python.OSGB import *
from ostn02python.OSTN02 import *
pointStore = []
vertLines = {}
out = file("grid.osm", "wt")
@TimSC
TimSC / reset-network.bat
Created November 18, 2014 09:33
Windows network reset script
echo Release current IP address
ipconfig /release
echo Flushes the ARP cache
arp -d *
echo Flush the NetBIOS cache
nbtstat -R
@TimSC
TimSC / read-entire-file.cpp
Last active August 29, 2015 14:10
Read an entire file in C++
#include <string>
#include <fstream>
#include <vector>
int ReadFileContents(const char *filename, int binaryMode, std::string &contentOut)
{
contentOut = "";
std::ios_base::openmode mode = (std::ios_base::openmode)0;
if(binaryMode)
mode ^= std::ios::binary;
@TimSC
TimSC / hextostr.py
Created December 5, 2014 13:54
Convert binary data to hex representation and back
import string
def BinToHex(a):
return "".join(["%02x" % ord(ch) for ch in a])
def HexToBin(a):
out = []
for i in range(0, len(a), 2):
twoChrs = a[i:i+2]
v = string.atoi(twoChrs, 16)
@TimSC
TimSC / diffang.js
Created February 14, 2015 21:03
Difference between two angles
function relativeBearing(b1Rad, b2Rad)
{
b1y = Math.cos(b1Rad);
b1x = Math.sin(b1Rad);
b2y = Math.cos(b2Rad);
b2x = Math.sin(b2Rad);
crossp = b1y * b2x - b2y * b1x;
dotp = b1x * b2x + b1y * b2y;
if(crossp > 0.)
return Math.acos(dotp);
@TimSC
TimSC / ftp-list-files.py
Created May 30, 2015 10:57
Save FTP folder listing to a local file
import os
from ftplib import FTP
if __name__ == "__main__":
ftp = FTP('ftp.debian.org') # connect to host, default port
ftp.login() # user anonymous, passwd anonymous@
ftp.cwd('debian') # change into "debian" directory
outFile = open("out.txt", "wt")
ftp.retrlines('LIST', lambda x: outFile.write(x+os.linesep)) # list directory contents
@TimSC
TimSC / contour+2-calibration.py
Last active August 29, 2015 14:22
Camera calibration for Contour+2 camera
#Contour+2 at 1080, 1920 pixels
#Based on http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_calib3d/py_calibration/py_calibration.html
mtx [[ 1.22124011e+03 0.00000000e+00 9.57305466e+02]
[ 0.00000000e+00 1.26040165e+03 5.16595581e+02]
[ 0.00000000e+00 0.00000000e+00 1.00000000e+00]]
dist [[-0.3890008 0.21574072 0.00787675 -0.00121706 -0.06532239]]
(h, w) (1080, 1920)
newcameramtx [[ 572.20837402 0. 828.30988318]
[ 0. 595.80700684 614.88650663]
@TimSC
TimSC / hack-python-opencv-calibration.py
Last active March 9, 2022 17:10
Hacked python camera calibration in opencv
import numpy as np
import cv2
import glob
import math
# termination criteria
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
shape = (7,5)

deploying web.py with nginx, uwsgi service and linux

It is possible to deploy web.py with nginx using a uWSGI 2.0.11 or later. Note that earlier versions available in the repository (such as 1.9.17) may not work! uWSGI is available via python's pip installer. Nginx natively supports uWSGI since 0.8.40. The following is for python 2.7.

sudo apt-get install python-pip nginx python-webpy python-dev libpcre3-dev zlib1g-dev libssl-dev libjansson-dev
sudo apt-get remove uwsgi uwsgi-core
sudo pip install uwsgi

Create the folders and set ownership: