Skip to content

Instantly share code, notes, and snippets.

View jbn's full-sized avatar

John B Nelson jbn

View GitHub Profile
import numpy as np
def your_function(x):
return x * np.random.rand()
# Repeatedly calling this,
# pytest --caprng-global-np
# from the command line will fail with the same values
# over and over again until it passes.
@jbn
jbn / pretty.py
Created May 13, 2018 15:11
Pretty Squares
def portray_neighborhood_offsets(C, origin, dist_func=None):
C = C.copy()
C[origin] = 2
fig, ax = plt.subplots(1, 1)
ax.imshow(C,
interpolation='nearest', # Not 'none'!
aspect='equal',
cmap=plt.cm.Purples)
import sys, locale
exprs = """
locale.getpreferredencoding()
type(fp)
fp.encoding
sys.stdout.isatty()
sys.stdout.encoding
sys.stdin.isatty()
@jbn
jbn / replot_as_svg.py
Created February 28, 2018 16:00
Extract for attempted David assist
import matplotlib.pyplot as plt
from ipykernel.pylab.backend_inline import flush_figures
from IPython.display import display, clear_output, SVG
def replot_as_svg(fig=None, **adjustments):
"""
Take a given matplotlib figure and write it as an embeddable SVG.
:param fig: the matplotlib figure or None for implicit use of plt.gcf()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from lxml.etree import fromstring, tostring
def hatch_safe_svg(data):
# rsvg-convert doesn't resolve <pattern> fills from #fragment
# URIs if they occur downfile from the usage. This makes sure
# definitions come first.
doc = fromstring(data)
defs = [el for el in doc.getchildren()
if el.tag == "{http://www.w3.org/2000/svg}defs"]
geo $congress {
# See: @congressedits
}
server {
if ($congress) {
rewrite ^ http://www.example.com/meta_random_refresh_original.html;
}
}
@jbn
jbn / test_cli.sh
Last active November 8, 2017 19:22
#!/bin/bash
###############################################################################
# setUp
###############################################################################
# Fail on first non-zero return value.
set -ev
# Ensure a pristine environment.
@jbn
jbn / .travis.yml
Last active November 8, 2017 17:58
language: python
python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
install:
- "pip install -r requirements.txt"
- "pip install coveralls nose"
script:
@jbn
jbn / scatch.ipynb.tmpl
Created November 4, 2017 17:59
Scratch notebook
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [