Skip to content

Instantly share code, notes, and snippets.

View mdboom's full-sized avatar

Michael Droettboom mdboom

View GitHub Profile
@mdboom
mdboom / gist:5588912
Created May 16, 2013 02:07
A PLY lexer that will cause a UnicodeDecodeError with ply-3.4
# -*- coding: utf-8 -*-
"""
Having any non-ascii content in this file is enough to get it to fail.
Jsme rytíři, kteří říkají "ni"
"""
tokens = (
'NAME','NUMBER',
@mdboom
mdboom / gist:5919376
Created July 3, 2013 15:29
__array_prepare__ doesn't get called.
import numpy as np
class Quantity(object):
def __init__(self, value, unit):
self.unit = unit
self.value = value
self.exception = False
def __getitem__(self, key):
@mdboom
mdboom / foo.c
Last active December 23, 2015 17:39
Dead simple setup.py to experiment with setuptools' setup_requires feature
#include "numpy/arrayobject.h"
@mdboom
mdboom / gist:7929306
Last active December 31, 2015 03:39
Timing of handling negative numbers raised to fractional powers.
import cmath
import timeit
def test_a(s, p):
try:
x = s ** p
except ValueError:
# on python2, sqrt(negative number) does not
# automatically lead to a complex number, but this is
@mdboom
mdboom / gist:89a8e9f2f38922d723a4
Created May 14, 2015 13:19
Hackish scripts to make installing and testing astropy-like packages from emacs easier
#!/usr/bin/env python
"""
Run from anywhere in a projects directory tree, this will compile and install
"""
import sys
import os
current_path = '.'
from pyasdf import AsdfFile
import numpy as np
import time
for i in (10, 100, 1000, 10000):
arrays = []
for x in range(i):
arrays.append(np.random.rand(32, 32))
tree = {'arrays': arrays}
@mdboom
mdboom / mpl_astropy_units.py
Created July 20, 2015 13:45
Proof of concept of support for astropy.Quantity in matplotlib
import numpy as np
from matplotlib import units
from matplotlib import ticker
from astropy import units as u
def rad_fn(x, pos=None):
n = int((x / np.pi) * 2.0 + 0.25)
if n == 0:
return '0'
@mdboom
mdboom / pandas_logo.py
Created April 18, 2016 13:27
Pandas logo
from matplotlib import pyplot as plt
from matplotlib import rcParams
import numpy as np
rcParams['mathtext.fontset'] = 'cm'
def fnx():
return np.random.randint(5, 50, 10)
fig = plt.figure(figsize=(6, 1.25))
@mdboom
mdboom / datashader-matplotlib-mashup.py
Last active April 23, 2020 10:59
The absolute bare minimum to get datashader working in matplotlib
import matplotlib.pyplot as plt
import pandas as pd
import datashader as ds
import datashader.transfer_functions as tf
from datashader.colors import Hot
time_period = 60

Keybase proof

I hereby claim:

  • I am mdboom on github.
  • I am mdboom (https://keybase.io/mdboom) on keybase.
  • I have a public key ASBfS4TOT-Pi1GSH25opWjghd-jdNd0uytAM-yQ0u1Ktego

To claim this, I am signing this object: