Skip to content

Instantly share code, notes, and snippets.

View prideout's full-sized avatar
🎯
Focusing

Philip Rideout prideout

🎯
Focusing
View GitHub Profile
@prideout
prideout / gist:2126890
Created March 19, 2012 20:36
generate SVG
from xml.etree import ElementTree as etree
from functools import partial
Circle = partial(etree.Element, 'svg:circle')
c = Circle(cx='100', cy='200', fill='red')
etree.tostring(c)
# <svg:circle cx="100" cy="200" fill="red" />
@prideout
prideout / gist:2429789
Created April 20, 2012 15:41
wolfram alpha stuff
ParametricPlot3D[{(3+cos(v)) * cos(u),(3+cos(v)) * sin(u), sin(v)},{u,0,2pi},{v,0,2pi}]
@prideout
prideout / SimulateMouse.py
Created May 22, 2012 22:45
use libxdo to simulate the mouse
#!/usr/bin/python
from ctypes import *
import time, random
import os
CURRENTWINDOW = 0
# nm -D /usr/lib64/libxdo.so.2 | grep mouselocation
# http://python.net/crew/theller/ctypes/tutorial.html#passing-pointers-or-passing-parameters-by-reference
@prideout
prideout / JSON-validating-formatting
Created May 24, 2012 18:38
one-line JSON validator
python -c "import json,sys; print json.load(sys.stdin)" < input.txt
cat unformatted.json | python -m json.tool > formatted.json
@prideout
prideout / parse-rib-stats.py
Last active December 1, 2015 05:49
dump all files that a RIB touches
# prman -statsfile FOO.xml BAR.rib
from lxml import etree
root = etree.parse('stats.xml').getroot()
print root.xpath("//set[@name='fileLog']/member/text()")
@prideout
prideout / ScopeExit.cpp
Created December 1, 2015 05:52
automatically execute code when the scope ends
template <typename F>
struct ScopeExit {
ScopeExit(F f) : f(f) {}
~ScopeExit() { f(); }
F f;
};
template <typename F>
ScopeExit<F> MakeScopeExit(F f) {
return ScopeExit<F>(f);
@prideout
prideout / togray.py
Created December 2, 2015 22:25
Python script that extracts red from 3 BPP image and saves as 1 BPP image.
from PIL import Image
im = Image.open("color.png")
im.split()[0].save("gray.png")
@prideout
prideout / steal-server.el
Created February 21, 2013 18:54
Steal the emacs server from another session and relabel its frame
(defun steal-server()
(interactive)
(shell-command "emacsclient -e '(set-frame-name \"STOLEN\")'")
(server-force-delete)
(server-start)
(set-frame-name "SERVER")
)
@prideout
prideout / dynamic_array.c
Last active January 16, 2016 18:17
dynamic array of uint16_t in C
#define PAR_CALLOC(T, N) ((T*) calloc(N * sizeof(T), 1))
#define PAR_REALLOC(T, BUF, N) ((T*) realloc(BUF, sizeof(T) * N))
#define PAR_FREE(BUF) free(BUF)
typedef struct {
uint16_t* values;
size_t count;
size_t capacity;
} par__uint16list;
@prideout
prideout / gist:c962b47e5b8e3e4790e0
Created January 19, 2016 04:09
paste-to-console flatbuffers test for Python serialization
cd tests
cat > wombat.fbs <<EOF
namespace Fauna;
struct Foo { x:short; }
table Wombat { foos:[Foo]; }
EOF
../flatc -p wombat.fbs
cat > wombat.py <<EOF
import flatbuffers, binascii
from Fauna import Wombat, Foo