Skip to content

Instantly share code, notes, and snippets.

View turtlemonvh's full-sized avatar

Timothy turtlemonvh

View GitHub Profile
@turtlemonvh
turtlemonvh / sequence_alignment.md
Last active January 22, 2016 17:52
Sequence alignment

Sequence alignment

While watching some videos from Udacity describing sequence alignment I was having a bit of a hard time understanding the algorithm as it was explained, so I decided to write it in code.

This is a fairly simple approach and uses recursion (so stack depth may be a problem for larger sequences), but it does use dynamic programming to keep things relatively fast. The code uses the same N, NW, W notation the video uses to describe the problem graph.

If there are branches in the problem graph (i.e. 2 alignments are have the same score) the program just takes the first solution.

Sequence alignment video series (part of the "Computability Complexity and Algorithms" class on Udacity): https://www.youtube.com/watch?v=3NLYH44F6SU&index=5&list=PLAwxTw4SYaPkbWSEj_1iO7rILlWDJImW4

@turtlemonvh
turtlemonvh / show_props.md
Last active January 22, 2016 17:53
Python list object properties

A function to get the values of all non-private properties of an object

showprops = lambda p: [(prop, getattr(p, prop)) for prop in [lprop for lprop in dir(p) if not lprop.startswith("_")]]

Example usage from an ipython shell

# Parse a complicated uri
In [1]: from urlparse import urlparse
In [2]: uri = "postgresql+psycopg2://user:password@postgres:5432/default"

In [3]: p = urlparse(uri)

@turtlemonvh
turtlemonvh / go_get_stash.md
Last active January 22, 2016 17:54
Go Get from Stash

Go Get from Stash

Add this function to your ~/.bashrc.

Use like

# Just use the url that stash recommends for cloning over ssh
go-get-stash ssh://git@stash.in.ionicsecurity.com:7999/il/common.git

You can use this package in your go files like

@turtlemonvh
turtlemonvh / README.md
Created March 4, 2016 20:10
Example of shifting the time components of a bson object id from mgo

Go retime objectid experiment

The mgo library has a function for generating an id with a timestamp (https://godoc.org/labix.org/v2/mgo/bson#NewObjectIdWithTime), but all the non-time related fields are zeroed out. This is useful for time range comparisons, but kind of annoying if you want to generate a new ObjectId for a particular time range that may be in the past or future.

This example shows how to take an existing unique ObjectId and adjust its origin time.

Example output

@turtlemonvh
turtlemonvh / README.md
Created March 21, 2016 12:32
Pocket bookmarklet
@turtlemonvh
turtlemonvh / build_rpm.sh
Created March 24, 2016 21:37
Building an RPM from a python package on ubuntu
#!/usr/bin/env bash
# Ensure ruby tools needed for FPM are available
apt-get install -y ruby ruby-dev gem rpm
# Ensure FPM is installed
gem install fpm
# Run FPM to build an image
fpm -s python \
@turtlemonvh
turtlemonvh / README.md
Last active March 29, 2016 05:03
Mezzanine template tag for longer post description
@turtlemonvh
turtlemonvh / README.md
Last active April 18, 2016 18:51
Print out the structural differences between all json files in a directory (what data paths are present in some and absent in others).

Find structural diffs

A simple script to show the structural differences between json files.

Usage

# Pairwise diffs between all files ending with `.json` in the current directory
python record-template-diffs.py

Pairswise diffs between every file ending in allowed.json in the current directory

@turtlemonvh
turtlemonvh / extract_env_as_dict.py
Created April 29, 2016 16:37
Python one liner to extract env as dict
# If the file you need to source is `.setup-env`
[e.split("=")[0:2] for e in commands.getoutput(". .setup-env && env").split("\n")]
@turtlemonvh
turtlemonvh / human_bytes.py
Created October 26, 2016 18:59
Human bytes for python
# Print byte counts in a human-friendly way
def human_bytes(b):
kb = 1024
mb = kb*1024
gb = mb*1024
tb = gb*1024
if b < 1024:
return "%d b" % b