Skip to content

Instantly share code, notes, and snippets.

View dansondergaard's full-sized avatar

Dan Søndergaard dansondergaard

View GitHub Profile
import sys
import textwrap
from itertools import dropwhile, takewhile
from collections import Counter
common_english_words = [
'the', 'of', 'and', 'to', 'a', 'in', 'for', 'is', 'on', 'that', 'by',
'this', 'with', 'i', 'you', 'it', 'not', 'or', 'be', 'are', 'from',
amino_acid_masses = {
'A': 71.0788,
'R': 156.1875,
'N': 114.1038,
'D': 115.0886,
'C': 103.1388,
'E': 129.1155,
'Q': 128.1307,
'G': 57.0519,
'H': 137.1411,
from docker import Client
cli = Client()
imgs = cli.images(all=True)
conts = cli.containers(filters={'status': 'running'})
# Make a map from image id to the name (tag) of the image.
# If no name is set, just use the id.
img_map = {}
function _jpu () {
squeue -h | awk '{print $4}' | sort | uniq -c | sort -b -h -r
}
alias jpu=_jpu
require('dplyr')
require('tidyr')
require('ggplot2')
# Read all cross-validation files and concatenate the dataframes.
tables = lapply(Sys.glob("cv_*.txt"), function (filename) {
read.csv(filename, sep=" ", header=FALSE,
col.names=c('File', 'Neighbors', 'Method', 'Accuracy'))
})
@dansondergaard
dansondergaard / notifications.fish
Created May 23, 2015 13:21
Notification when long-running process has completed (only for OS X and Fish 2.2b1-10 or newer).
#################
# notifications #
#################
function __record_cmd_begin -d "Record time when command started." -e fish_preexec
set -g cmd_begin_time (eval date +"%s")
end
function __record_cmd_end -d "Record time when command ended." -e fish_postexec
set -g cmd_end_time (eval date +"%s")
#!/usr/bin/env python3
import sys
import os
import os.path
import argparse
import subprocess
DEVNULL = open(os.devnull, 'wb')
import xml.etree.ElementTree as et
import base64
import array
def parse_file(filename_or_obj):
tree = et.parse(filename_or_obj)
for spectrum in tree.findall('.//spectrum'):
mz_elm = spectrum.find('mzArrayBinary').find('data')
intensity_elm = spectrum.find('intenArrayBinary').find('data')
@dansondergaard
dansondergaard / symbol.py
Created December 20, 2013 11:57
Symbols in Python.
class symbol(object):
_symbols = {}
def __new__(cls, name):
if name not in symbol._symbols:
symbol._symbols[name] = object.__new__(cls, name)
return symbol._symbols[name]
def __init__(self, name):
self.name = name
def compute_error(partition):
"""Find the majority category of the partition. Count how big
a part of the partition that the majority category is.
Return the ratio of things that are *not* of the majority category."""
categories = map(get_category, partition)
majority = max(set(categories), key=categories.count)
return 1 - (categories.count(majority) / float(len(partition)))
# This is what a typical partition looks like. The inner tuple may
# be very large (in the thousands) and the list of the length may