Skip to content

Instantly share code, notes, and snippets.

View kleinschmidt's full-sized avatar

Dave Kleinschmidt kleinschmidt

View GitHub Profile
@kleinschmidt
kleinschmidt / knit.sh
Created April 17, 2013 19:55
Little shell script to streamline using knitr from the command line, or in case you want to use it with something like emacs which can call a shell script to compile a document.
#!/bin/bash
# knit.sh -- Dave Kleinschmidt, April 2013
# streamline knitting of Rnw files from the command line.
usage="Usage: $0 input-filename.Rnw [-nolatex] [-notangle]"
if [ $# -lt 1 ]; then
echo $usage
exit 1
fi
@kleinschmidt
kleinschmidt / errorbars-se-ddply.R
Created March 2, 2013 00:36
How to compute SE of an observed variable and plot errorbars in R using plyr and ggplot.
require(plyr)
require(ggplot2)
# say dat is a data.frame with the predictor x, grouping variables z1, z2, and z3 (factors or discrete numeric values)
# and the observed values are in the variable y. then I would do:
dat.summ <- ddply(dat, .(x, z1, z2, z3), summarise,
y.mean=mean(y), y.se=sd(y)/sqrt(length(y)))
# this is equivalent to
@kleinschmidt
kleinschmidt / collect_keyboard_resp.js
Created August 15, 2012 16:12
JS: Collect a one-off keyboard response, using JQuery namespaces to allow multiple, overlapping responses
/* collect a one-off keyboard response, using JQuery namespaces to allow multiple, overlapping responses
* fcn(e): function to be called with event on key press
* keys: vector of allowed keys (as characters, uppercase for alphanumeric) (optional)
* to: timeout for response, in ms (optinal)
* tofcn: function to be called on timeout (optional)
*/
function collect_keyboard_resp(fcn, keys, to, tofcn) {
// create unique namespace for this response
var namespace = '._resp' + (new Date()).getTime();