Skip to content

Instantly share code, notes, and snippets.

View tuzz's full-sized avatar

Chris Patuzzo tuzz

View GitHub Profile
@tuzz
tuzz / lookup_table.rb
Created October 21, 2012 14:50
Pangrammic Lookup Table
require 'numbers_and_words'
def lookup_table(limit = 64)
[nil] + (1..limit).map do |i|
word = i.to_words
('a'..'z').map do |c|
('a'..'z').map do |l|
count = word.count(l)
# plural
@tuzz
tuzz / priority_calculator.rb
Created October 31, 2012 18:48
Priority Calculator
# Calculates the priority for a vector of ranges.
# Favours those that are similar to a probability density.
# Lower is better.
require 'canberra_distance'
require 'frequency_analyser'
class PriorityCalculator
def initialize(params = {})
@tuzz
tuzz / main.c
Created November 14, 2012 20:20
Compiling OpenGL + GLUT natively on Mac OS X
// gcc main.c -O3 -framework GLUT -framework OpenGL && ./a.out
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
// ...
@tuzz
tuzz / bootstrap.rb
Created March 15, 2013 19:44
A useful bootstrap for Vim / Ruby gem development.
# Run :ruby load "bootstrap.rb" in Vim to re-source your gem.
NAME ||= File.basename(Dir.getwd)
$".reject! { |f| f =~ /#{NAME}/ }
$:.unshift("lib") unless $:.include?("lib")
require NAME
Vim.command("command! B :ruby load '#{__FILE__}'")
@tuzz
tuzz / convert.sh
Last active December 15, 2015 20:59
The PS3 can't play MKVs over my minidlna server. This script attempts to convert to mp4. I run this in cron.
%!/bin/bash
previous=IFS
IFS=$(echo -en "\n\b")
for file in `find /media/hdd -iname '*.mkv'`
do
if [ ! -f "$file.mp4" ];
then
echo "Converting $file..."
@tuzz
tuzz / twosComplement.js
Created December 27, 2015 19:51
Encode and Decode integers to and from twos complement in JavaScript
"use strict";
var _ = require("underscore");
var TwosComplement = {};
TwosComplement.encode = function (n) {
var binary, array;
if (n < 0) {
@tuzz
tuzz / isbnSpec.js
Created March 16, 2016 21:25
A Sentient program to convert 10-digit ISBNs to 13-digits
"use strict";
var Sentient = require("../../lib/sentient");
describe("ISBN", function () {
var machineCode = Sentient.compile({
instructions: [
{ type: "integer", symbol: "ten0", width: 5 },
{ type: "integer", symbol: "ten1", width: 5 },
{ type: "integer", symbol: "ten2", width: 5 },
@tuzz
tuzz / riss-427-mac-os-x.patch
Created May 30, 2016 11:09
Port Riss 4.27 and Coprocessor to Mac OS X
From efc06ffab5435b4686f3889167a7d5260de4e1fe Mon Sep 17 00:00:00 2001
From: Chris Patuzzo <chris@patuzzo.co.uk>
Date: Mon, 30 May 2016 11:59:11 +0100
Subject: [PATCH 1/1] Port Riss 4.27 and Coprocessor to Mac OS X
---
Makefile | 5 ++---
coprocessor-src/BoundedVariableEliminationParallel.cc | 2 +-
coprocessor-src/Coprocessor.cc | 9 +--------
coprocessor-src/Coprocessor.h | 12 +++++-------
@tuzz
tuzz / combinations_spec.rb
Created July 22, 2016 14:32
Generates combinations from an array
require "rspec"
def combinations(array, length)
if length.zero?
[[]]
else
array.flat_map.with_index do |element, index|
tail = array[(index + 1)..-1]
combinations(tail, length - 1).map do |combination|
@tuzz
tuzz / N=200
Last active August 14, 2016 00:11
N=200
For which N is there a permutation of {1,...,N} s.t. termwise sum with {1,...,N} gives all squares?
Here's a solution for N=200, solved with http://sentient-lang.org/
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120,