Skip to content

Instantly share code, notes, and snippets.

View provegard's full-sized avatar
Test-driving things

Per Rovegård provegard

Test-driving things
View GitHub Profile
@provegard
provegard / ivt490d.py
Created June 20, 2015 21:36
Collect IVT490 readings
#!/usr/bin/env python
#pylint: indent-string=' '
import serial
import daemon
import signal
import lockfile
import time
import getopt
import os
@provegard
provegard / listifs.c
Created November 24, 2011 22:51
Tiny program for listing network interface names and indexes in Linux
/* 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 / lsblkctrl.sh
Created December 8, 2011 20:27
Lists Linux block devices and for each one the controller it is connected to.
#!/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 December 15, 2011 09:58
Script that downloads and builds defender-prototype and lambda (Project Lambda).
#!/bin/bash
# Script that downloads and builds defender-prototype and lambda (Project Lambda).
set -e
set -u
function error_exit()
{
echo >&2 $@
@provegard
provegard / rel_unpack.py
Created January 1, 2012 20:32
Script for unpacking the contents of a release directory
#!/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 / HowToUse_Dll.cpp
Last active December 21, 2015 15:28
MediaInfo buffer usage
/* Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license that can
* be found in the License.html file in the root of the source tree.
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Linux: g++ -o howtouse HowToUse_Dll.cpp -lmediainfo -lzen -ldl
// Windows: cl /Fehowtouse.exe HowToUse_Dll.cpp
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
@provegard
provegard / ghclone.js
Last active February 23, 2017 19:54
A Node.js script that clones all non-forked repos and all gists on GitHub for a user.
/*
* 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 / notify-up.sh
Last active June 17, 2018 09:18
Script for sending sms on server start
#!/bin/bash
set -x
msg="$SERVER has started."
shutdown_dt=$(last -x --time-format iso |grep shutdown | head -n 1 | awk '{print $7}')
if [ -n "$shutdown_dt" ]; then
msg="$msg Shutdown at $shutdown_dt"
fi
@provegard
provegard / notify-up.service
Created June 17, 2018 09:19
Systemd boot service for calling notify-up.sh
[Unit]
Description=Sends SMS to notify about system coming up
After=network.target
[Service]
ExecStart=/usr/local/bin/notify-up.sh
Type=oneshot
[Install]
WantedBy=default.target
@provegard
provegard / et_patch.py
Created November 21, 2011 07:22
ElementTree parsing for non-prefixed attributes with default namespace
#!/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", )