Skip to content

Instantly share code, notes, and snippets.

View alexras's full-sized avatar

Alex Rasmussen alexras

View GitHub Profile
@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 / 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 / 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 / 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 / drop_caches.c
Created July 3, 2012 20:28
Tell the kernel to drop the page cache
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char **argv) {
sync();
int fd = open("/proc/sys/vm/drop_caches", O_WRONLY);
@alexras
alexras / breaks.tex
Created September 23, 2012 01:46
Fix URL breaks in LaTeX
% Allow breaking at both hyphens and spaces
\usepackage[hyphens,spaces]{url}
% A sequence of BigBreaks will be treated as one break, so it will only be able to break after ://
\renewcommand{\UrlBigBreaks}{\do\:\do\/}
% (Less aggressive) Treat both / and - as breakable characters (don't know why this does something different than hyphens in the package declaration, but it does)
\renewcommand{\UrlBreaks}{\do\/\do\-}
% (More aggressive) Any letter and / are treated as breakable characters
@alexras
alexras / img_resize.py
Last active May 5, 2024 12:58
Nearest-neighbor image scaling with PIL
#!/usr/bin/env python
from PIL import Image
import sys
im = Image.open(sys.argv[1])
def scale_to_width(dimensions, width):
height = (width * dimensions[1]) / dimensions[0]
@alexras
alexras / sfq.sh
Created April 21, 2013 05:44
Turn Stochastic Fairness Queueing on or off for a given interface
#!/bin/bash
if [ $# -ne 2 ]
then
echo "Usage: sfq.sh <enable|disable> <device>"
exit 1
fi
COMMAND=$1
DEVICE=$2
@alexras
alexras / gist:6979932
Last active December 25, 2015 12:59
Applying Google Search's autocomplete feature to "the three [a-z]'s" returned the following:
the three a's of awesome
the three a's of marriage
the three a's in a relationship
the three b's of baseball
the three c's of life
the three c's of a relationship
the three e's of sustainable development
the three e's of fire prevention
the three e's of leadership
the three f's of life
#!/bin/bash
set -e
libs=( "/usr/local/lib/libmacfuse_i32.2.dylib" \
"/usr/local/lib/libosxfuse_i32.2.dylib" \
"/usr/local/lib/libosxfuse_i64.2.dylib" \
"/usr/local/lib/libmacfuse_i64.2.dylib" \
"/usr/local/lib/libosxfuse_i32.la" \
"/usr/local/lib/libosxfuse_i64.la" \