Skip to content

Instantly share code, notes, and snippets.

@jrudolph
jrudolph / TowersOfHanoi.scala
Created February 19, 2009 13:51
Scala-Metaprogramming: Towers of Hanoi
/*
* This is the Towers of Hanoi example from the prolog tutorial [1]
* converted into Scala, using implicits to unfold the algorithm at
* compile-time.
*
* [1] http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/2_3.html
*/
object TowersOfHanoi {
import scala.reflect.Manifest
package iwsexample
import scala.actors._
import scala.actors.Actor._
import scala.actors.Futures._
import scala.collection.mutable._
case class RegisterWorker (worker:Worker)
case class UnregisterWorker (worker:Worker)
case class SortList (data:List[Int])
@gnip
gnip / Twitter (json format).js
Created January 4, 2011 00:49
Twitter Sample Payload, JSON format
{
"coordinates": null,
"created_at": "Thu Oct 21 16:02:46 +0000 2010",
"favorited": false,
"truncated": false,
"id_str": "28039652140",
"entities": {
"urls": [
{
"expanded_url": null,
@mrflip
mrflip / gist:766608
Created January 5, 2011 17:15
Elasticsearch shell config
We couldn’t find that file to show.
@josiahcarlson
josiahcarlson / redis_simple_chat.py
Created June 24, 2011 22:07
A way of implementing a poll-based chat inside Redis
'''
redis_simple_chat.py
Written June 24, 2011 by Josiah Carlson
Released under the GNU GPL v2
available: http://www.gnu.org/licenses/gpl-2.0.html
Other licenses may be available upon request.
@kedarbellare
kedarbellare / ThresholdLevenshtein.scala
Created September 14, 2011 15:14
Scala implementation of threshold edit distance
def thresholdLevenshtein(_s: String, _t: String, threshold: Int): Int = {
val (s, t) = if (_s.length > _t.length) (_s, _t) else (_t, _s)
val slen = s.length
val tlen = t.length
var prev = Array.fill[Int](tlen+1)(Int.MaxValue)
var curr = Array.fill[Int](tlen+1)(Int.MaxValue)
for (n <- 0 until math.min(tlen+1, threshold+1)) prev(n) = n
for (row <- 1 until (slen+1)) {
@dcj
dcj / StormBuildLion
Created September 19, 2011 20:42
Getting Storm to build on Mac OS X Lion
Note: When I started, JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
$ git clone https://github.com/nathanmarz/jzmq.git
Cloning into jzmq...
remote: Counting objects: 611, done.
remote: Compressing objects: 100% (204/204), done.
remote: Total 611 (delta 317), reused 570 (delta 292)
Receiving objects: 100% (611/611), 304.06 KiB | 298 KiB/s, done.
Resolving deltas: 100% (317/317), done.
@tixxit
tixxit / EditDistance.scala
Created September 28, 2011 03:10
Short Levenshtein distance implementation in Scala
package net.tixxit.levenshtein
import scala.math.min
object EditDistance {
def editDist[A](a: Iterable[A], b: Iterable[A]) =
((0 to b.size).toList /: a)((prev, x) =>
(prev zip prev.tail zip b).scanLeft(prev.head + 1) {
case (h, ((d, v), y)) => min(min(h + 1, v + 1), d + (if (x == y) 0 else 1))
}) last
@quinn
quinn / ubuntu-neo4j.sh
Created October 23, 2011 16:33
neo4j on ubuntu
sudo apt-get install openjdk-6-jre-headless
curl -O http://dist.neo4j.org/neo4j-community-1.5.M02-unix.tar.gz
tar -xf neo4j-community-1.5.M02-unix.tar.gz
rm neo4j-community-1.5.M02-unix.tar.gz
neo4j-community-1.5.M02/bin/neo4j start
@timcowlishaw
timcowlishaw / Trie.scala
Created November 14, 2011 10:06
A Trie (Prefix-tree) implementation in Scala
package uk.ac.ucl.cs.GI15.timNancyKawal {
class Trie[V](key: Option[Char]) {
def this() {
this(None);
}
import scala.collection.Seq
import scala.collection.immutable.TreeMap
import scala.collection.immutable.WrappedString