Skip to content

Instantly share code, notes, and snippets.

View mgronhol's full-sized avatar

Markus Grönholm mgronhol

View GitHub Profile
@mgronhol
mgronhol / Python (x)html templating with context manager
Created December 12, 2011 07:37
Referring to https://gist.github.com/1461441 , a pure python (no extra modules) version (NOT thread safe).
#!/usr/bin/env python
class HtmlDocument( object ):
TAGS = ['html', 'head', 'body', 'div', 'link', 'script',
'title', 'meta', 'p', 'a', 'span', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
'ul', 'li', 'ol', 'pre', 'code', 'footer', 'article', 'canvas', 'img', 'text' ]
def __init__( self ):
@kristacc
kristacc / Weasel.py
Created April 28, 2012 10:48
Genetic algorithms example
#!/usr/bin/env python
# this is a genetic algorithms tutorial by krista <3
# <[email protected]>
# Richard Dawkins is the inventor of this example ("METHINKS IT IS LIKE A WEASEL.")
# example is done with Python (works with versions 2.6 and 2.7)
# and to be more specific, we'll use elitistic evolution
# (== only fittest 10% will survive to the next population and rest will die.
# 50% of the best creatures will mate and make pretty babies to the next population <3 )
# 26.11.2011
@dronir
dronir / JDplot.py
Last active April 9, 2019 16:47
Sliced histogram plots
import numpy as np
def JDplot(data, ax, N, resolution=None, white=False, alpha=1.0, stagger=0.0, fill_color=None, fg_color=None):
"""Make a sliced histogram plot in the style of Joy Division's album cover.
- `data`, a 1D numpy array containing values.
- `ax`, the matplotlib Axes to draw onto.
- `N`, the number of histogram slices.
- `resolution`, the number of bins. Defaults to `N`.
- `white`, boolean. Sets black-on-white colour scheme instead default.