Skip to content

Instantly share code, notes, and snippets.

nmalkin /
Created October 31, 2023 06:54
Replace longtable with table in LaTeX generated by Quarto and/or Pandoc
#!/usr/bin/env python
This script patches the .tex generated by Quarto to replace usage of \longtable with vanilla tables, and then compiles that.
This is necessary because longtable doesn't support two-column layouts, and even after applying the hacky solution, the PDF output is mangled in such a way that entire pages are skipped.
import os
import shutil
nmalkin /
Created September 22, 2022 23:57
Sample grading script (for Prolific surveys and others)

Sample grading script (for Prolific surveys and others)

This is an example grading script I use for more easily reviewing survey responses. It spins up a webpage showing all the responses that still need to be reviewed, with Approve/Reject buttons for each one.

This particular script assumes the survey being graded is being run on the Prolific platform. It therefore looks for a separate Prolific export file (in ~/Downloads) and joins it with the provided data file (on the PROLIFIC_PID field) in order to only show responses that (1) are associated with a Prolific submission and (2) have not already been graded. This portion can be removed, if needed.

When you approve or reject a response through this script, the associated ID gets added to approved.txt or rejected.txt, respectively. The contents of these files can then by copied into the bulk action interface on Prolific.


nmalkin /
Last active December 24, 2019 03:53
npm install latest available package (equivalent of `yarn upgrade --latest`)

npm install latest available package (equivalent of yarn upgrade --latest)

npm outdated --parseable --depth=0 | cut -d: -f4 | xargs npm install


Per the official documentation, here's what yarn upgrade --latest does:

nmalkin /
Last active May 20, 2022 00:18
SHA-256 hash of a string in Python 3
#!/usr/bin/env python3
import hashlib
def hash_string(string):
Return a SHA-256 hash of the given string
return hashlib.sha256(string.encode('utf-8')).hexdigest()
nmalkin / cors.html
Created February 21, 2016 05:11
CORS request example
<!DOCTYPE html>
<meta charset='utf-8'>
var xhr = new XMLHttpRequest();'GET', '');
xhr.onload = function() {
nmalkin /
Created February 1, 2016 22:47
Docker cleanup
#!/usr/bin/env python3
# This snippet provides the code to make an HTTP request using Python 3's
# built-in libraries, with the following properties:
# - POST request
# - send form-encoded data
# - the URL is behind HTTP basic authentication
# The motivating example is making API requests to a service such as Mailgun.

Keybase proof

I hereby claim:

  • I am nmalkin on github.
  • I am nmalkin ( on keybase.
  • I have a public key whose fingerprint is AE7F 92E6 76DC 764E 44E9 7459 5B32 A1DA B4CB 2894

To claim this, I am signing this object:

User agent:

This bug appears in the latest Nightly (Firefox 34). It behaves correctly in the current stable version (Firefox 31).

Steps to reproduce:

  1. Start with a page that sets a cookie and redirects (HTTP 302) in the same request
  2. Load that page in an iframe
  3. Make sure the page that serves the iframe is on a different host/origin from the page in the iframe
nmalkin / barrier.js
Created July 4, 2014 09:21
Barrier demonstration
"use strict";
function longRunningFunction1(onComplete) {
setTimeout(onComplete, 3000);
function longRunningFunction2(onComplete) {
setTimeout(onComplete, 2000);