Skip to content

Instantly share code, notes, and snippets.

Avatar
Test-driving things

Per Rovegård provegard

Test-driving things
View GitHub Profile
@provegard
provegard / et_patch.py
Created Nov 21, 2011
ElementTree parsing for non-prefixed attributes with default namespace
View et_patch.py
#!/usr/bin/python
from xml.etree import ElementTree as ET
from cStringIO import StringIO
def parse_attrns(file):
"""Parse file to ElementTree instance. Patch non-prefixed attributes
with the namespace of the element they belong to.
"""
events = ("start", )
@provegard
provegard / listifs.c
Created Nov 24, 2011
Tiny program for listing network interface names and indexes in Linux
View listifs.c
/* Tiny program for listing network interface names and indexes in Linux.
*
* Compile with: gcc -std=c99 -o listifs listifs.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <net/if.h>
int main(int argc, char *argv[])
@provegard
provegard / ssdp-test.py
Created Dec 5, 2011
Small SSDP server/client test in Python
View ssdp-test.py
#!/usr/bin/python
# Python program that can send out M-SEARCH messages using SSDP (in server
# mode), or listen for SSDP messages (in client mode).
import sys
from twisted.internet import reactor, task
from twisted.internet.protocol import DatagramProtocol
SSDP_ADDR = '239.255.255.250'
@provegard
provegard / avahi-test.py
Created Dec 5, 2011
Test program for using Avahi in Python
View avahi-test.py
#!/usr/bin/python
# Test program for using Avahi in Python. Publishes a dummy service.
import sys
import avahi
import dbus
from twisted.internet import reactor
# Service details
@provegard
provegard / lsblkctrl.sh
Created Dec 8, 2011
Lists Linux block devices and for each one the controller it is connected to.
View lsblkctrl.sh
#!/bin/bash
# Lists Linux block devices and for each one the controller
# it is connected to.
set -o pipefail
for i in /sys/block/sd*; do
# Find the path that contains the PCI ID of the controller.
link=$(readlink $i)
@provegard
provegard / build_lambda.sh
Created Dec 15, 2011
Script that downloads and builds defender-prototype and lambda (Project Lambda).
View build_lambda.sh
#!/bin/bash
# Script that downloads and builds defender-prototype and lambda (Project Lambda).
set -e
set -u
function error_exit()
{
echo >&2 $@
@provegard
provegard / getnifs.py
Created Dec 29, 2011
Python script for listing network interfaces with name, index and addresses
View getnifs.py
#!/usr/bin/python
# Based on getifaddrs.py from pydlnadms [http://code.google.com/p/pydlnadms/].
# Only tested on Linux!
from socket import AF_INET, AF_INET6, inet_ntop
from ctypes import (
Structure, Union, POINTER,
pointer, get_errno, cast,
c_ushort, c_byte, c_void_p, c_char_p, c_uint, c_int, c_uint16, c_uint32
@provegard
provegard / rel_unpack.py
Created Jan 1, 2012
Script for unpacking the contents of a release directory
View rel_unpack.py
#!/usr/bin/python -W ignore::DeprecationWarning
"""rel_unpack.py - unpacks the contents of a release directory, optionally
checking SFV check sums prior to unpacking. The script only handles RAR
compressed content, and descends into any CD sub directories as well.
Usage: rel_unpack.py <release directory>
This script relies on the 'unrar' binary being installed. For SFV checking
to take place, the cfv Python module must be present.
@provegard
provegard / ghclone.js
Last active Feb 23, 2017
A Node.js script that clones all non-forked repos and all gists on GitHub for a user.
View ghclone.js
/*
* A Node.js script that clones all non-forked repos and all gists on GitHub
* for a user. If the repos/gists have been cloned already, the script pulls
* new commits from GitHub instead.
*
* Usage:
*
* node ghclone.js -u <user> -p <password> -d <destination dir>
*
* Tested with Node.js version 0.6.7.
@provegard
provegard / Meh.cs
Created Jan 18, 2012
Extension method for calculating the usable client area of a control
View Meh.cs
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
public static class Meh
{
private static readonly IDictionary<DockStyle, Func<Control, Point>> DockAdjusters = new Dictionary<DockStyle, Func<Control, Point>>
{