Skip to content

Instantly share code, notes, and snippets.

View justmytwospence's full-sized avatar

Spencer justmytwospence

View GitHub Profile
@justmytwospence
justmytwospence / theme-xkcd
Last active December 14, 2015 09:58
R: An XKCD theme for ggplot2
### XKCD theme for ggplot2
theme_xkcd <- theme(
panel.background = element_rect(fill="white"),
axis.ticks = element_line(colour=NA),
panel.grid = element_line(colour="white"),
axis.text.y = element_text(colour=NA),
axis.text.x = element_text(colour="black"),
text = element_text(size=16, family="Humor Sans")
)
@justmytwospence
justmytwospence / snip.R
Last active August 19, 2019 09:15
R: Copy R output to the Mac OSX clipboard
snip <- function(input) {
pb <- pipe("pbcopy", "w")
write(input, file=pb)
close(pb)
}
@justmytwospence
justmytwospence / embed-gist-in-tumblr
Last active December 25, 2015 22:29
Web: Embed a gist in your tumblr blog.
# Place this into the header of your HTML
<script src="http://static.tumblr.com/fpifyru/AKFlv9zdu/embedgist.js"></script>
# Embed the gist using a div of this format:
<div class="gist">https://gist.github.com/`username`/`gist#`</div>
@justmytwospence
justmytwospence / mathjax-tumblr
Last active December 26, 2015 00:29
Web: Configure and source MathJax using their content distribution network. Place these two scripts in your tumblr header.
<!-- MathJax configuration -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: { equationNumbers: {autoNumber: "AMS"} },
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
processEscapes: true
}
});
</script>
@justmytwospence
justmytwospence / ignore-big
Last active December 27, 2015 21:29
Shell: Add all large files to .gitignore
find . -size +1G | cat >> .gitignore
@justmytwospence
justmytwospence / stratified-sample.R
Last active December 31, 2015 04:59
I was surprised to find that R doesn't have a base function for stratified random sampling. There's not even a well known package I could find that does this in a straight forward way. So heres my own. It is essentially a wrapper for a ddply call that samples each subset and then combines them. If the size argument is less than 1, it will be int…
stratified_sample <- function(df, size = .5, .by, seed = 37L) {
require(plyr)
set.seed(seed)
df.sample <- ddply(df, .by,
function(x) {
if (size < 1) { size <- size * nrow(x) }
return(x[sample(nrow(x), size = size),])
},
.progress = 'text')
return(df.sample)
@justmytwospence
justmytwospence / direct-download.php
Last active January 3, 2016 17:29
This PHP function will initiate a direct download of a file (pdf, etc.). MIME type on line 5 will also need to be changed if not PDF (eg "application/xml"). Now just create a hyperlink directly to this php script.
<?php
$actual_file_name = "path/to/foo.pdf";
$saved_file_name = "foo-bar.pdf"
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename=$saved_file_name");
header("Content-Length: " . filesize($actual_file_name));
readfile($actual_file_name);
exit;
% FontAwesome (http://fortawesome.github.com/Font-Awesome/) bindings for (Xe)LaTeX
% Author: Honza Ustohal <honza@egoistic.biz>
% A few icons added by: Spencer Boucher <spencer.g.boucher@gmail.com>
%
% Translation of FontAwesome's private range characters into XeTeX symbols. All icons are camel-cased and prefixed with 'fa', i.e. what was .icon-align-center the CSS version of FontAwesome becomes \faAlignCenter
% This might be reworked into a full blown package in the near future
%
% Prerequisite:
% XeLaTeX, FontAwesome installed as a system font accessible by XeLaTeX
%
@justmytwospence
justmytwospence / SVM.ipynb
Created February 1, 2014 03:55
First homework assignment for MSAN 630. All about training SVMs, including parameter grid search, leave one out cross validation, k-fold cross validation, 2 dimensional decision boundary plotting, RBF kernels, and more. View it here: http://nbviewer.ipython.org/gist/justmytwospence/8747722.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@justmytwospence
justmytwospence / Rmagic.ipynb
Last active August 29, 2015 13:55
IPython is not just for Python! Master your interdisciplinary data-science-fu with IPython magic! View here: http://nbviewer.ipython.org/gist/justmytwospence/8750427
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.