Skip to content

Instantly share code, notes, and snippets.

Avatar

Toby Jungen toluju

View GitHub Profile
@toluju
toluju / barbershop.scala
Created Jan 18, 2011
A better scala barbershop simulator.
View barbershop.scala
import scala.actors.Actor
import scala.actors.Actor._
import scala.util.Random
import scala.collection.{immutable, mutable}
val rand = new Random()
case class Customer(id: Int) {
var shorn:Boolean = false
}
@toluju
toluju / delicious2google.rb
Created Dec 17, 2010
Delicious is shutting down, so here's a script to load the exported delicious bookmarks into Google Bookmarks.
View delicious2google.rb
require 'net/http'
require 'uri'
require 'cgi'
text = "<html><head><title>Delicious2Google</title></head><body>" +
"<h1>Upload</h1>" +
"<form action='https://www.google.com/bookmarks/mark?op=upload&zx=#{rand(65535)}' method='POST'>" +
"<input type='submit'/><input type='hidden' id='data'></form>" +
"<textarea id='xml' style='display:none'>\n<bookmarks>"
@toluju
toluju / gist:561592
Created Sep 1, 2010
Generic Exceptions suck
View gist:561592
public interface Request<R, E extends Exception> {
public R process() throws E;
}
public class Processor {
public <R, E extends Exception> R process(Request<R, E> request) throws E {
E lastException = null;
for (int x = 0; x < retries; ++x {
try {
return request.process();
View ThreadPipeIterator.java
import java.io.IOException;
import java.util.Random;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.io.Closeable;
/**
* @author Toby
*/
public abstract class ThreadPipeIterator<T> implements Iterator<T>, Closeable {
View cod09.rb
require 'net/http'
require 'uri'
require 'json'
languages = ["java", "c++", "c", "perl", "ruby", "python", "javascript", "html", "css",
"scala", "xml", "xslt", "xquery", "php", "actionscript", "flash", "flex",
"vbscript", "applescript", "erlang", "objective-c", "smalltalk", "haskell",
"c#", "boo", "f#", "go", "processing", "arduino", "pd", "qc", "vimscript",
"as3", "assembly", "sh", "obj-c", "sql", "coldfusion", "lex", "yacc",
"scheme", "lisp", "bourne", "awk", "tcl", "d", "ocaml", "elisp", "clojure",
View gist:239889
#include <stdio.h>
class Node {
public:
int value;
Node* left;
Node* right;
Node() {
left = NULL;
You can’t perform that action at this time.