Skip to content

Instantly share code, notes, and snippets.

@samba
samba / sampleId.js
Last active April 16, 2018 19:10
GTM Sampling Variable
function(){
// Sets and gets a sample ID for bucket selection in A/B and related testing methodologies.
var ckPattern = /sampleId=(\d+)/g;
var sampleId = -1;
// TODO: adopt a different method for selecting the corp top level domain
var domain = document.location.hostname;
document.cookie.replace(ckPattern, function($0, $d){
@samba
samba / csvextract.py
Created March 9, 2018 06:10
Extract a subset of named fields from a CSV file
#!/usr/bin/env python
# Loads a CSV file, assuming it has header names, and prints only the specified columns.
# ... like selecting two columns of a 7-column table.
#
# Arguments:
# - field names, comma-separated
# - input filename
#
# Output:
# - the header row for the specified columns, and those fields for all input records.
@samba
samba / hubspot-gtm-loader.html
Last active July 5, 2017 22:59
GTM Container Snippet for HubSpot
<!-- Google Tag Manager loader; customized by Analytics Pros [analyticspros.com] -->
<script>
/* Update these for your GTM container(s); be sure they're unique, occurring only once each, not duplicated */
var GTMContainerIDs = ['GTM-XXXXX', 'GTM-YYYYY' ];
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'platform': 'hubspot' // Update this value to reflect other platforms
});
@samba
samba / Makefile
Last active May 5, 2017 23:18
Python requirements based on Operating System
# Example dynamic selection of Python requirements files
dependencies: $(shell python requirements.py)
for req in $^; do \
pip install --upgrade -r $$req ; \
done
test: dependencies
echo run your tests.
@samba
samba / setup.sh
Last active April 25, 2017 18:05
MAC Development Environment Setup
#!/bin/sh
# Sets up a wide array of my development environment on a Mac...
fail(){
err=$1; shift 1;
echo "$@" >&2
exit $err
}
@samba
samba / converse.sh
Last active March 2, 2017 19:24
Scripted conversations in your Mac.
#!/bin/sh
# Execute directly: sh converse.sh script.text
which say || exit 1
cat $@ | grep -v '^#' | tr -s ':' '\t' | while read name content; do say -v $name "$content"; done
@samba
samba / scandupes.py
Created January 11, 2017 07:00
MD5 Index Scanner
#!/usr/bin/env python
"""
Scan an index of files, typically keyed by MD5 checksum, in the format produced by
GNU `md5sum` (not BSD-style), searching for one of many checksums listed in a pattern file.
The primary objective is to help find duplicates in a large collection of files, e.g. an
archive of music. Example:
> find ./music -type f -print0 | xargs -0 md5sum | sort > index.txt
@samba
samba / fortunesay.sh
Created January 7, 2017 00:39
Say (audibly) random quotes/etc from UNIX fortune
#!/bin/sh
curl http://www.coe.neu.edu/cgi-bin/fortune | \
xmllint --nowarning --html --recover --xpath "//pre//text()" - 2>/dev/null | \
say -v Alex
@samba
samba / vm.sh
Last active December 29, 2016 23:18
Virtual Box headless - shell shortcuts
#!/bin/bash
# VirtualBox control handler
# OS X shell context (BSD utilities)
# Simplifies VBoxHeadless and VBoxManage calls.
# In my use-case, the primary objective is to
# Usage:
# vm.sh list lists all your VMs
@samba
samba / vbox-snapshot.sh
Created December 26, 2016 06:17
VirtualBox Snapshot Kit
#!/bin/sh
export MACHINE_NAME="test machine"
export DATE=`date +"%Y-%m-%d %H:%M:%S"`
take_snapshot () {
while read vmuuid; do
VBoxManage snapshot "${vmuuid}" take "Snapshot ${DATE}"
done
}