Skip to content

Instantly share code, notes, and snippets.

def hexdump(src, length=16, sep='.'):
FILTER = ''.join([(len(repr(chr(x))) == 3) and chr(x) or sep for x in range(256)])
lines = []
for c in xrange(0, len(src), length):
chars = src[c:c+length]
hex = ' '.join(["%02x" % ord(x) for x in chars])
if len(hex) > 24:
hex = "%s %s" % (hex[:24], hex[24:])
printable = ''.join(["%s" % ((ord(x) <= 127 and FILTER[ord(x)]) or sep) for x in chars])
lines.append("%08x: %-*s |%s|\n" % (c, length*3, hex, printable))
@kogcyc
kogcyc / heroku.sh
Created August 14, 2017 22:45
how to install the heroku cli on raspberry pi
wget https://cli-assets.heroku.com/branches/stable/heroku-linux-arm.tar.gz
mkdir -p /usr/local/lib /usr/local/bin
sudo tar -xvzf heroku-linux-arm.tar.gz -C /usr/local/lib
sudo ln -s /usr/local/lib/heroku/bin/heroku /usr/local/bin/heroku
@kogcyc
kogcyc / mm2inch.py
Last active November 1, 2017 16:44
convert millimeters to inches and fractional eigths of an inch
# if you want to return something other than 1/8ths an inch
# then change the two 8.0s and the 8 to that sometheing else
# or start using millimeters for goodness' sake
from math import ceil,modf
def mm2inch(millimeters):
a = float(millimeters) / 25.4 # mms -> inches
b = modf(a)[0] # 0 is the
@kogcyc
kogcyc / boiler.pov
Last active November 10, 2017 16:01
a boilerplate POVRay scene, Linux variety
//while inotifywait -e close_write boiler.pov ; do povray boiler.pov -H1050 -W1680 +A0.1 -o- > /home/user/background.png ; done
camera {right 16/9*x look_at <0,-10,0> angle 48 location <1,1,-1>*50 }
light_source {<2,1,-0.5>*5000 color rgb 1}
light_source {<1,1,1>*5000 color rgb 1}
background { rgb <1,1,1>*0 }
@kogcyc
kogcyc / addBorder.sh
Created November 24, 2017 00:11
resize a set of animation frame, via Imagemagick, by adding a black border
convert *.png -background black -gravity center -extent 1280x720 -set filename:f '%t' '%[filename:f].jpg'
@kogcyc
kogcyc / vapory.py
Created January 7, 2019 20:06
example of using vapory to run Povray
# vapory depends on numpy
from vapory import *
camera = Camera( 'location', [30,30,-30], 'look_at', [0,0,0] )
light1 = LightSource( [100,100,-200], 'color', [1,1,1] )
light2 = LightSource( [-100,-100,200], 'color', [1,1,1] )
bg = Background('color',[1,1,1])
ll = []
@kogcyc
kogcyc / watch_show_image.py
Last active January 28, 2019 19:39
use Python to display a bitmap when it is modifed (saved)
import os
import time
from PIL import Image
import psutil
filename = './rectangle.png'
modifiedTime = os.stat(filename).st_mtime
while True:
time.sleep(0.1)
checkTime = os.stat(filename).st_mtime
@kogcyc
kogcyc / prism2lathe.py
Created February 6, 2019 22:12
change a PovRAY 'prism' object, which was generated by Inkscape, into a 'lathe' object ( povray prism lathe )
import sys
fo = open(sys.argv[1] + '.pov')
a = fo.read()
fo.close()
b = a.find('prism')
c = a[b:]
d = c.find('}')
e = c[:d+1]
f = e.replace('prism','#declare ' + sys.argv[1] + ' = ' + 'lathe')
g = f.replace(' linear_sweep\n','')
@kogcyc
kogcyc / shimano9spline280.py
Last active March 15, 2019 16:08
a Python bit that creates the shape of the spline for a 'standard' Shimano freehub cassette body
from math import cos,sin,atan,radians
import os
class Pt():
def __init__(self,x=0,y=0):
self.x = x
self.y = y
def rotate(self,about,a,returnInts=False):
ax = about.x
@kogcyc
kogcyc / shimano9spline280.svg
Last active March 15, 2019 22:05
that which is generated by shimano9spline280.py
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.