Skip to content

Instantly share code, notes, and snippets.

thomasballinger /
Created Dec 15, 2013
Using a pseudo-terminal to interact with interactive Python in a subprocess
from subprocess import Popen, PIPE
import pty
import os
from select import select
import sys
import tty
master, slave = pty.openpty()
p = Popen(['python'], stdin=slave, stdout=PIPE, stderr=PIPE)
pin = os.fdopen(master, 'w')
thomasballinger / gist:1336916
Created Nov 3, 2011
nifti2nrrd dwi conversion
View gist:1336916
#!/usr/bin/env python
#1) Add measurement frame
#2) Save data part of nifti to its own file, and point to it in 'data file' field
import nibabel as nib
import sys
#!/usr/bin/env python
"""File format conversion
category: vtk, file conversion, tomb"""
import os, sys
import vtk
def vtk2vtp(invtkfile, outvtpfile, binary=False):
"""What it says on the label"""
reader = vtk.vtkPolyDataReader()
View gist:2991211
#!/usr/bin/env python
"""An externally-accessible toy server whith several response strategies"""
import socket
import sys
from multiprocessing import Pool
def web_scrape(site):
s = socket.socket()
s.connect((site, 1333))
View myrepl.mjs
import tty from 'tty'
import { emitKeypressEvents } from 'readline';
let drain;
process.stdout.on('drain', () => { drain() });
const waitForDrain = () => new Promise(r => {drain = r});
function waitForDrainify(func) {
return async (...args) => {
if (!func(...args)) {
await waitForDrain();
View endless-sky emscripten progress
# Starting with Ubuntu 18.04.3 (LTS) x64
# I'm using a local VMwareFusion vm instead of Docker or something because I want to be able to test with a video device.
# New install
# (not shown) make account, enable ssh, add vm to /etc/hosts
ssh vm
apt-get update
sudo apt install git
git clone
thomasballinger / cell_invalidation.ipynb
Created Feb 1, 2020
sketch of noticing that a cell has been removed or reexecuted. Useful for stopping timers, removing event listeners, etc.
View cell_invalidation.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
thomasballinger / invalidation.js
Created Feb 5, 2020
invalidation of Jupyter notebook cells
View invalidation.js
// Find deepest DOM ancestor that does not change on reexecute
const findParentOutputDiv = (el) => {
let candidate = el;
while (candidate) {
candidate = candidate.parentElement
if (candidate.className === 'output') {
return candidate;
throw Error("parent output div not found");
import socket
import select
import sys
clients = []
server = socket.socket()
server.bind(('', 8001))
View browserCanvasCtxFill.html
<canvas id="canvas1" width="200" height="200"></canvas>
<canvas id="canvas2" width="200" height="200"></canvas>
<canvas id="canvas3" width="200" height="200"></canvas>
var canvases = [canvas1, canvas2, canvas3]
var fillArgs = [undefined, 'evenodd', 'nonzero']