Skip to content

Instantly share code, notes, and snippets.

View nickgarvey's full-sized avatar

Nick Garvey nickgarvey

View GitHub Profile
#!/usr/bin/env python
import cStringIO
import codecs
import csv
import sys
import xlrd
# Taken verbatim from https://docs.python.org/2/library/csv.html#examples
class UnicodeWriter:
"""
library('ggplot2')
library('reshape2')
setwd('eda/problem_sets/ps3/gapminder')
aid <- melt(t(read.csv('aid_per_person.csv', header=TRUE, row.names = 1)))
aid["Var1"] <- gsub("[.]0", "", aid["Var1"])
head(aid)
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 49 columns, instead of 48 in line 1.
ODA aid per person (constant 2007 US$),1960.0,1961.0,1962.0,1963.0,1964.0,1965.0,1966.0,1967.0,1968.0,1969.0,1970.0,1971.0,1972.0,1973.0,1974.0,1975.0,1976.0,1977.0,1978.0,1979.0,1980.0,1981.0,1982.0,1983.0,1984.0,1985.0,1986.0,1987.0,1988.0,1989.0,1990.0,1991.0,1992.0,1993.0,1994.0,1995.0,1996.0,1997.0,1998.0,1999.0,2000.0,2001.0,2002.0,2003.0,2004.0,2005.0,2006.0,2007.0
Australia,51.6556420233,60.1455756422,61.2196261682,75.6141154904,75.3201438849,85.2751322751,89.8965517241,104.065254237,98.0799333888,106.996737357,113.535571543,102.003060444,115.469924812,90.7675795707,107.735422741,130.223182145,83.8496079829,88.3516560958,114.937325905,113.690082645,106.5,91.9839142091,124.390645586,108.526315789,107.087291399,121.653578214,118.546816479,86.0301353014,122.019358742,102.224271267,91.1013473931,96.7743055556,96.6651428571,95.9541595925,100.131019037,105.126729386,86.4391043146,87.7294816415,92.5648691938,90.4694415174,95.9344773791,90.3150333504,94.1338100102,93.0990945674,93.3903530582,98.6227250369,119
> head(aid)
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 52 columns, instead of 37 in line 4.
Aid received % of GNI,1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010
Abkhazia,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Afghanistan,3.12995974125,6.191071177,3.03525880936,4.78304322982,5.66117162264,5.25292201971,3.52441683836,2.37581275173,2.08526154892,1.89528598758,1.54726028877,2.3778863167,3.38297453444,3.15903774304,2.23319878333,2.87247242647,2.73561696773,2.83685574489,2.44785766744,2.79335695786,0.855900528846,0.64507681999,,,,,,,,,,,,,,,,,,,,,32.0639872753,34.7809137317,43.6797551715,45.1830588651,41.7115881073,56.7412273682,45.6284529742,50.8536673511,40.8676693215
Akrotiri and Dhekelia,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Albania,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0.261499388581,0.442821812847,0.526259401136,29.7055837448,60.1823174808,22.2585627193,8.19320964943,7.31737274104
@nickgarvey
nickgarvey / gist:8229874
Created January 3, 2014 00:08
Go from a dom_id to an IP address for a libvirt domain
import libvirt
from xml.dom import minidom
DNSMASQ_LEASES = "/var/lib/libvirt/dnsmasq/default.leases"
def dom_id_to_ip(dom_id):
conn = libvirt.openReadOnly('qemu:///system')
dom = conn.lookupByID(dom_id)
output = dom.XMLDesc(0)
import libvirt
import xml.etree.ElementTree as ET
def findDomainWithMac(conn, addr):
domlist = map(conn.lookupByID, conn.listDomainsID())
for dom in domlist:
root = ET.fromstring(dom.XMLDesc(0))
searchString = "./devices/interface/mac[@address='{0}']".format(addr)
if (root.find(searchString) is not None):
return dom
/*
* Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it would be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of