Skip to content

Instantly share code, notes, and snippets.

@msure
msure / blog.txt
Created May 18, 2020 14:50
Current Conda Environment for Blog
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: osx-64
@EXPLICIT
https://repo.anaconda.com/pkgs/main/osx-64/blas-1.0-mkl.conda
https://repo.anaconda.com/pkgs/main/osx-64/ca-certificates-2020.1.1-0.conda
https://repo.anaconda.com/pkgs/main/osx-64/intel-openmp-2019.4-233.conda
https://repo.anaconda.com/pkgs/main/osx-64/jpeg-9b-he5867d9_2.conda
https://repo.anaconda.com/pkgs/main/osx-64/libcxx-10.0.0-1.conda
https://repo.anaconda.com/pkgs/main/osx-64/libgfortran-3.0.1-h93005f0_2.conda
@msure
msure / screen_pet.py
Created April 21, 2020 20:34
Screen Pet From Python For Kids Book
from tkinter import HIDDEN, NORMAL, Tk, Canvas
def toggle_eyes():
current_color = c.itemcget(eye_left,'fill')
new_color = c.body_color if current_color == 'white' else 'white'
current_state = c.itemcget(pupil_left,'state')
new_state = NORMAL if current_state == HIDDEN else HIDDEN
c.itemconfigure(pupil_left,state=new_state)
c.itemconfigure(pupil_right,state=new_state)
c.itemconfigure(eye_left,fill=new_color)
@msure
msure / helpful_snippets.py
Last active August 26, 2020 19:41
Pandas Scratchpad
# faster/vectorized replacement for getting monthly cohort
df['months_elapsed'] = (df['stats_date'].dt.month - df['first_date'].dt.month) + (12 * (df['stats_date'].dt.year - df['first_date'].dt.year))
# for handy functions (pandas, seaborn, etc.) where you need to reshape the dataframe first
df.query('some_filter == "2020-01-01" & another_filter != "error"').pipe(lambda x: pd.crosstab(x['variation'],x['customers']))
@msure
msure / dplyr_to_pandas.py
Created December 1, 2017 17:32
Example of Dplyr Code From R Reproduced In Python's Pandas
# https://www.reddit.com/r/datascience/comments/7ggdlz/what_do_you_hate_about_pandas/dqj6kaw/
# some_df %>%
# mutate(new_column = do_something(old_column)) %>%
# group_by(new_column) %>%
# summarize(some_means = mean(other_column))
df.assign(new_column = do_something(lambda x: x.old_column)) \
.groupby('new_column') \
.agg({'other_column':'mean'})
.rename(columns={'mean':'some_means'})
@msure
msure / why_would_i_even_do_this.js
Created October 26, 2016 22:32
Iterate Through An Objects Key-Value Pairs In Javascript: The Unnecessarily Complicated One-Liner Edition
var vals = {'one':1,'two':2};
Object.keys(vals).forEach(function(i) {console.log('key:' + i + ', value:' + vals[i]);});
@msure
msure / index.html
Created August 22, 2016 22:01
This Example Shows How To Locally Display Your Base64 Output As An Image
<html>
<head>
</head>
<body>
<p>Here is my image:</p>
<img id="img" src=""/>
<script type="text/javascript">
document.getElementById('img').setAttribute( 'src', 'data:image/png;base64,PASTE_THE_BASE64_OUTPUT_HERE' );
</script>
</body>
@msure
msure / values_to_datalayer_step_by_step.html
Last active July 22, 2016 20:08
Detailed Walk-Through of Marketo Form Values To DayaLayer
<script>
// all the marketo from 2.0 javascript has successfully loaded, so we can continue
MktoForms2.whenReady(function (form) {
// the user has just submitted the form
form.onSubmit(function(){
// marketo provides a form object with a nifty method to get the values from the form
// we'll store those values in a "vals" variable
var vals = form.vals();
// now we can push to the dataLayer
dataLayer.push({
@msure
msure / form_values_to_datalayer.html
Created July 22, 2016 19:28
Example of How To Push Marketo Form Values to DataLayer
<script>
MktoForms2.whenReady(function (form) {
form.onSubmit(function(){
var vals = form.vals();
dataLayer.push({
'event': 'marketoFormSubmit',
'marketoCompany': vals['Company'],
'marketoLeadSource': vals['LeadSource'],
'marketoOriginalSource': vals['Original_Source_Detail__c'],
'marketoCurrentSource': vals['Source_Detail__c']
@msure
msure / marketo_submit_values.js
Created July 22, 2016 19:27
Example of How To Grab Marketo Form Values On Submission
MktoForms2.loadForm("//app-sjst.marketo.com", "785-UHP-775", 1057, function(form) {
// Add an onSubmit handler
form.onSubmit(function(){
// Get the form field values
var vals = form.vals();
// You may wish to call other function calls here, for example to fire google analytics tracking or the like
// callSomeFunction(vals);
// We'll just alert them to show the principle
alert("Submitted values: " + JSON.stringify(vals));
});
@msure
msure / optimizely_info.js
Last active May 2, 2018 21:57
Get Information About Active Optimizely Experiments
// all of this is made possible by the optimizely javascript api, specifically:
// http://developers.optimizely.com/javascript/reference/#the-data-object
function getExperiments() {
var experimentInfo = {};
var wasRedirected = false;
/*
* create an array of experiments that are active on the page
* you must pass two tests to be placed in an active experiment:
* 1) url targeting: https://help.optimizely.com/hc/en-us/articles/200040835-URL-Targeting-Choose-where-your-experiment-runs