Skip to content

Instantly share code, notes, and snippets.

@dmeliza
dmeliza / learning-models.ipynb
Created January 29, 2015 15:41
Learning models
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Keybase proof

I hereby claim:

  • I am dmeliza on github.
  • I am dmeliza (https://keybase.io/dmeliza) on keybase.
  • I have a public key whose fingerprint is 01EC 589A D750 9ADA B42C 7B72 F275 EE6B C700 7DBB

To claim this, I am signing this object:

@dmeliza
dmeliza / gist:5774125
Created June 13, 2013 14:30
natural sort strings in python
def natsorted(key):
""" key function for natural sorting. usage: sorted(seq, key=natsorted) """
import re
return map(lambda t: int(t) if t.isdigit() else t, re.split(r"([0-9]+)",key))
@dmeliza
dmeliza / scalebars.py
Last active February 7, 2023 00:33
matplotlib: add scale bars to axes
# -*- coding: utf-8 -*-
# -*- mode: python -*-
# Adapted from mpl_toolkits.axes_grid1
# LICENSE: Python Software Foundation (http://docs.python.org/license.html)
from matplotlib.offsetbox import AnchoredOffsetbox
class AnchoredScaleBar(AnchoredOffsetbox):
def __init__(self, transform, sizex=0, sizey=0, labelx=None, labely=None, loc=4,
pad=0.1, borderpad=0.1, sep=2, prop=None, barcolor="black", barwidth=None,
**kwargs):
@dmeliza
dmeliza / python_sqlite3.py
Created June 1, 2012 19:02
python sqlite3 table inspection
# two python functions to extract field names from sqlite3 database tables
def schema_fields(schema):
"""
Extract fields defined in a (sqlite3) table schema.
schema: string with CREATE TABLE statement for the table
returns tuple of field names
raises ValueError, if parsing failed
@dmeliza
dmeliza / axgriditer.py
Created May 17, 2012 23:28
Python coroutine for plotting to multiple axes in multiple figures
def axgriditer(gridfun=None, figfun=None, **figparams):
"""
Generator for making a series of plots to multiple axes in multiple figures.
This function provides a coroutine to handle tasks involved in
creating a figure with one or more axes and saving the figure when
all the axes have been used (or all the data has been used),
repeating as needed.
Keyword arguments:
@dmeliza
dmeliza / read.org.R
Created May 17, 2012 19:30
load org-mode tables in R
##' Read tabular data in org format
##'
##' Reads data stored in org tables, which have '|' characters and
##' whitespace separating columns. Uses GNU sed to select lines that
##' start with '| ' (which excludes hlines), replaces separators and
##' excess whitespace with tabs, and passes the stream to
##' read.table. Missing fields will be NA in numeric columns and empty
##' in character columns. It's recommended to use quote="" to avoid
##' nasty parsing errors if there are quotation marks in the table.
##'