Skip to content

Instantly share code, notes, and snippets.

View thekensta's full-sized avatar

Chris Kenwright thekensta

View GitHub Profile
@thekensta
thekensta / ab_mc.ipynb
Last active November 5, 2015 16:15
Interactive AB split test via Monte Carlo Integration
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thekensta
thekensta / power_prop_test.py
Created November 13, 2015 10:30
Call power.prop.test via Python
# Need to change the values extracted, serves as aide-memoire for R <-> Python
def parse_robj(obj):
"""Extract n, p1 and p2 from R List from power.prop.test. """
return (obj[obj.names.index("n")][0],
obj[obj.names.index("p1")][0],
obj[obj.names.index("p2")][0])
def call_power_prop_test(p1, n):
P__ = %R power.prop.test(p1=$p1, n=$n, power=0.8)
return parse_robj(P__)
@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
@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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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
@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 / 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
-- 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 / 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.