Skip to content

Instantly share code, notes, and snippets.

=begin
Sample buildfile for akka-sample-chat (akka 0.6).
Save as akka-0.6/akka-samples/akka-sample-chat/Buildfile
Shell #1:
% export AKKA_HOME=...
% cd $AKKA_HOME
% java -jar dist/akka-0.6.jar
Shell #2:
Interactive example:
Welcome to Scala version 2.8.0.Beta1-prerelease (Java HotSpot(TM) Server VM, Java 1.6.0_17).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :load MapReduce.scala
Loading MapReduce.scala...
defined class MapReduce
require 'rubygems'
require 'oauth'
require 'oauth/consumer'
require 'json'
key = 'xxxxxxxx'
secret = 'yyyyyyyy'
consumer = OAuth::Consumer.new(key, secret, {
:site => "http://api.bizographics.com",
/** Fixed point combinator: The essence of recursion */
def fix[T, R](f: (T => R) => (T => R)): (T => R) = new Function1[T, R] {
def apply(t: T): R = f(this)(t)
}
/** Factorial definition with fixed point */
def factorial(recursive: Long => Long) = (x: Long) => x match {
case 1 => 1
case x => x * recursive(x-1)
}
#!/usr/bin/env ruby
require 'optparse'
# Parse arguments
OPTIONS = {}
op = OptionParser.new do |x|
x.banner = 'killjava [-9] [-n] [java_main_class]'
x.separator ''
x.on("-9", "--KILL", "Send KILL signal instead of TERM") do
@aboisvert
aboisvert / gist:629126
Created October 15, 2010 23:09
How to run jetty
*{toc}*
----
Basically you can run jetty in two different modes:
# Interactively: use s.th. like {{buildr yourproject:run-jetty}} and have the jetty running within this shell, so that you see the output of jetty and your app
# In the background: use {{buildr jetty:start}} and {{buildr yourproject:deploy-app}} to start jetty in the background and deploy your app. The build is not blocking in this case and you can use your shell for different things.
@aboisvert
aboisvert / Generator.scala
Created November 10, 2010 21:51
Python-style generator in Scala
class Generator[T] extends Iterable[T] {
val buffer = scala.collection.mutable.ArrayBuffer[() => Iterable[T]]()
protected def <<(t: => T) { buffer += (() => List(t)) }
protected def <<<(t: => Iterable[T]) { buffer += (() => t) }
override def iterator = buffer.toStream.flatMap(_.apply).iterator
}
@aboisvert
aboisvert / Employee.scala
Created December 21, 2010 15:44
When do we get first-class properties in Scala???
class Employee(var employer: Employer)
class Employer(var name: String)
object Test {
import Properties._
// killer boilerplate of death !!!
val name1 = property(
@aboisvert
aboisvert / stashboard-pingdom.rb
Created May 16, 2011 19:28
Stashboard <-> Pingdom Integration
#!/usr/bin/env ruby
require 'time'
require 'logger'
require 'rubygems'
require 'pingdom-client'
require 'active_support/core_ext/numeric/time' # time extensions, e.g., 5.days
require 'stashboard'
TIME_FORMAT = "%Y-%m-%d %H:%M:%S %Z" # YYYY-MM-DD HH:MM:SS ZZZ
@aboisvert
aboisvert / union.scala
Created June 9, 2011 18:06
Union Type + Specialized
object Union {
type ¬[A] = A => Nothing
type ¬¬[A] = ¬[¬[A]]
type ∨[T, U] = ¬[¬[T] with ¬[U]]
type |∨|[T, U] = { type λ[X] = ¬¬[X] <:< (T ∨ U) }
def size[@specialized(Int) T : (Int |∨| String)#λ](t : T) = t match {
case i : Int => i
case s : String => s.length
}