Skip to content

Instantly share code, notes, and snippets.

View kputnam's full-sized avatar
💭
I have 478 browser tabs open

kputnam kputnam

💭
I have 478 browser tabs open
View GitHub Profile
@kputnam
kputnam / worker-group.js
Created November 4, 2011 22:05
Group of Asynchronous Workers
/**
* Starts all workers at once and executes the given afterFinish
* callback when all workers have completed. Workers are expected
* to signal when they are finished.
*
* @example
*
* WorkerGroup(
* [ function(whenDone) { $.ajax({url: 'http://jquery.com/a/', error: whenDone, success: whenDone}); }
* , function(whenDone) { $.ajax({url: 'http://jquery.com/b/', error: whenDone, success: whenDone}); }
object Unfold {
/**
* Builds a list by recursively applying `f`, until `f` returns None
*
* @param seed the initial value passed to `f`
* @param f returns Some(Pair(element, nextSeed)) where `element` is added
* to the list and `nextSeed` is passed to `f` on the next invocation.
*/
def buildList[T, R](seed: T)(f: T => Option[Pair[R, T]]): List[R] =
@kputnam
kputnam / SqlParser.scala
Created October 19, 2010 19:11
Parses a trivial subset of SQL
trait SqlParser extends scala.util.parsing.combinator.RegexParsers {
// ignore ordinary whitespace, line comments, and inline comments between combinators
override val whiteSpace = "(?sm)(\\s*(?:--.*?$|/\\*((?!\\*/).)*\\*/)\\s*|\\s+)+".r
def sqlStatement: Parser[Statement] =
opt(whiteSpace) ~> positioned( procedureCallStatement
| insertStatementCustom
| insertStatement
| updateStatement