Skip to content

Instantly share code, notes, and snippets.

View sporkmonger's full-sized avatar

Bob Aman sporkmonger

View GitHub Profile
type expr =
Noop
| Int of int
| Float of float
| Seq of expr list
| Call of expr * string * expr (* * params *)
let print_ast ast =
let rec print_ast_internal = function
Noop -> "Noop"
let double x = 2 * x;;
let sum x y = x + y;;
(* How do you get a function 2(x + y) from this? *)
let foo = double sum;; (* Obviously doesn't work *)
package com.sporkmonger.util;
import java.net.URL;
import java.util.ArrayList;
public class HydraLoader extends ClassLoader {
private ArrayList<ClassLoader> childLoaders = new ArrayList<ClassLoader>();
public HydraLoader() {
super();
@sporkmonger
sporkmonger / ANSILineStyler.java
Created May 17, 2009 18:10
Use this to give any StyledText widget decent ANSI color support; could use optimization, please fork; WTFPL license
package com.sporkmonger.rmud.swt.custom;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.LineStyleEvent;
import org.eclipse.swt.custom.LineStyleListener;
import org.eclipse.swt.custom.StyleRange;
require "sync"
require "blankslate"
class Channel < BlankSlate
def initialize
@sync = Sync.new
@queue = []
end
def queue
# Author: Cyril Rohr
# This has been gemified into the cacheability gem (http://github.com/cryx/cacheability/tree/master)
require 'rubygems'
require 'rest_client' # sudo gem install rest-client
require 'rack/cache' # sudo gem install rack-cache
require 'addressable/uri' # sudo gem install addressable
module RestClient
# this is a quick hack to show how you can use rack-cache as a powerful client cache.
# BAD:
foo.bar = 25
foo.biz = 'Hello World'
foo.bazzle = 42
# GOOD:
foo.bar = 25
foo.biz = 'Hello World'
foo.bazzle = 42
>> "///".gsub(%r{/*$}, ".")
=> ".."
>> "//".gsub(%r{/*$}, ".")
=> ".."
>> "/".gsub(%r{/*$}, ".")
=> ".."
>> "".gsub(%r{/*$}, ".")
=> "."
@sporkmonger
sporkmonger / case_insensitive_hash.rb
Created December 9, 2008 17:43
CaseInsensitiveHash
##
# This Hash subclass stores keys in a case-insensitive manner.
class CaseInsensitiveHash < Hash
##
# @see Hash#[]
def [](key)
return super(key.downcase)
end
##
From 044bd08970c8f5475c53b62a003c332543b7aa71 Mon Sep 17 00:00:00 2001
From: Bob Aman <[email protected]>
Date: Thu, 4 Dec 2008 16:20:45 -0500
Subject: [PATCH] Fixed issue with indexing models with non-numeric id values.
---
lib/acts_as_xapian.rb | 17 ++++++++++++-----
1 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/lib/acts_as_xapian.rb b/lib/acts_as_xapian.rb