Skip to content

Instantly share code, notes, and snippets.

View nat-n's full-sized avatar
🏠
Working from home

Nat Noordanus nat-n

🏠
Working from home
View GitHub Profile
@nat-n
nat-n / volume_stamper.py
Last active December 17, 2015 11:49
Takes a *stamp* volume file (such as a single label image of an oil capsule on the left side of the temple) and adds it to each image in the input directory and writes the resulting images to the output directory. The stamp file must match the dimensions of all the image files.
#!/usr/bin/python
# created on 18/5/13 by Nat Noordanus [email protected]
import os, argparse
parser = argparse.ArgumentParser()
parser.add_argument("input_dir")
parser.add_argument("stamp_file")
@nat-n
nat-n / read_variable_length_integer_file.js
Last active December 30, 2015 15:19
A proof of concept script for streaming a binary file of variable length integers through a nodejs context.
var fs, vi, sys, rs, bufferSize, remainder, startTime;
startTime = Date.now();
fs = require('fs');
vi = require('varint');
sys = require('sys');
rs = fs.createReadStream('/path/to.file');
total = 0;
@nat-n
nat-n / analyze_pi.rb
Last active December 31, 2015 10:38
Analyses the first 100 billion digits of pi to determine the greatest number of decimal places separating consecutive occurrences of the same digit. The purpose is to discover the first gap of more than 255 decimal places between consecutive occurrences of a base 10 digit in pi. Downloads segments of 100 000 000 digits at a time as zipped text f…
#!/usr/bin/env ruby
# encoding: utf-8
#
# Created by Nat Noordanus on 2013-12-13.
# Description:
# Analyses the first 100 billion digits of pi to determine the greatest number
# of decimal places separating consecutive occurrences of the same digit.
# The purpose is to discover the first gap of more than 255 decimal places
# between consecutive occurrences of a base 10 digit in pi.
@nat-n
nat-n / work_queue.rb
Last active August 29, 2015 14:00
A simple Ruby class for managing work queues to be run in series or in parallel.
class WorkQueue
attr_reader :result
def initialize
@q = []
end
def push &block
@q << block
@nat-n
nat-n / dserver.rb
Created May 3, 2014 21:17
An experimental class wrapping druby to make it easy to spawn and control Distributed Ruby servers from within a ruby context. Thus allowing a ruby program to relatively painlessly spawn and control "worker" subprocesses.
#!/usr/bin/env ruby
require 'tempfile'
require 'drb/drb'
class DServer
attr_reader :active_server
attr_reader :service
@nat-n
nat-n / three-value-toggle.html
Created June 16, 2014 15:21
A javascript and styles to implement a new input type which resembles a checkbox but with three arbitrary values instead of just two.
<html>
<head>
<meta charset="UTF-8">
<title>Three Value Toggle</title>
</style>
</head>
<body>
<input name="foo" type="tvg" value="Maybe">
<input name="bar" type="tvg" value="True">
@nat-n
nat-n / bitwiseAddition.js
Last active August 29, 2015 14:10
Implementing naive integer addition from bitwise operators in javascript.
function add(a,b){
var x, o;
do {
x = a & b;
o = a | b;
a = o ^ x;
b = x << 1;
} while (x)
return o;
@nat-n
nat-n / tmux_recipes.md
Last active August 29, 2015 14:16
tmux recipes

Programatically setup up session with splitpane window with different REPLs

tmux new-session -d -s repls 'irb'
tmux send-keys 'p "Hello Ruby!"' C-m
tmux rename-window 'Repls'
tmux select-window -t 'Repls'
tmux split-window -h 'python'
tmux send-keys 'print "Hello Python!"' C-m
tmux split-window -v -t 0 'node'

tmux send-keys 'console.log("Hello node!")' C-m

@nat-n
nat-n / Recipe-bundling-fonts-with-headless-chrome.md
Last active February 28, 2024 19:23
How to build a fontconfig bundle for adding arbitrary fonts to headless chrome independent of the OS. This is specifically useful for deploying headless chrome to AWS lambda where it is necessary to include fonts for rendering CJK (Chinese, Japanese, Korean) characters into the deployed bundle.

Building fontconfig

Start up a lambda-like docker container:

docker run -i -t -v /tmp:/var/task lambci/lambda:build /bin/bash

Install some dependencies inside the container:

yum install gperf freetype-devel libxml2-devel git libtool -y

easy_install pip

@nat-n
nat-n / CircularBuffer.swift
Created June 3, 2018 20:24
CircularBuffer implementation in Swift 4
public struct CircularBuffer<T>: Collection, CustomStringConvertible {
private var cursor: Int = 0
private var contents: [T] = []
let capacity: Int
public init(capacity: Int) {
self.capacity = capacity
}
public subscript(i: Int) -> T {