Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Joe Kington joferkington

View GitHub Profile
View zmap2xyz.py
"""
Converts one or more zmap grids to ascii x,y,z tab-delimited files. Exported
files will be saved to the current directory with a ".xyz" extension and the
same file name as the original. Null grid values will not be included unless
the "--with_nulls" option is specified.
Usage:
zmap2xyz.py [options] INPUT_FILES...
Options:
@joferkington
joferkington / cards_that_do_not_fit_future_sight.py
Created Nov 30, 2018
How many MTG cards would not fit on a future sight border?
View cards_that_do_not_fit_future_sight.py
import json
# https://mtgjson.com/v4/json/AllCards.json.zip
with open('AllCards.json', 'r') as infile:
data = json.load(infile)
for name in data:
card = data[name]
cost = card.get('manaCost', '')
if cost.count('{') > 6:
View circular_colorbar_demo.py
import numpy as np
from scipy.interpolate import Rbf
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
from mpl_toolkits.axes_grid1 import inset_locator
from matplotlib.projections.polar import PolarAxes
np.random.seed(1977)
def main():
x, y, z = generate_surface()
View example_scrolling_plot.py
import Tkinter as tk
import numpy as np
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
def main():
root = tk.Tk()
app = Application(root)
tk.mainloop()
@joferkington
joferkington / struct_vs_numpy_example.py
Last active Dec 7, 2015
Writing an arbitrary, pre-existing numpy array to a hetergenous binary format
View struct_vs_numpy_example.py
import numpy as np
# Our input data...
x = np.random.randint(0, 3200, (1000,1000))
# We're replacing something like
# struct.pack(">"+"hB"*x.size)
# Note that that's a 2-byte signed int followed by 1-byte unsigned
# We'll need to create the output 1D array and assign manually:
View fast_kde.py
import numpy as np
import scipy.sparse
import scipy.ndimage
import scipy.stats
import scipy.signal
import matplotlib.pyplot as plt
def main():
x, y = generate_data(int(1e7))
View matplotlib_layout_model.py
import matplotlib.pyplot as plt
def main():
resized = (8, 3)
basic_example()
basic_example(resized)
fixed_aspect()
fixed_aspect(resized)
View pandas_merge_example.py
import numpy as np
import pandas as pd
#-- Generate some data similar to yours
idx = np.arange(20)
np.random.shuffle(idx)
idx1 = idx[:15]
np.random.shuffle(idx)
idx2 = idx[:10]
@joferkington
joferkington / silly.py
Created Aug 28, 2015
Lovely dynamic typing
View silly.py
import random
class BadIdea(object):
def __getattr__(self, key):
return random.randint(0, 1000)
def __setattr__(self, key, value):
pass
x = BadIdea()
View bachelors_mpl_pr.py
import matplotlib.pyplot as plt
from matplotlib.mlab import csv2rec
from matplotlib.cbook import get_sample_data
#fname = get_sample_data('percent_bachelors_degrees_women_usa.csv')
fname = 'percent_bachelors_degrees_women_usa.csv'
gender_degree_data = csv2rec(fname)
# These are the colors that will be used in the plot
You can’t perform that action at this time.