Skip to content

Instantly share code, notes, and snippets.

@admackin
admackin / run-class.sh
Created August 14, 2014 01:29
Execute Java class in Maven Project using exec-maven-plugin
#!/bin/sh
# Don't forget to add the plugin to your POM - eg:
# <plugin>
# <groupId>org.codehaus.mojo</groupId>
# <artifactId>exec-maven-plugin</artifactId>
# <version>1.3.2</version>
# </plugin>
MAINCLASS=$1
@admackin
admackin / DateConversion.java
Created March 23, 2015 03:26
Java: Convert US customary week/date number into JodaTime DateTime object
package net.akmy.utils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.IllegalFieldValueException;
/*
Copyright 2014 Andrew MacKinlay
Licensed under the Apache License, Version 2.0 (the "License");
@admackin
admackin / lowerCamelCase.py
Last active September 4, 2015 13:44
Convert from underscores to camel case, if you randomly change conventions
# converts the input string with underscores from eg lower_camel_case to lowerCamelCase (do you like what I did with the name there?)
# should work reasonably on anything with vaguely C-like syntax (not LISP probably, but who really cares?)
from contextlib import nested
def camelCaseWord(underscored):
output_vals = []
prev_idx = 0
und_idx = underscored.find('_')
while und_idx != -1:
@admackin
admackin / gist:1136200
Created August 10, 2011 05:35
Force US Letter paper size in PDFlatex
% commands to get pdflatex to output in letter format
\special{papersize=8.5in,11in}
\setlength{\pdfpageheight}{\paperheight}
\setlength{\pdfpagewidth}{\paperwidth}
@admackin
admackin / mysql-repl-check.py
Created August 10, 2011 05:37
Cron script to check for MySQL replication problems
#!/usr/bin/python -Wignore::DeprecationWarning
"""
Call this as a cron script to check for replication problems
"""
import MySQLdb
DB_HOST = '127.0.0.1'
DB_USER = 'USERNAME'
DB_PASSWD = 'PASSWORD'
@admackin
admackin / gist:1318551
Created October 27, 2011 01:36
Install packages from last year's BasicTeX distribution in this year's.
grep install /usr/local/texlive/2010basic//texmf-var/web2c/tlmgr.log| perl -pi -e 's/.*install: //' | sudo xargs tlmgr install
@admackin
admackin / replace-command.tex
Created October 31, 2011 06:35
Replace Latex Command
%The following's adapted from the TeX Frequently Asked Questions - Rather than overwriting an old command it's common to want to add some code at the beginning or the end of it. Suppose we want a version of a command that does some small extension of its original definition: we might try:
\renewcommand{\splat}{addedcode\splat}
%However, this would not work: a call to \splat would execute addedcode, and then call the redefined \splat again; this is an infinite recursive loop. Fortunately, the TeX primitive \let command comes to our rescue; it allows us to take a "snapshot" of the current state of a command, which we can then use in the redefinition of the command. So:
\let\Oldsplat\splat
\renewcommand{\splat}{addedcode\Oldsplat}
%effects the required patch, safely. Adding things at the end of a command works similarly.
%If \splat takes arguments, one must pass them on:
\renewcommand{\splat}[2]{addedcode\Oldsplat{#1}{#2}}
@admackin
admackin / check-free-space.py
Last active September 28, 2015 09:58
Check free space and print error message if it is below a threshold
#!/usr/bin/env python
from __future__ import division
import os
import sys
import optparse
"""
Designed for use with cron scripts, as in the default state it only prints output
when the free space it below the requested threshold.
@admackin
admackin / gzipabstract.py
Created February 7, 2012 02:09
Handle Gzipped files semi-transparently
import gzip
import os
import errno
import codecs
from contextlib import nested
GZ_SUFF = '.gz'
BUFSIZE = 1048576
def gzip_fname(filename):
@admackin
admackin / time.py
Created April 26, 2012 05:13
TimeDeltaCustom - adds functionality to Python timedelta objects
from datetime import timedelta
class TimeDeltaCustom(timedelta):
"""A variant of timedelta with some neat extra features.
In particular, it supports division of TimeDeltaCustom by TimeDeltaCustom,
float multiplication, and getting the total number of seconds or hours.
"""
@classmethod