Skip to content

Instantly share code, notes, and snippets.

View crowding's full-sized avatar

Peter Meilstrup crowding

View GitHub Profile
@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
@crowding
crowding / README
Last active February 18, 2022 01:49
Screencap showing focus-follows-mouse issue
See video file
@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 / 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 / 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 / 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"
(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)
@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;
@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 en@quot.header en@boldquot.header 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 / 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