Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
def get_blks():
import gzip
# <http://hgdownload.cse.ucsc.edu/goldenPath/hg38/liftOver/hg38ToHg19.over.chain.gz>
with gzip.open('hg38ToHg19.over.chain.gz', 'rt') as f:
for line in f:
line = line.rstrip('\n').split()
if line and line[0] == 'chain':
blk = dict(chr1=line[2], std1=line[4], stt1=int(line[5]), len1=int(line[6]),
# resulting graph is at https://www.dropbox.com/s/vepdi2deoeejly0/dhs_nreads.png?dl=0
import pybedtools
import pysam
import itertools
import matplotlib.pyplot as plt
def avg(iterator):
total, n = 0,0
for it in iterator:
#!/usr/bin/env python3
import asyncio
import sys
class StdOutProtocol(asyncio.SubprocessProtocol):
def __init__(self, exit_future):
self.exit_future = exit_future
self.output = bytearray()
def pipe_data_received(self, fd, data):
list(v.update(num_bad_guesses=sum(1 for g in guesses if g not in chosen_word)) or \
((10 <= v['num_bad_guesses'] and prin('You lose!\n'+scaffold.format(*man))) or \
(all(l in guesses for l in chosen_word) and prin('You win!'))) and \
(prin('Word was ' + chosen_word) and next(iter([]))) or \
prin(','.join(sorted(guesses)) + '({} guesses left)'.format(10-v['num_bad_guesses'])+'\n' +
scaffold.format(*man[:v['num_bad_guesses']]+' '*10)) and \
guesses.update(filter(str.isalpha,
inpt(' '.join(l if l in guesses else '_' for l in chosen_word)+': ').upper())) \
for (license, chosen_word, guesses, scaffold, man, v, prin, inpt) in [(
'https://opensource.org/licenses/MIT',
#!/bin/bash
set -euo pipefail
error() {
local parent_lineno="$1"
local message="$2"
local code="${3:-1}"
if [[ -n "$message" ]] ; then
echo "Error on or near line ${parent_lineno}: ${message}; exiting with status ${code}"
#!/usr/bin/env python3
import subprocess, random
rows, columns = (int(r) for r in subprocess.check_output([b'stty', b'size']).split())
data1 = [(x*0.1, random.gauss(40,3) - 30*(x/100.)**2) for x in range(0,100)]
data2 = [(x*0.1, random.gauss(20,3) + 30*(x/100.)**2) for x in range(0,100)]
gnuplot = subprocess.Popen("/usr/bin/gnuplot", stdin=subprocess.PIPE)
#!/bin/bash
# Notes: since we're just taking everything, we're not using the information in this comment block.
# Note: dialog_partner is no longer reliable as of 2015 Aug 25.
# Good columns are: timestamp, convo_id, author, body_xml.
# To find the right convo_id, run
# $ sqlite3 path/to/main.db
# > select datetime(timestamp, 'unixepoch'),convo_id,author from Messages;
# > select count(*) from Messages;
# > select count(*) from Messages where convo_id = 270;
//investigate the memory layout of a c++ program
//run with: `gcc b.c && ./a.out $(seq 1000) | sort | uniq`
#define OUT(var) printf("%16lx %s\n", (unsigned long int) &var, #var )
#define NL printf("\n")
#include <stdio.h>
#include <stdlib.h>
char global_const = 5;
@pjvandehaar
pjvandehaar / wikilifetimes.py
Created February 11, 2015 04:09
how many minutes a wikipedia edit lasts
import requests
r=requests.get('http://en.wikipedia.org/w/index.php?title=Credit_card_interest&offset=&limit=5000&action=history')
from bs4 import BeautifulSoup
soup = BeautifulSoup(r.text)
date_strings = (a.text for a in soup.select('a.mw-changeslist-date'))
from dateutil import parser
dates = (parser.parse(date) for date in date_strings)
@pjvandehaar
pjvandehaar / aes_url.py
Last active August 29, 2015 14:04
encrypt data & store it in an url. ought to do compression.
#!/usr/bin/env python3
# this code is all wrong; don't use it.
# constant IV + allowing a plaintext attack means that this is totally broken.
# the intention was to be able to store javascript code in URLs and then run it.
# but that problem needs authentication, not encryption.
# so, just add an HMAC's 128-bit digest to the URL.
import string
import random