Skip to content

Instantly share code, notes, and snippets.

@msure
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
@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 Apr 21, 2020
Screen Pet From Python For Kids Book
View screen_pet.py
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)
View helpful_snippets.py
# 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
msure / dplyr_to_pandas.py
Created Dec 1, 2017
Example of Dplyr Code From R Reproduced In Python's Pandas
View dplyr_to_pandas.py
# 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 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
msure / index.html
Created Aug 22, 2016
This Example Shows How To Locally Display Your Base64 Output As An Image
View index.html
<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 Jul 22, 2016
Detailed Walk-Through of Marketo Form Values To DayaLayer
View values_to_datalayer_step_by_step.html
<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 Jul 22, 2016
Example of How To Push Marketo Form Values to DataLayer
View form_values_to_datalayer.html
<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 Jul 22, 2016
Example of How To Grab Marketo Form Values On Submission
View marketo_submit_values.js
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
Get Information About Active Optimizely Experiments
View optimizely_info.js
// 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
You can’t perform that action at this time.