Skip to content

Instantly share code, notes, and snippets.

@briangordon
briangordon / Text to pixel array
Created March 10, 2013 06:09
HTML5 JavaScript snippet for turning arbitrary text into a binary array of pixel on/off
var buffer = document.createElement('canvas');
var bufContext = buffer.getContext("2d");
buffer.width = 60;
buffer.height = 20;
bufContext.fillStyle = "#FFFFFF";
bufContext.fillRect(0, 0, 60, 20);
bufContext.textBaseline = "top";
@briangordon
briangordon / gist:3382806
Last active October 8, 2015 20:08
JavaScript n-queens solution generator. This was written for an hour-long contest, so it's super sloppy.
var n = 40;
// Each row has exactly one queen. We have to determine which column to place each queen in.
var board = [];
function initBoard() {
// Put one queen in each row
board = [];
for(var row = 0; row < n; row++) {
board[row] = [];
@briangordon
briangordon / RecursiveThreadPoolExecutor.java
Created May 3, 2012 01:04
A ThreadPoolExecutor that shuts down when it runs out of tasks.
public class RecursiveThreadPoolExecutor extends ThreadPoolExecutor {
private AtomicInteger count;
public RecursiveThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
count = new AtomicInteger(0);
}
public void execute(Runnable command) {