Skip to content

Instantly share code, notes, and snippets.

msure / blog.txt
Created May 18, 2020
Current Conda Environment for Blog
View blog.txt
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: osx-64
msure /
Created Apr 21, 2020
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
# 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))
msure /
Created Dec 1, 2017
Example of Dplyr Code From R Reproduced In Python's Pandas
# 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') \
msure / why_would_i_even_do_this.js
Created Oct 26, 2016
Iterate Through An Objects Key-Value Pairs In Javascript: The Unnecessarily Complicated One-Liner Edition
View why_would_i_even_do_this.js
var vals = {'one':1,'two':2};
Object.keys(vals).forEach(function(i) {console.log('key:' + i + ', value:' + vals[i]);});
msure / index.html
Created Aug 22, 2016
This Example Shows How To Locally Display Your Base64 Output As An Image
View index.html
<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' );
msure / values_to_datalayer_step_by_step.html
Last active Jul 22, 2016
Detailed Walk-Through of Marketo Form Values To DayaLayer
View values_to_datalayer_step_by_step.html
// 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
// 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
msure / form_values_to_datalayer.html
Created Jul 22, 2016
Example of How To Push Marketo Form Values to DataLayer
View form_values_to_datalayer.html
MktoForms2.whenReady(function (form) {
var vals = form.vals();
'event': 'marketoFormSubmit',
'marketoCompany': vals['Company'],
'marketoLeadSource': vals['LeadSource'],
'marketoOriginalSource': vals['Original_Source_Detail__c'],
'marketoCurrentSource': vals['Source_Detail__c']
msure / marketo_submit_values.js
Created Jul 22, 2016
Example of How To Grab Marketo Form Values On Submission
View marketo_submit_values.js
MktoForms2.loadForm("//", "785-UHP-775", 1057, function(form) {
// Add an onSubmit handler
// 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 / optimizely_info.js
Last active May 2, 2018
Get Information About Active Optimizely Experiments
View optimizely_info.js
// all of this is made possible by the optimizely javascript api, specifically:
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:
You can’t perform that action at this time.