Skip to content

Instantly share code, notes, and snippets.

View alexras's full-sized avatar

Alex Rasmussen alexras

View GitHub Profile
@alexras
alexras / tail-demux.py
Last active May 10, 2016 21:02
Demultiplex the output of `tail -f *.log`
#!/usr/bin/env python
import argparse
import re
import os
import sys
file_delimiter_regex = re.compile('.*?\=\=\> (.*?) \<\=\=\n')
@alexras
alexras / find-diskdoubler-archives.py
Last active December 29, 2015 21:05
Find all files with a resource fork that begin with the magic number 'DDA2'; these are DiskDoubler archives
#!/usr/bin/env python
import os
import subprocess
DIRS_TO_SKIP = ['.fseventsd', '.Spotlight-V100']
for (dirpath, dirnames, filenames) in os.walk(os.getcwd()):
should_skip = False
@alexras
alexras / requirements.txt
Created May 4, 2015 07:24
Convert @jvns' strace zine into a standard PDF
PyPDF2==1.24
@alexras
alexras / calculords.py
Created February 3, 2014 04:58
Quick script to generate good moves in Calculords
#!/usr/bin/env python
import sys, argparse, itertools
operators = [
('x', lambda x, y: x * y),
('+', lambda x, y: x + y),
('-', lambda x, y: x - y)]
def calculords_recurse(card, numbers, stack):
#!/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" \
@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
@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 / img_resize.py
Last active January 11, 2025 20:44
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 / 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 / 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);