Skip to content

Instantly share code, notes, and snippets.

View wspringer's full-sized avatar

wilfred@eastpole.nl wspringer

View GitHub Profile
@wspringer
wspringer / gist:986713
Created May 23, 2011 13:47
Just in case we ever need absolute URLs
/**
* Drop in replacement for the original {{ExtensibleReadability}} class, allowing us to add some of our own processing. (Like augmenting image URLs
* .)
*/
class UltimateReadability(base: String) extends ExtensibleReadability with Logging {
val baseURI = URI.create(base)
val uriConversion = catching(classOf[IllegalArgumentException])
override def cleanup(document: JSoupDocument) {
@wspringer
wspringer / dpkg.rb
Created May 31, 2011 06:21
Modified version of the dpkg formula, to include start-stop-daemon
require 'formula'
class Dpkg <Formula
url 'http://ftp.debian.org/debian/pool/main/d/dpkg/dpkg_1.15.8.10.tar.bz2'
homepage 'http://en.wikipedia.org/wiki/Dpkg'
md5 'bce745c7083ace01da1df6cdcad35f9a'
def patches
#Fixes the PERL_LIBDIR
DATA
@wspringer
wspringer / gist:1028893
Created June 16, 2011 08:33
Setting up resourceHandler
private Handler addResourceHandler(Handler handler, File directory, final String index) throws Exception {
final HandlerList list = new HandlerList();
ContextHandler contextHandler = new ContextHandler("/resources");
contextHandler.setHandler(createResourceHandler(directory));
if (index != null) {
list.addHandler(new AbstractHandler() {
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if ("/".equals(target)) {
response.sendRedirect(index);
@wspringer
wspringer / gist:1075779
Created July 11, 2011 12:59
How we thought it would work?
// Trait
trait EventLoggerComponent {
val eventProcessor: EventProcessor
trait EventLogger {
}
}
@wspringer
wspringer / gist:1075790
Created July 11, 2011 13:05
Other attempt
// SearchService #2
class SearchService(implicit eventProcessor: EventProcessor) extends EventLogger
// EventLogger
trait EventLogger {
val eventProcessor: EventProcessor
}
// Context
class Context extends ... with ... with .. {
@wspringer
wspringer / gist:1649700
Created January 20, 2012 21:28
LZW Encoding *and Decoding* in Scala
object lzw {
trait Appendable[T] {
def append(value: T)
}
import scala.collection.generic._
case class GrowingAppendable[T](growable: Growable[T]) extends Appendable[T] {
def append(value: T) {
growable += value
@wspringer
wspringer / dashboard.haml
Created March 25, 2012 20:29
Super compact JMX dashboard, based on Jolokia, ICanHaz and HAML
!!!
%html
%head
%title JMX Console
%script(src="js/ICanHaz.min.js" language="javascript")
%script(src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" language="javascript")
%script(src="js/json2.js" language="javascript")
%script(src="js/jolokia-min.js" language="javascript")
%script(src="js/jolokia-simple-min.js" language="javascript")
%link(href="css/style.css" rel="stylesheet" type="text/css")
@wspringer
wspringer / jaro.scala
Created July 2, 2012 10:56
Jaro distance in Scala
import math._
object Jaro {
def distance(first: String, second: String) = {
val maxLength = max(first.length, second.length)
val maxDistance = (maxLength / 2) - 1
var matches = 0
var halfTranspositions = 0
for (i <- 0 until first.length) {
@wspringer
wspringer / Tuple2Traversable.scala
Created October 10, 2012 21:00
Need something that wraps a traversable collection of tuples. Does this approach make sense at all?
/**
* A Traversable-alike abstraction of a traversable collection of tuples, without actually creating the tuples.
* I'd hope this would prevent me from polluting the heap with actual Tuple2 instances I never actually need.
*/
trait Tuple2Traversable[+A, +B] {
def foreach[T](fn: (A, B) => T)
def map[T](fn: (A, B) => T): Traversable[T] = new Traversable[T] {
def foreach[U](f: (T) => U) {
import Cocoa
enum Try<T>: Printable, DebugPrintable {
// Captures a successful outcome
case Success(@autoclosure() -> T)
// Captures a failure, including the root cause, which for now can be anything
case Failure(Any)