Skip to content

Instantly share code, notes, and snippets.


Dave Kleinschmidt kleinschmidt

View GitHub Profile
kleinschmidt / collect_keyboard_resp.js
Created Aug 15, 2012
JS: Collect a one-off keyboard response, using JQuery namespaces to allow multiple, overlapping responses
View collect_keyboard_resp.js
/* 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();
kleinschmidt / errorbars-se-ddply.R
Created Mar 2, 2013
How to compute SE of an observed variable and plot errorbars in R using plyr and ggplot.
View errorbars-se-ddply.R
# 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,
# this is equivalent to
kleinschmidt /
Created Apr 17, 2013
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.
# -- 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
kleinschmidt / mod_to_table.R
Created Jan 13, 2014
Code to turn lmer models into a nice latex table. Specify model object or coefficients. Based on functions by Judith Degen (modified by Florian Jaeger):
View mod_to_table.R <- function(mod.all=NA, prednames=NA, pred_name_subs=NA, file="",,
...) {
if ( {
if ( {
prednames <- row.names(coefs)
} else {
prednames <- str_replace_multi(row.names(coefs), pred_name_subs, replace.all=T)
kleinschmidt /
Last active Jan 4, 2016
Bash script which combines multiple (possibly redundant) .results files returned by Amazon Mechanical Turk's command line tools.
# Author: Dave Kleinschmidt
# Author: Dave Kleinschmidt
# concatenate all *.results files in the directory, printing one line
# per unique assignment id (first encountered). NOTE: the header isn't
kleinschmidt / clean-library-auto.plist
Last active Oct 30, 2016
Make Mendeley, BibTeX, and apacite play nicely together by removing URL and month entries. Apacite lumps journal articles and newspaper/magazine articles in the same class, and always prints a month if it's provided. This gist has a shell script that strips this info out and a launchd handler that watches the auto-exported .bib file and runs the…
View clean-library-auto.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">
kleinschmidt / histogram_woes.ipynb
Created Aug 3, 2014
Problems with Geom.histogram in Gadfly
View histogram_woes.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
kleinschmidt / qqplot.jl
Last active Aug 29, 2015 — forked from johnmyleswhite/qqplot.jl
QQ plots in Julia with Gadfly (based on Vega example)
View qqplot.jl
using Stats, Distributions, Gadfly
import Gadfly.ElementOrFunction
# First add a method to the basic Gadfly.plot function for QQPair types (generated by Distributions.qqbuild())
Gadfly.plot(qq::QQPair, elements::ElementOrFunction...) = Gadfly.plot(x=qq.qx, y=qq.qy, Geom.point, Theme(highlight_width=0px), elements...)
# Now some shorthand functions
qqplot(x, y, elements::ElementOrFunction...) = Gadfly.plot(qqbuild(x, y), elements...)
qqnorm(x, elements::ElementOrFunction...) = qqplot(Normal(), x, Guide.xlabel("Theoretical Normal quantiles"), Guide.ylabel("Observed quantiles"), elements...)
kleinschmidt / aws_creds.json
Last active Aug 29, 2015
Tiny demo of using Amazon SQS to listen to notifications from Mechanical Turk. Run `npm install` to get dependencies.
View aws_creds.json
"accessKey": "your access key",
"secretKey": "your secret key"
kleinschmidt / input.R
Created Jan 28, 2015
converting factor to character after rowwise()
View input.R
data.frame(a=factor(c('10', '20', '30', '40'))) %>%
mutate(b=as.character(a)) %>%
rowwise() %>%
mutate(c=as.character(a)) %>%
You can’t perform that action at this time.