Skip to content

Instantly share code, notes, and snippets.

View crowding's full-sized avatar

Peter Meilstrup crowding

View GitHub Profile
@crowding
crowding / lru.r
Created March 7, 2014 20:52
Simulating doubly-linked lists with hashtables
library(microbenchmark)
lru_cache <- function(cache.size = 1000) {
lru <- new.env(hash=TRUE, parent=emptyenv(), size=cache.size)
pred <- new.env(hash=TRUE, parent=emptyenv(), size=cache.size)
succ <- new.env(hash=TRUE, parent=emptyenv(), size=cache.size)
pred$TAIL <- "HEAD"
succ$HEAD <- "TAIL"
@crowding
crowding / logistic.ijs
Created April 10, 2014 05:49
Draw the logistic map in J, annotated.
'dot;color black' plot (; 50&}.@:((**(1-]))^:(i. 200)&0.25)) 2.4 ([+-~*((%~i.)100)) 4
NB. 100 numbers in [0,1) ^^^^^^^^^
NB. rescaled to ^^^^^
NB. 100 numbers in [2.4,4) ^^^ ^
NB. makes "x", ^^^^^^^^^^^^^^^^^^^^^^^^
NB. ^^^^^^^^^ function y -> y * (1-y)*x
NB. ^^^^^^^^^^ applied 200 times
NB. ^^^^^ starting with y=0.25
NB. ^^^^^^^ then dropping first 50 iterations
NB. ^ put original "x" alongside result
@crowding
crowding / Makefile
Last active August 29, 2015 14:04
hevea test case
all: text.pdf text.html
text.pdf: bib.bib text.tex
git clean -f -e text.pdf -e text.html
latexmk -pdf text.tex -pdflatex="pdflatex -halt-on-error -interaction=nonstopmode"
text.image.html: text.pdf
cp text.bbl text.hbbl
hevea text.tex -o text.html < /dev/null
@crowding
crowding / scanForDotUsage.R
Created October 11, 2014 23:39
Walk over a code base scanning for a particular pattern of usage
library(vadr)
library(plyr)
# do "chain" arguments ever feature a dot on the second level (not in
# its own chain?) Answer by walking over expressions to pull out
# examples of usages.
dirs = c("~/analysis", "~/analysis/writing")
globs = c("*.r", "*.R")
@crowding
crowding / README
Last active February 18, 2022 01:49
Screencap showing focus-follows-mouse issue
See video file
@crowding
crowding / import_bibdesk_dates.py
Created August 4, 2022 01:19
Tool to populate Zotero's date-added and date-modified values from the "extra" field resulting from importing from BibDesk
#!/usr/bin/env python3
# Usage: python3 import_bibdesk_dates.py path/to/zotero.sqlite
# Will only touch records that have not been synced (i.e. "version" == 0)
import sqlite3
import re
import datetime
import pytz
import dateutil.parser