Skip to content

Instantly share code, notes, and snippets.

Step One
Fetch URL based on column:
'http://www.datasciencetoolkit.org/maps/api/geocode/json?sensor=false&address=' + escape(value, 'url')'
Step Two
Parse Json for longitude:
value.parseJson()["results"][0]["geometry"]["location"]["lng"]
@samuelleach
samuelleach / .bashrc
Created August 20, 2013 08:39
Bash configuration script for jumping around your file system.
# From http://jeroenjanssens.com/2013/08/16/quickly-navigate-your-filesystem-from-the-command-line.html
export MARKPATH=$HOME/.marks
function jump {
cd -P $MARKPATH/$1 2> /dev/null || echo "No such mark: $1"
}
function mark {
mkdir -p $MARKPATH; ln -s $(pwd) $MARKPATH/$1
}
function unmark {
rm -i $MARKPATH/$1
@samuelleach
samuelleach / publickey2clipboard
Last active January 2, 2016 22:29
Script to copy your public key to the clipboard (via @scraperwiki)
[ -e ~/.ssh/id_rsa.pub ] || ssh-keygen -f ~/.ssh/id_rsa
pbcopy < ~/.ssh/id_rsa.pub
@samuelleach
samuelleach / ggmap.txt
Created February 26, 2014 20:26
Geocode with ggmap/R in Tableau
SCRIPT_STR("
library('ggmap');
geo <- geocode(.arg1, output='latlon');
geo$latlon <- do.call(paste, c(geo[c('lat','lon')], sep = ','));
geo$latlon
", ATTR([FULL ADDRESS]))
@samuelleach
samuelleach / saltstack_init.sh
Created February 28, 2014 12:18
Initial set up for getting started with Saltstack
brew install saltstack
sudo mkdir -p /etc/salt /var/cache/salt /var/log/salt
sudo chown -R leach /etc/salt /var/cache/salt /var/log/salt
@samuelleach
samuelleach / conditional_filter.txt
Created February 28, 2014 15:41
Example of a conditional filter in Tableau
MAX(IFF([Category]="category1",1,0))+
MAX(IFF([Category]="category2",1,0))=2
<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script>
var width = 960,
height = 500;
var nodes = d3.range(200).map(function() { return {radius: Math.random() * 12 + 4}; }),
@samuelleach
samuelleach / yeartodate.txt
Created March 2, 2014 09:48
Tableau calculation to convert a year (YYYY) into a date
DATEPARSE("yyyy", STR(year) )
@samuelleach
samuelleach / polynomial.txt
Created March 3, 2014 06:57
Tableau calculated field using R to predict values using a polynomial fit of degree two. Data may contain zeroes which are excluded from the fit, but are predicted by the model.
SCRIPT_REAL("
xdata <- .arg1
ydata <- .arg2
indices <- which( abs(ydata) < 0.01 )
ndata <- length( ydata )
weights <- rep(1, ndata)
weights[indices] = 0
model <- lm( ydata ~ xdata + I(xdata^2), weights=weights )
SCRIPT_STR('classify_polarity(.arg1,algorithm="bayes",verbose=TRUE)[,4]',
ATTR([CommentText])
)
SCRIPT_STR('classify_emotion(.arg1,algorithm="bayes",verbose=TRUE)[,7]',
ATTR([CommentText])
)