Skip to content

Instantly share code, notes, and snippets.

View craigpatten's full-sized avatar

Craig Patten craigpatten

View GitHub Profile
@craigpatten
craigpatten / metadata.xml
Last active August 29, 2015 14:11
ANDS DOI generation - minimal example
<?xml version="1.0" encoding="UTF-8"?>
<resource xsi:schemaLocation="http://datacite.org/schema/kernel-3 http://schema.datacite.org/meta/kernel-3/metadata.xsd" xmlns="http://datacite.org/schema/kernel-3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<identifier identifierType="DOI">filler</identifier>
<creators>
<creator>
<creatorName>Researcher</creatorName>
</creator>
<creator>
<creatorName>Another Researcher</creatorName>
</creator>
@craigpatten
craigpatten / sonicjson.py
Created December 4, 2014 04:25
SonicWALL export → JSON
#!/usr/bin/python
import base64, json, sys
if len(sys.argv) != 2:
print "args: sonicwall-export-file.exp"
exit(1)
with open(sys.argv[1], "r") as f:
data = base64.b64decode(f.read()).split("&")
@craigpatten
craigpatten / host.py
Created November 18, 2014 01:41
Visualising VM-hypervisor mappings on NeCTAR/OpenStack
#!/usr/bin/env python
import json, os
from novaclient.v1_1 import client
auth_url = "https://keystone.rc.nectar.org.au:5000/v2.0/"
nectar = client.Client(username = os.environ["OS_USERNAME"], api_key = os.environ["OS_PASSWORD"], project_id = os.environ["OS_TENANT_NAME"], auth_url = auth_url)
@craigpatten
craigpatten / boot.py
Created November 7, 2014 05:55
NeCTAR VM boot script
#!/usr/bin/env python
import sys, os, time, socket, argparse, random, urllib2
from novaclient.v1_1 import client
default_image = urllib2.urlopen("https://swift.rc.nectar.org.au:8888/v1/AUTH_6f3b184bcf194672a55d258620e732db/deploy/nectar-zfs-image").read().strip()
default_setup_script = None
default_security_group = "default"
default_auth_url = "https://keystone.rc.nectar.org.au:5000/v2.0/"
@craigpatten
craigpatten / Wrap.java
Created October 19, 2014 12:47
Exception wrappers aimed for use with Java 8 lambdas.
import java.util.concurrent.Callable;
import javax.ws.rs.WebApplicationException;
public class Wrap {
public static <T> T webApplicationException(Callable<T> callable) {
try {
return callable.call();
} catch (Exception e) { throw new WebApplicationException(e); }
}
@craigpatten
craigpatten / scale.html
Last active August 29, 2015 14:06
markdown image scaling example: kramdown scale.md > scale.html
<h3 id="image-scaling-example">image scaling example</h3>
<p><img src="https://www.ersa.edu.au/sites/default/files/danland_logo.png" alt="ersa logo" style="max-width: 200px; height: auto;" /></p>
@craigpatten
craigpatten / pingdom-probe-servers.py
Created July 7, 2014 00:56
pingdom-probe-servers.py
#!/usr/bin/python
import urllib, xml.etree.ElementTree as et
ns = { "pingdom" : "http://www.pingdom.com/ns/PingdomRSSNamespace" }
rss = et.fromstring(urllib.urlopen("https://www.pingdom.com/rss/probe_servers.xml").read())
for ip in rss.iterfind("channel/item/pingdom:ip", namespaces = ns):
print ip.text
@craigpatten
craigpatten / iolog.py
Last active August 29, 2015 14:03
I/O logging
#!/usr/bin/python
import subprocess, time, re
devices = [ "vda", "vdb" ]
space = re.compile(" +")
cmd = [ "iostat", "-dky" ]
cmd.extend(devices)
cmd.append("1")
@craigpatten
craigpatten / ssh-auth-probe.py
Created June 23, 2014 05:39
ssh-auth-probe.py
#!/usr/bin/python
import sys, socket, paramiko
if len(sys.argv) < 2:
print "args: host ..."
exit(1)
for host in sys.argv[1:]:
s = socket.socket()
def prettify(x):
return json.dumps(x, sort_keys = True, indent = 2, separators = (",", ": "))