Skip to content

Instantly share code, notes, and snippets.

View jrha's full-sized avatar

James Adams jrha

  • Rutherford Appleton Laboratory, Harwell, UK
View GitHub Profile
@jrha
jrha / changex.sh
Created March 7, 2013 08:20
Find and group differences between two XML trees.
#!/bin/bash
if [[ -f "/usr/bin/shasum" ]]; then
SHASUM='/usr/bin/shasum'
else SHASUM='/usr/bin/sha1sum'
fi
if [[ -n "$XML1" ]] && [[ -n "$XML2" ]] && [[ "$XML1" != "$XML2" ]]; then
profiles=$(diff $XML1 $XML2 --brief | grep -v '\.dep' | grep -v '\.json\.gz' | grep -v profiles-info.xml | grep -v "Only in" | awk '{ print $2 }' | sed "s/^.*\///g")
@jrha
jrha / panc-expressive.py
Last active December 17, 2015 11:09
Wrapper for pan ant tasks to generate more expressive error messages
#!/usr/bin/python2 -u
from sys import stdin, stdout
from re import compile
RE_ERROR = compile(r'\[panc\]([\w\s]+)\[(/.+):(\d+).(\d+)-(\d+).(\d+)\]')
RE_INFO = compile(r'\[panc\](.+)')
def caretline(pos, pre = 0, post = 0):
@jrha
jrha / gtr-example.py
Last active December 20, 2015 18:08
Example of using Gateway To Research JSON API
import json
import urllib2
# Get org data = http://gtr.rcuk.ac.uk/organisation/2512EF1C-401B-4222-9869-A770D4C5FAC7.json
# Get project data = http://gtr.rcuk.ac.uk/search/project.json?term=mouse
f = urllib2.urlopen('http://gtr.rcuk.ac.uk/search/project.json?term=mouse')
data = json.load(f)
f.close()
@jrha
jrha / searchprofile
Last active December 22, 2015 05:19
Use dep files to search the source files of a compiled panc object.
#!/bin/bash
if [[ "$#" -eq 2 ]]; then
if [[ "$1" == *.dep ]]; then
awk '! /ABSENT_SOURCE/ {sub("^[^:]*:", "", $3); print $3$1($2!="TEXT"?"."tolower($2):"")}' $1 | xargs grep $2
else
echo "DEP_FILE must be a pan dependency file"
fi
else
echo "Usage: searchprofile DEP_FILE NEEDLE"
@jrha
jrha / quattor_report_stats.py
Last active December 29, 2015 10:49
Quattor Report Stats
#!/usr/bin/env python2
"""Gather and submit some operating data about a Quattor server"""
import os
import platform
import urllib
import ConfigParser
import argparse
from datetime import date
@jrha
jrha / aqssh
Created May 16, 2014 10:22
ClusterSSH into all nodes with a particular personality in Aquilon
#!/bin/bash
if [[ $# -eq 1 ]]; then
hosts=$(curl -s http://aquilon.example.com:6901/find/host?personality=$1)
if [[ $hosts ]]; then
cssh -l root $hosts
else
echo "ERROR: No hosts found with personality $1"
fi
else
@jrha
jrha / beamercolorthemequattor.sty
Created May 20, 2014 16:54
Quattor Colour Scheme for Beamer
% Copyright 2004 by Madhusudan Singh <madhusudan.singh@gmail.com>
% Copyright 2014 by James Adams <james.adams@stfc.ac.uk>
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/licenses/LICENSE for more details.
@jrha
jrha / htcondor-history.conf
Created May 22, 2014 09:58
Logstash Configuration for HTCondor Job History Logs
input {
file {
path => "/var/lib/condor/spool/history"
sincedb_path => "/opt/logstash/sincedb"
start_position => "beginning"
}
}
filter {
multiline {
@jrha
jrha / aq.py
Created June 6, 2014 10:17
Kerberised CGI Wrapper for Aquilon
#!/bin/env python2
import cgi
import socket
import time
from os import environ
KNC_SOCKET_PATH = '/var/quattor/run/sockets/kncsock'
def recv_timeout(the_socket,timeout=2):
@jrha
jrha / flattendict.py
Last active August 29, 2015 14:04
Flatten a dictionary tree into a list of paths
def gen(d, pfx=()):
return (
x for k, v in d.iteritems()
for x in (
gen(v, pfx+(k,)) if isinstance(v, dict) else ((pfx+(k,), v),)
)
)
def flattendict(tree):
paths = []