Skip to content

Instantly share code, notes, and snippets.

@RichardBarrell
RichardBarrell / gist:a33a5dcaa022ba784cf7
Created August 10, 2014 14:51
Watching the PCI registers in /sys/ while switching my 3d card on and off 😸
RichardB@narcissus ~$ od -t x1 /sys/bus/pci/devices/0000:01:00.0/config
0000000 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
*
0000100
RichardB@narcissus ~$ optirun glxgears >/dev/null &
[1] 3758
RichardB@narcissus ~$ sleep 1
RichardB@narcissus ~$ od -t x1 /sys/bus/pci/devices/0000:01:00.0/config
0000000 de 10 92 13 07 00 10 00 a2 00 02 03 00 00 00 00
0000020 00 00 00 f6 0c 00 00 e0 00 00 00 00 0c 00 00 f0
@RichardBarrell
RichardBarrell / gist:941565a570729339240e
Created August 7, 2014 00:26
__reduce__ gets used by pickle and cPickle, when defined by regular Python classes
>>> import pickle
>>> class C(object):
... def __init__(self, banana):
... self.banana = banana
... def __reduce__(self):
... return (C, (self.banana,))
...
>>> pickle.dumps(C(1))
'c__main__\nC\np0\n(I1\ntp1\nRp2\n.'
>>> pickle.loads(pickle.dumps(C(1)))
int hork(int x, int y)
{
return x * (x + y);
}
@RichardBarrell
RichardBarrell / main.c
Created July 9, 2014 00:35
Does calling a function defined like "foo()" differ from calling a function defined like "foo(void)"?
#include <stdio.h>
int foo(FOO_ARGS);
int main(int argc, char **argv) {
printf("%d!\n", foo());
return 0;
}
@RichardBarrell
RichardBarrell / Vagrantfile
Created April 14, 2014 22:40
Typical Lucid Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "lucid64"
config.vm.box_url = "http://files.vagrantup.com/lucid64.box"
config.vm.define :lucid do |t|
end
config.vm.network "forwarded_port", guest: 8080, host: 8080
import thread
import threading
import sys
import dis
import os
done = threading.Semaphore(0)
A = [0]
@RichardBarrell
RichardBarrell / cpath_env.sh
Last active August 29, 2015 13:57
Bourne shell function for adding things to linking, include, etc, paths.
# "cpath_env $DIRECTORY" sets paths appropriately for making gcc+autoconf
# pick up C libraries installed with ./configure --prefix $DIRECTORY.
# example:
# cd /tmp
# tar xf ~/libfoo.tar.gz
# cd libfoo
# ./configure --prefix=$HOME/stuff
# make && make install
@RichardBarrell
RichardBarrell / Vagrantfile
Created January 9, 2014 15:00
bog standard Vagrantfile for working with Lucid
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "lucid64"
config.vm.box_url = "http://files.vagrantup.com/lucid64.box"
config.vm.hostname = "puppet"
config.vm.network :private_network, :ip => "192.168.50.100"
config.vm.provision :shell, :path => bootstrap.sh
end
import inspect
def marmoset_patch(old, new, extra_globals={}):
g = old.func_globals
g.update(extra_globals)
c = inspect.getsource(new)
exec c in g
old.func_code = g[new.__name__].func_code
# Incoming, allow TCP 22, 80, 443 and all ICMP except redirect.
# Outgoing, allow everything.
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
iptables -F
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT