Skip to content

Instantly share code, notes, and snippets.

View alexras's full-sized avatar

Alex Rasmussen alexras

View GitHub Profile
@alexras
alexras / hp_diagnostic_xml.py
Created June 29, 2012 23:46
Turn invalid XML output from hpacucli into valid XML
#!/usr/bin/env python
from xml.dom.minidom import parse, parseString
import os, sys, argparse, subprocess, uuid, re, time, getpass
def hp_diagnostic_xml(output_filename):
try:
# Run a diagnostic, outputting to a temporary file
@alexras
alexras / striphtml.py
Created June 22, 2012 23:49
Quick-and-dirty HTML tag stripper
#!/usr/bin/env python
from HTMLParser import HTMLParser
import sys, os
class MLStripper(HTMLParser):
def __init__(self):
self.reset()
self.fed = []
def handle_data(self, d):
@alexras
alexras / import.py
Created June 22, 2012 22:02
Script that I used to import my Mendeley library into paper-pile
#!/usr/bin/env python
import yaml, os, sys, subprocess
venue_strings = ["booktitle", "journal", "institution"]
with open(sys.argv[1], 'r') as fp:
collection_yaml = yaml.load(fp.read())
transformed_entries = {}
@alexras
alexras / google-code-table-to-html.el
Created February 16, 2012 02:06
Turn a Google Code table into HTML table rows, and convert any backticks in the table to <code> tags
(defun google-code-table-to-html ()
(interactive)
(save-restriction
(narrow-to-region (region-beginning) (region-end))
(goto-char (region-beginning))
(while (re-search-forward "^||" nil t)
(replace-match "<tr><td>"))
(goto-char (region-beginning))
(while (re-search-forward "||$" nil t)
(replace-match "</td></tr>"))
@alexras
alexras / git_prune_remote.sh
Created December 17, 2011 00:30
Similar to gist:942899, deletes all remote branches that have already been merged into master. It's just a lot more nervous about doing the deletion.
#!/bin/bash
# -*- mode: shell-script -*-
EXPECTED_ARGS=1
if [ $# -ne ${EXPECTED_ARGS} ]
then
echo "Usage: git_prune_remote <remote name>"
exit 2
fi
@alexras
alexras / timed_kill.py
Created December 9, 2011 05:11
Execute a child process, redirecting its output and error to files. If it's not done after a predetermined number of seconds, KILL IT WITH FIRE. Tested on Python 2.4+
#!/usr/bin/env python
"""
Execute a child process, redirecting its output and error to files. If it's not
done after a predetermined number of seconds, KILL IT WITH FIRE
"""
from optparse import OptionParser
import shlex, subprocess, time, os, sys
@alexras
alexras / markupserve-elisp.el
Created November 27, 2011 05:33
Emacs lisp functions for creating attachment directories and attaching files in MarkupServe
(defun markupserve-resource-dir-for-buffer (buffer)
(concat (buffer-file-name buffer) "/../" (file-name-sans-extension
(buffer-name buffer))
".resources"))
(defun markupserve-make-resource-directory ()
(interactive)
(if (buffer-file-name (current-buffer))
(let ((dirname (markupserve-resource-dir-for-buffer (current-buffer))))
(make-directory dirname)
@alexras
alexras / id3tagger.py
Created November 23, 2011 04:17
Quick-and-dirty script for tagging a bunch of MP3s based on title and artist data stored in a text file
#!/usr/bin/env python
import os
with open("names.txt", "r") as fp:
for file_num, line in enumerate(fp):
track_num = file_num + 1
artist, sep, title = line.strip().partition('-')
artist = artist.strip()
@alexras
alexras / count.json
Created October 26, 2011 00:12
Convert lines-of-code information found at https://docs.google.com/spreadsheet/ccc?key=0AszFIYMceP5EdEtQT3l4MlY2Q1Etb0JqWURHU0E3aUE&hl=en_US into something more easily manipulable
{
"emacs-21.3.tar.gz": {
"XML": {
"files": 2,
"comment": 106,
"code": 4262,
"blank": 91
},
"C": {
"files": 181,
@alexras
alexras / ssh-agent-snippets.sh
Created October 17, 2011 00:14
Bash snippets to automatically start and stop an ssh-agent process on login and logout
#!/bin/bash
## in .bash_profile
SSHAGENT=`which ssh-agent`
SSHAGENTARGS="-s"
if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then
eval `$SSHAGENT $SSHAGENTARGS`
trap "kill $SSH_AGENT_PID" 0
fi