Skip to content

Instantly share code, notes, and snippets.

View quad's full-sized avatar

Scott Robinson quad

View GitHub Profile
@quad
quad / icake.py
Created December 14, 2016 01:18
Interview Cake Solutions
import typing
import unittest
class TreeNode:
def __init__(self, left=None, right=None):
self.left = left
self.right = right
def is_superbalanced(self):
@quad
quad / zim-to-sn.rb
Created November 1, 2010 14:25
Import a (my) Zim notebook to Simplenote
#!/usr/bin/env ruby
require 'json'
require 'Simplenote'
class ZimDirectory < Hash
class ZimException < Exception
end
attr_reader :dir
@quad
quad / jshint-runner.js
Created April 23, 2013 04:58
A phantomjs runner for JSHint
// PhantomJS doesn't support bind yet
Function.prototype.bind = Function.prototype.bind || function (thisp) {
var fn = this;
return function () {
return fn.apply(thisp, arguments);
};
};
(function(p) {
var fs = require('fs'),
@quad
quad / Sanke.pas
Last active December 18, 2015 01:39
SANKE THE SNAKE By Brandon Ethakada & Tai Bell-Liu 10J Ported Scott Robinson
program YearTenComputerSystemsProjectByBrandonEthakadaAndTaiBellLiu;
uses ptccrt, ptcgraph;
var keyz : string;
selection,speed : integer;
procedure InitIt;
var gd, gm : integer;
begin
Gd := d8bit;
Gm := m640x480;
@quad
quad / mini-proof.rb
Created May 10, 2013 05:18
A (probably incorrect) proof of work system based on my understanding of Hashcash. For instructional purposes only!
require 'digest/sha1'
class Proof < Struct.new :data, :difficulty, :token
def valid?
hash = Digest::SHA1.hexdigest("#{data} #{difficulty} #{token}")
pl = prefix_length(hash.to_i(16))
difficulty <= pl
end
def increment
@quad
quad / dci_spec.rb
Last active December 10, 2015 19:48
Working through the DCI example from Singapore Ruby (2013-1-8)
require 'minitest/autorun'
class Account < Struct.new :balance
end
class MoneyTransfer < Struct.new :source, :destination
def initialize source, destination
super
source.extend Transferrer
end
@quad
quad / lr.c
Created October 31, 2012 02:24
Local Register
#include <arpa/inet.h>
#include <errno.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <dns_sd.h>
void callback(DNSServiceRef sdRef,
@quad
quad / pecha.rb
Created August 10, 2012 05:51
Discrimination made easy!
NUM_POOLS = 5
Grad = Struct.new :name, :gender, :region
def norm_name first, last
"#{first.strip} #{last.strip}"
end
def norm_gender gender
{'M' => 'Male', 'F' => 'Female'}[gender] || gender
@quad
quad / lockit.sh
Created June 29, 2012 09:32
Achtung: a not very nice hotdog
#!/bin/sh
#
# We have a few repeat customers here at the TWU 27 hotdog shack.
#
# They've decided it's FUN to visit our stand.
#
# So, we've cooked up something a little special for our valued customers.
set -e
@quad
quad / tie.js
Created May 27, 2012 21:45
Retarded simple event-binding "DSL"
/*
Retarded simple event-binding "DSL"
Best with:
* jQuery (or Zepto)
* event_emitter
https://github.com/ajaxorg/ace/blob/master/lib/ace/lib/event_emitter.js
Usage:
tie($(window), "hashchange")