Skip to content

Instantly share code, notes, and snippets.

def parseParams(path:String):Map[String,Array[String]] = {
for {
pair <- path.split('/').toList.tail.zipWithIndex.filter(part => placeholders.exists(place => part._2 == place))
} yield (parts(pair._2) -> Array(pair._1))
}
//[error] /Users/alan/Projects/scala/step/./src/main/scala/Step.scala:34: type mismatch;
//[error] found : List[(String, Array[String])]
//[error] required: Map[String,Array[String]]
//[error] pair <- path.split('/').toList.tail.zipWithIndex.filter(part => placeholders.exists(place => part._2 == place))
import scala.actors.Actor
import scala.actors.Actor._
import java.net.{InetAddress,ServerSocket,Socket,SocketException}
import java.io._
import scala.xml._
//case classes
case class Request(s:Socket)
// actor definition
@alandipert
alandipert / mmap example
Created June 12, 2009 12:56
mmap character reading example
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
//takes a filename as 1st argument
//opens it, and mmaps the whole thing.
import scala.actors.Actor
import scala.actors.Actor._
import java.net.{InetAddress,ServerSocket,Socket,SocketException}
import java.io._
case class Start(m:String)
case class Request(s:Socket)
object Qbert extends Actor {
@alandipert
alandipert / componentize.rb
Created June 25, 2009 17:51 — forked from anonymous/componentize.rb
ruby script for turning golf component tree into components.js
#!/usr/bin/env ruby
require 'rubygems'
require 'json'
# given a components directory, poop a components.js to stdout
raise(ArgumentError, "target dir is required") unless cdir = ARGV[0]
exts = ["css", "html", "js", "res"]
puts "jQuery.golf.components="+Hash[*exts.collect{|e|
def bit
"%0160b" % to_i(16)
end
def distance(word1, word2)
word1, word2 = word1.bit, word2.bit
distance = 0
word1.chars.zip(word2.chars) do |char1, char2|
puts "#{char1} | #{char2}"
distance += 1 unless char1 == char2
scala> def List(op:(Double,Double)=>Double, n:Double*) = n.reduceLeft(op(_,_))
List: ((Double, Double) => Double,Double*)Double
scala> List(_+_,1,2,List(_*_,3,3))
res32: Double = 12.0
<?php
include 'functional.php';
mail(
"alan.dipert@gmail.com",
"Simplerochester.com Submission",
implode(
"\n",
map(
<?php
function lambda() {
if(func_num_args() > 1) {
$func = func_get_arg(1);
if($func[strlen($func)-1] != ';')
$func = $func.';';
return create_function(func_get_arg(0), 'return '.$func);
} else {
$func = func_get_arg(0);
#!/usr/bin/env bash
# On Macs, you need to install growlnotify: http://growl.info/documentation/growlnotify.php
# and put it in your PATH somewhere.
function usage() {
echo "tailnote file [regex]"
echo
echo "Tail a file and show notifications using Growl or Mumbles for lines matching regex."
echo "If a regex is not provided, this will notify about all lines."
echo