Skip to content

Instantly share code, notes, and snippets.

Avatar

Abraham Hmiel abehmiel

View GitHub Profile
@abehmiel
abehmiel / langton.py
Last active Mar 28, 2017
Python script for creating a Langton's Ant cellular automata
View langton.py
#!/usr/bin/python
# Langton's Ant
# Abraham Hmiel, 2017
# CC 3.0 attribution sharealike license
import numpy as np
import re
import sys
import matplotlib.pyplot as plt
import matplotlib as mpl
@abehmiel
abehmiel / 0_reuse_code.js
Created Mar 31, 2017
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@abehmiel
abehmiel / subplot_latex_nice.py
Created Mar 31, 2017
Matplotlib subplots with TeX rendering: good figure baseline for publications
View subplot_latex_nice.py
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
fig = plt.figure(figsize=(8.5,11.0))
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plt.rcParams['text.latex.preamble'] = [r'\boldmath']
# data in xmn, ymn does not exist. Replace with whatever data you're trying to plot
@abehmiel
abehmiel / 3dplot_quick.py
Last active Mar 31, 2017
Quick 3d plot snippet for 4 series on the same plot
View 3dplot_quick.py
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# generally, it's not advised to make 3d plots becuase they're not very transferable
# and there's usually ways to do dimensionality reduction. However, sometimes it's useful
# for exploratory purposes.
fig = plt.figure(figsize=(14,9.5))
ax = fig.add_subplot(111, projection='3d')
ax.scatter(x1, y1, z1, label='data1', c='k')
@abehmiel
abehmiel / colorblind_palete.py
Created Apr 3, 2017
Palette for colorblind-differentiable colors for plotting with Matplotlib
View colorblind_palete.py
col1 = (0/255.,107/255.,164/255.) # dark blue
col2 = (255/255.,128/255.,14/255.) # orange
col3 = (171/255.,171/255.,171/255.) # half-gray
col4 = (89/255.,89/255.,89/255.) # mostly gray
col5 = (95/255.,158/255.,209/255.) # sky blue
col6 = (200/255.,82/255.,0/255.) # burnt sienna
col7 = (137/255.,137/255.,137/255.) # 3/4 gray
col8 = (162/255.,200/255.,236/255.) # periwinkle
col9 = (255/255.,188/255.,121/255.) # peach
col10 = (207/255.,207/255.,207/255.) # 1/4 gray
View useful_pandas_snippets.py
# List unique values in a DataFrame column
pd.unique(df.column_name.ravel())
# Convert Series datatype to numeric, getting rid of any non-numeric values
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True)
# Grab DataFrame rows where column has certain values
valuelist = ['value1', 'value2', 'value3']
df = df[df.column.isin(valuelist)]
@abehmiel
abehmiel / gifsicle-120.sh
Created Apr 5, 2017
Gifsicle resize & context
View gifsicle-120.sh
#!/bin/sh
gifsicle --resize 120x120 file.gif > out-120.gif
@abehmiel
abehmiel / starter.lua
Created Apr 7, 2017 — forked from byronhulcher/starter.lua
PICO-8 Starter LUA code (save this as starter.p8)
View starter.lua
-- pico-8 starter code
-- by @hypirlink
-- _init() is called when
-- you 'run' the program
function _init()
-- states: menu, game, end
state = "menu"
end
@abehmiel
abehmiel / csv_tools.py
Created Apr 18, 2017
Useful Pandas csv import functions. Original by Chris Albon
View csv_tools.py
# Thanks to Chris Albon. Shamelessly lifted from: https://chrisalbon.com/python/pandas_dataframe_importing_csv.html
import pandas as pd
import numpy as np
# Create dataframe (that we will be importing)
raw_data = {'first_name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy'],
'last_name': ['Miller', 'Jacobson', ".", 'Milner', 'Cooze'],
'age': [42, 52, 36, 24, 73],
'preTestScore': [4, 24, 31, ".", "."],
@abehmiel
abehmiel / get_max_key.py
Created May 9, 2017
Get the key with the maximum value in a dictionary
View get_max_key.py
some_dict = {'one': 1, 'two':2, 'three': 3480394803840, 'four': 4}
max_key = max(some_dict, key=some_dict.get)
You can’t perform that action at this time.