Skip to content

Instantly share code, notes, and snippets.

View crowding's full-sized avatar

Peter Meilstrup crowding

View GitHub Profile
@crowding
crowding / expressions.R
Created January 20, 2013 08:37
enumerate all expressions w. some oberands and operators
##
{
## let's go ahead and generate the possibilities.
x <- 2
y <- pi
z <- exp(1)
`%^%` <- `^`
`%/%` <- `/`
@crowding
crowding / .bash_profile
Created March 11, 2013 22:10
if a command takes longer than some timeout, say "I'm done"
#.bash_profile
TIMEOUT=10
function speak_if_long {
last_command_time=$(HISTTIMEFORMAT="%s " history 1 | awk '{print $2}')
if (( $(date -u +"%s") - $last_command_time > $TIMEOUT ))
then
say "I'm done"
fi
}
@crowding
crowding / latex-math.r
Last active December 17, 2015 08:08 — forked from hadley/latex-math.r
# User facing function
#
# to_math(x_1 + 1^{2 + 4} + 5 + sqrt(y) / 5 %/% 10)
# to_math(paste(x^2, y - 1, z_i))
# to_math(hat(tilde(ring(x))))
# to_math(pi*r^2)
# to_math(unknown_call(x, floor(sqrt(z))))
to_math <- function(x) {
x <- substitute(x)
env <- latex_env(x)
@crowding
crowding / bdd.R
Last active May 9, 2023 11:56
R Code to simulate and describe a reaction-time decision process
library(ggplot2)
library(plyr)
theme_set(theme_bw())
theme_update(panel.border=element_blank())
# A reaction time experiment works as follows: On each trial, an
# observer is asked to view a stimulus and categorize it into one of
# multiple values. For instance, it may be a noisy motion stimulus,
# and the observer is asked to classify the motion as "leftward" or
@crowding
crowding / spatial-interactions.R
Created July 16, 2013 01:55
A toy model of a neuron with a gaussian receptive field responding to sparse noise, and recovering parameters with Stan
library(plyr)
library(ggplot2)
library(R.cache)
library(rstan)
#There is a sensor which either emits "yes" or "no." It adds up
#signals over some region of space (The "receptive field", which we
#model as having a Gaussian profile,) and emits a "yes" if the
#summed-up spatially weighted signals, plus unit additive noise, are
#over some threshold.
@crowding
crowding / README.Rmd
Last active December 22, 2015 03:08
Performance tuning rbind.fill
## Performance tuning `rbind.fill`
```{r setup, include=FALSE, cache=FALSE}
library(methods)
opts_chunk$set(cache=TRUE, dev="svg", tidy=FALSE,
fig.width=5, fig.height=5, autodep=TRUE,
fig.path='figure-')
with_dir <- function(dir, expr) {
prev <- getwd()
setwd(dir)
@crowding
crowding / lazy.frame.R
Last active December 23, 2015 10:19
Lazy data frame sketch
# lazy data frame
#
# like idata.frame, but exploits lazy evaluation + macro code generation
# instead of active bindings
library(vadr)
lazy.frame <- function(df, enclos=parent.frame(), ...) UseMethod("lazy.frame")
lazy.frame.lazy.frame <- function(df, ...) df
@crowding
crowding / 02.make
Created October 16, 2013 10:23
build errors for libextractor
Making install in m4
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
Making install in po
if test "libextractor" = "gettext-tools"; then \
.././install-sh -c -d /usr/local/Cellar/libextractor/1.0.1/share/gettext/po; \
for file in Makefile.in.in remove-potcdate.sin quot.sed boldquot.sed [email protected] [email protected] insert-header.sin Rules-quot Makevars.template; do \
/usr/bin/install -c -m 644 ./$file \
/usr/local/Cellar/libextractor/1.0.1/share/gettext/po/$file; \
done; \
@crowding
crowding / gist:8185810
Last active January 1, 2016 18:48
function on characters with recycling
SEXP _find_subst_expressions_list(SEXP strs, SEXP begin, SEXP end) {
int ns, nb, ne;
assert_type(strs, STRSXP);
assert_type(begin, STRSXP);
assert_type(end, STRSXP);
ns = LENGTH(strs);
nb = LENGTH(begin);
ne = LENGTH(end);
int nout;
(require 'ess-site)
(require 'ess-rutils)
(setq ess-use-tracebug t)
(setq ess-dbg-auto-single-key-p nil)
(setq inferior-R-args "--no-save")
(setq TeX-auto-save t)
(setq TeX-auto-parse-self t)