Skip to content

Instantly share code, notes, and snippets.


whiledoing whiledoing

View GitHub Profile
View interface-slice.go
// from:
// make any slice to interface{} slice
func InterfaceSlice(slice interface{}) []interface{} {
s := reflect.ValueOf(slice)
if s.Kind() != reflect.Slice {
panic("InterfaceSlice() given a non-slice type")
ret := make([]interface{}, s.Len())
class Pipe(object):
def __init__(self, func):
self.func = func
def __ror__(self, other):
def generator():
for obj in other:
if obj is not None:
yield self.func(obj)
return generator()
whiledoing /
Last active February 1, 2020 08:27
[scipy-snippets] scipy snippets #python #scipy
# from:
import scipy.stats as stats
from matplotlib import pyplot as plt
import numpy as np
a = np.linspace(0, 4, 100)
expo = stats.expon
lambda_ = [0.5, 1]
for l, c in zip(lambda_, colours):
whiledoing /
Last active February 1, 2020 08:24
[sklearn-snippets] skl-learn snippets #python #sklearn
import numpy as np
import matplotlib.pyplot as plt
import ipywidgets as widget
from sklearn.datasets import make_blobs
from sklearn.svm import SVC
def plot_svc_decision_function(model, ax=None, plot_support=True):
"""Plot the decision function for a 2D SVC"""
ax = ax or plt.gca()
whiledoing /
Last active January 21, 2020 09:59
[altair-snippets] altair snippets #python #altair #visualization
# load an example dataset
from vega_datasets import data
cars =
import altair as alt
interval = alt.selection_interval()
base = alt.Chart(cars).mark_point().encode(
whiledoing /
Created January 21, 2020 09:40
[bokeh-snippets] bokeh snippets #python #bokeh #visualization
import numpy as np
from bokeh.plotting import figure, show
from import output_notebook
# Call once to configure Bokeh to display plots inline in the notebook.
N = 4000
x = np.random.random(size=N) * 100
y = np.random.random(size=N) * 100
whiledoing /
Last active January 21, 2020 09:41
[seaborn-snippets] seaborn snippets #python #seaborn #visualization
from sklearn.datasets import load_digits
digits = load_digits()
# split data
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(,, shuffle=True)
# use Gaussian Naive Bayes
from sklearn.naive_bayes import GaussianNB
model = GaussianNB()
whiledoing /
Last active January 22, 2020 09:34
[matplotlib-snippets] matplotlib snippets #matplotlib #python #visualization
def f(x, y):
return np.sin(x) ** 10 + np.cos(10+x*y) + np.cos(x)
x = np.linspace(0, 5, 50)
y = np.linspace(0, 5, 50)
X, Y = np.meshgrid(x, y)
Z = f(X, Y)
# draw contour
contour = plt.contour(X, Y, Z, 3, colors='black')
whiledoing /
Last active January 21, 2020 09:41
[pandas-snippet] pandas snippets #python #pandas #datascience
from pandas_datareader import data
goog = data.DataReader('GOOG', start='2014', end='2020', data_source='yahoo')
goog.columns = goog.columns.str.lower()
goog = goog.asfreq('D', method='bfill')
whiledoing /
Created December 28, 2019 11:09
[python-memo-decorator] python memo func call result decorator #python #util
from functools import wraps
def memoize(function):
memo = {}
def wrapper(*args):
return memo[args]
except KeyError:
rv = function(*args)