Skip to content

Instantly share code, notes, and snippets.

View tmalsburg's full-sized avatar

Titus von der Malsburg tmalsburg

View GitHub Profile
@tmalsburg
tmalsburg / insert_bibtex_from_doi.el
Last active April 16, 2024 09:27
An Emacs command that takes the DOI in the clipboard and inserts the corresponding BibTeX entry at point.
(require 'url-http)
(defun insert-bibtex-from-doi ()
(interactive)
(let* ((doi (string-trim (gui-get-primary-selection)))
(url (if (string-prefix-p "https://doi.org/" doi)
doi
(concat "https://doi.org/" doi)))
(url-request-method "GET")
(url-mime-accept-string "application/x-bibtex"))
@tmalsburg
tmalsburg / confidence_intervals.R
Last active October 14, 2023 07:48
Quick simulation of 50 experiments and their means and 95% confidence intervals
set.seed(1)
mu <- 0
sigma <- 1
N.trials <- 20
N.sims <- 50
rnorm(N.trials*N.sims, mu, sigma) |>
matrix(nrow=N.sims) -> Y
d <- apply(Y, 1, \(y) c(mean(y), sd(y)/sqrt(length(y))))
@tmalsburg
tmalsburg / chinese_color_terms.R
Created September 27, 2023 10:15
Analysis of onset patters of basic Mandarin Chinese color terms
library(ggplot2)
library(dplyr)
options(scipen=999)
N <- 100000 # Number of simulations
# Data:
@tmalsburg
tmalsburg / lengths_of_words_brown_corpus.py
Last active December 11, 2022 11:42
Python script that uses NLTK to calculate the average length of English words across token and types in the Brown corpus
import nltk
from statistics import mean, stdev, median, mode
nltk.download('brown')
tokens = nltk.corpus.brown.tagged_words(tagset="universal")
types = list(dict.fromkeys(tokens))
# Lengths of tokens / types but ignoring punctuation, numbers, and X
# which is mostly foreign words (German, French, Latin) but strangely
# also a small number of common English words:
@tmalsburg
tmalsburg / psychling_journals.opml
Last active June 3, 2023 05:15
RSS feeds of journals publishing work in (psycho)linguistics
<?xml version="1.0"?>
<opml version="1.0">
<head>
<title>(Psycho)linguistics journals</title>
</head>
<body>
<outline title="Annual Rev Ling" xmlUrl="https://www.annualreviews.org/action/showFeed?ui=45mu4&amp;mi=3fndc3&amp;ai=6690&amp;jc=linguistics&amp;type=etoc&amp;feed=atom"/>
<outline title="Brain &amp; Language" xmlUrl="https://rss.sciencedirect.com/publication/science/0093934X"/>
<outline title="Cognition" xmlUrl="http://rss.sciencedirect.com/publication/science/00100277"/>
<outline title="Cognitive Science" xmlUrl="https://onlinelibrary.wiley.com/feed/15516709/most-recent"/>
@tmalsburg
tmalsburg / week04.org
Created November 6, 2019 15:15
Sample org file for teaching slides

Foundations of Math

Agenda for today

@tmalsburg
tmalsburg / README.org
Last active May 12, 2018 17:23
R functions for calculating binomial credible intervals
@tmalsburg
tmalsburg / Instructions.md
Last active August 16, 2022 13:58
LaTeX template for articles in APA format

Compile this template by executing the following in a command shell:

  pdflatex test && biber test && pdflatex test && pdflatex test

This template uses biblatex and biber instead of good old BibTeX. The bibliography files (*.bib) can have the same format (although biblatex allows using some interesting extensions). However, the biblatex+biber combo is much more powerful than good-old BibTeX (e.g. support for multiple bibliographies in one document) and comes with great documentation.

Suggestions for improvements welcome.

@tmalsburg
tmalsburg / rmarkdown-render.el
Last active April 26, 2018 17:23
Elisp function for rendering RMarkdown files to PDF. Shows the output of the render process in a separate window.
(defun tmalsburg-rmarkdown-render ()
"Compiles the current RMarkdown file to PDF and shows output of
the compiler process in a separate window."
(interactive)
(let* ((buf (get-buffer-create "*rmarkdown-render*"))
(temp-window (or (get-buffer-window buf)
(split-window-below -10)))
(command "Rscript -e 'library(rmarkdown); render(\"%s\", output_format=\"%s\")'")
(command (format command (buffer-file-name) "pdf_document")))
(set-window-buffer temp-window buf)
@tmalsburg
tmalsburg / mturk_completion_times.org
Last active June 15, 2016 19:45
How to correctly calculate worker compensation for Amazon Mechanical Turk

How to correctly calculate worker compensation for Amazon Mechanical Turk

tl;dr: When calculating the average time it takes to complete a HIT, it may be more appropriate to use the geometric mean or the median instead of the arithmetic mean. You may otherwise spend considerably more money than necessary (in our case 50% more).