Skip to content

Instantly share code, notes, and snippets.

View sporkmonger's full-sized avatar

Bob Aman sporkmonger

View GitHub Profile
@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
##
>> "///".gsub(%r{/*$}, ".")
=> ".."
>> "//".gsub(%r{/*$}, ".")
=> ".."
>> "/".gsub(%r{/*$}, ".")
=> ".."
>> "".gsub(%r{/*$}, ".")
=> "."
# BAD:
foo.bar = 25
foo.biz = 'Hello World'
foo.bazzle = 42
# GOOD:
foo.bar = 25
foo.biz = 'Hello World'
foo.bazzle = 42
# 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.
require "sync"
require "blankslate"
class Channel < BlankSlate
def initialize
@sync = Sync.new
@queue = []
end
def queue
@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;
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();
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 *)
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"
require "datamapper"
class CrawledURI
include DataMapper::Resource
STORAGE_NAME = "crawled_uris"
property :id, Integer, :serial => true
# Data
property :uri, String, :length => 1024