Skip to content

Instantly share code, notes, and snippets.

@jrudolph
jrudolph / wello.scala
Created June 16, 2011 09:49
Wello Horld
\u006f\u0062\u006a\u0065\u0063\u0074\u0020
\u0057\u0065\u006c\u006c\u006f\u0048\u006f\u0072\u006c\u0064\u0020
\u0065\u0078\u0074\u0065\u006e\u0064\u0073\u0020
\u0041\u0070\u0070\u0020\u007b\u000a\u0020
\u0020\u0070\u0072\u0069\u006e\u0074\u006c\u006e\u0028
\u0022\u0057\u0065\u006c\u006c\u006f\u0048\u006f\u0072\u006c\u0064\u0022
\u0029\u000a\u007d\u000a
@jrudolph
jrudolph / ExistentialsConsideredHarmful.scala
Created June 27, 2011 14:00
Existentials considered harmful
object ExistentialsConsideredHarmful {
class Animal(val name: String)
object Dog extends Animal("Dog")
object Sheep extends Animal("Sheep")
trait Tools[A] {
def shave(a: A): A
}
def tools[A](a: A): Tools[A] = null // dummy
case class TransportBox[A <: Animal](animal: A, tools: Tools[A]) {
@jrudolph
jrudolph / Ordering.scala
Created June 29, 2011 13:53
Custom Orderings
sealed abstract class Bound[+T] { val value : T }
case class Closed[T : Ordering](value : T) extends Bound[T]
case class Opened[T : Ordering](value : T) extends Bound[T]
object Bound {
implicit def ordering[T: Ordering]: Ordering[Bound[T]] = Ordering.by((_: Bound[T]).value)
}
object BoundDemo {
def main(args : Array[String]) : Unit = {
@jrudolph
jrudolph / LazyValLock.scala
Created July 11, 2011 14:51
LazyVal Locking
trait Holder {
def x: String
def y: Int
def getX = {
println("While initializing x")
Thread.sleep(5000);
println("Finished initializing x")
null
}
@jrudolph
jrudolph / gist:1097283
Created July 21, 2011 14:18
Show the non-Existential Of God
abstract class Action
case object Eat extends Action
case object Speak extends Action
case object Move extends Action
abstract class Creature (val action: Action)
case class Fish (a: Action, val size: String) extends Creature (a)
case class Dog (a: Action, val sound: String) extends Creature (a)
@jrudolph
jrudolph / Boot.scala
Created August 5, 2011 08:20
Custom error handling in spray example calculator
package cc.spray.examples.calculator
import akka.config.Supervision._
import akka.actor.Supervisor
import akka.actor.Actor._
import cc.spray._
import utils.ActorHelpers._
class Boot {
@jrudolph
jrudolph / output.txt
Created September 13, 2011 20:06
dalvikvm output
D/dalvikvm(14165): DexOptY: --- BEGIN 'classes.jar' (bootstrap=0) ---
D/dalvikvm(14166): creating instr width table
D/dalvikvm(14166): --- LinearAllocV(interfaces, 0x0, 16)
D/dalvikvm(14166): --- LinearAllocV(ifields, 0x0, 60)
D/dalvikvm(14166): --- LinearAllocV(directMethods, 0x0, 1092)
D/dalvikvm(14166): --- LinearAllocV(virtualMethods, 0x0, 3016)
D/dalvikvm(14166): CLASS: linking 'Ljava/lang/Class;'...
D/dalvikvm(14166): --- LinearAllocV(directMethods, 0x0, 104)
D/dalvikvm(14166): --- LinearAllocV(virtualMethods, 0x0, 572)
D/dalvikvm(14166): CLASS: linking 'Ljava/lang/Object;'...
@jrudolph
jrudolph / gist:1308727
Created October 24, 2011 10:17
Abstract type members and poor man's HLists
trait X[T] {
type Next[U] <: X[U]
def add[U](gen: U): Next[(T, U)]
}
object Tester {
val x: X[Int] = null
val y =
x.add(1)
@jrudolph
jrudolph / console.log.scala
Created December 3, 2011 09:36
Scala Class Hierarchy Depth
scala> import collection.JavaConversions._
import collection.JavaConversions._
scala> def allIf(clazz: Class[_]): Seq[String] = clazz.getInterfaces.map(_.toString) ++ clazz.getInterfaces.flatMap(allIf)
allIf: (clazz: Class[_])Seq[String]
scala> val theClazz = Class.forName("scala.collection.immutable.StreamViewLike$$anon$10")
theClazz: Class[_] = class scala.collection.immutable.StreamViewLike$$anon$10
scala> val res0 = { allIf(theClazz) }
@jrudolph
jrudolph / .gitignore
Created December 5, 2011 17:51
Dalvik dexopt failure
/bin
/gen