This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
mkdir tmp | |
cd tmp | |
wget https://github.com/downloads/libevent/libevent/libevent-2.0.20-stable.tar.gz | tar xzf - | |
cd libevent-2.0.20-stable | |
./configure --prefix=$HOME/local && make && make install | |
cd .. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from xml.etree import cElementTree as elemtree | |
from datetime import date | |
""" | |
Use this to parse XML from MeSH (Medical Subject Headings). More information | |
on the format at: http://www.ncbi.nlm.nih.gov/mesh | |
End users will primarily want to call the `parse_mesh` function and do something | |
with the output. | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# use with cron entries such as: | |
#3 */2 * * * $HOME/bin/mysql-backup.sh dbname backupname hourly H | |
#8 1 * * * $HOME/bin/mysql-backup.sh dbname backupname daily a | |
#33 2 1,8,15,23 * * $HOME/bin/mysql-backup.sh dbname backupname weekly d | |
#33 2 28 * * $HOME/bin/mysql-backup.sh dbname backupname monthly b | |
DB_NAME="$1" | |
BACK_ROOT="$2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import multiprocessing | |
import time | |
import signal | |
import sys | |
# based on http://stackoverflow.com/a/6191991/1711188 | |
# but instead of calling Pool.join(), we just close and manually poll for processes exiting | |
# also it assumes we have a finite number of jobs we want to run; if they complete | |
# it terminates in the normal way |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ssh_auth_save() { | |
ln -sf "$SSH_AUTH_SOCK" "$HOME/.ssh/ssh-auth-sock.$HOSTNAME" | |
} | |
alias screen='_ssh_auth_save ; export HOSTNAME=$(hostname) ; screen' | |
alias tmux='_ssh_auth_save ; export HOSTNAME=$(hostname) ; tmux' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# use this for any package (such as ClearParser) which requires setting the | |
# classpath to a particular set of jar files | |
if [ -z $BASH_SOURCE ] ; then | |
echo "Script must be sourced (using '.' or 'source') and run under bash >= 3.0" | |
exit 1 | |
fi | |
script_path="${BASH_SOURCE%/*}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from codecs import open | |
from contextlib import nested | |
import re | |
import sys | |
from os import path | |
# The regex ranges below may not work on narrow builds of python < 3.3 | |
# see http://stackoverflow.com/a/25417872/1711188 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Implicit conversion for Traversable instances where the elements are convertible - possibly controversial */ | |
implicit def convTrav[S, T, I[S] <: Traversable[S]](input: I[S])(implicit c: S => T): I[T] = | |
(input map c).asInstanceOf[I[T]] | |
/** Less controversial version of the above using the pimp-my-library pattern | |
- to use this, you must explicitly call .as[TypeName] on the source Traversable */ | |
trait Convertible[M[A], A] { | |
def as[B](implicit f: A => B): M[B] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
from contextlib import nested | |
from nltk import tree | |
def pretty_print(filenames): | |
for f in filenames: | |
with nested(open(f), open(f + '.pretty', 'w')) as (inf, outf): | |
for line in inf: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from blist import sorteddict, blist | |
class RangeFilter(sorteddict): | |
def filter_items(self, lt=None, lte=None, gt=None, gte=None): | |
"""Return the items with keys corresponding to the supplied parameters | |
('lt' denotes 'less than', 'gte' denotes 'greater than or equal' etc) | |
""" | |
bottom, top = self._get_range_indexes(lt, lte, gt, gte) | |
return self.items()[bottom:top] |
NewerOlder