Skip to content

Instantly share code, notes, and snippets.

View thekensta's full-sized avatar

Chris Kenwright thekensta

View GitHub Profile
@thekensta
thekensta / what_is_the_roi_on_data.py
Last active January 11, 2016 23:37
Draw XKCD Plot for ROI
x1 = np.linspace(-0.5, 1.25, num=100)
x2 = np.linspace(0, 2, num=100)
def y1(x):
y = -2 * x**3 + 1.5 * x ** 2 + x
return y[np.argmax(y <0):]
def y2(x):
return 1 / (1 + np.exp(-5 * x + 4))
@thekensta
thekensta / matplotlib_styles.ipynb
Last active January 11, 2016 21:47
Matplotlib Styles
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thekensta
thekensta / window_function_comparison.ipynb
Created December 23, 2015 11:35
Window Function Comparison
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
-- Python function template to simulate the effects of a split test
-- Returns string with expected uplift and probability of Alt being better than Orig
-- as these are the values used to support decision making for UIUX testing
create function f_simulate_split_test(completions_orig INTEGER, sessions_orig INTEGER,
completions_alt INTEGER, sessions_alt INTEGER)
;
create function f_simulate_split_test(completions_orig INTEGER, sessions_orig INTEGER,
completions_alt INTEGER, sessions_alt INTEGER)
returns varchar(2000)
@thekensta
thekensta / fix_matplotlib_slow_import.sh
Created December 14, 2015 11:25
Fix Matplotlib slow import
# http://stackoverflow.com/questions/17490444/import-matplotlib-pyplot-hangs#
cd ~/.matplotlib/
fc-list
@thekensta
thekensta / simple_google_dataproc_ipython.sh
Last active December 31, 2015 15:32
Simple Google DataProc IPython Example
# http://stackoverflow.com/questions/33112020/how-do-i-install-jupyter-ipython-on-dataproc
PROJECT_ID=<project_id>
CLUSTER_NAME=<cluster_name>
# This should be ipython.sh
# https://github.com/GoogleCloudPlatform/dataproc-initialization-actions/blob/master/ipython-notebook/ipython.sh
INIT_GCS_SCRIPT=<init_gcs_script>
CHROME="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
gcloud beta dataproc clusters create $CLUSTER_NAME --zone europe-west1-b \
@thekensta
thekensta / redshift_python_df_example.sql
Last active December 9, 2015 14:21
Example of a UDF written in python on Redshift
create function f_extract_query_param(query_string VARCHAR, param VARCHAR)
returns varchar
STABLE
AS $$
# Split on ampersand and then on =, ensuring every param has a pair
params = query_string.split("&")
# split(.., 1) because there might be multiple '=' in the param
kp = [p.split("=", 1) for p in params]
# create dict, with "" for missing values where the key is not an empty string
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thekensta
thekensta / pip_update_everything.bash
Last active December 2, 2015 21:20
Update all outdated packages with pip
# Based on
# http://stackoverflow.com/questions/2720014/upgrading-all-packages-with-pip
# pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
pip3 list -o | cut -d ' ' -f 1 | xargs -n1 pip3 install -U
@thekensta
thekensta / install_cartopy.sh
Created December 2, 2015 10:31
Install Cartopy on OS X
brew install proj
brew install geos
# Assuming normal scipy stack is installed
pip3 install Pillow
pip3 install cartopy