This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Git(x: Any) { | |
def fork = "forking %s..." format x | |
} | |
implicit def any2Git(x: Any) = new Git(x) | |
"eelco".fork |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# how to resolve a class constant from a string | |
# via http://www.rubyquiz.com/quiz113.html | |
class A | |
end | |
module B | |
class C | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.util.parsing.combinator._ | |
class JsonParsers extends JavaTokenParsers { | |
def value: Parser[Any] = obj | arr | | |
stringLiteral | | |
floatingPointNumber | | |
"null" | "true" | "false" | |
def obj: Parser[Any] = "{"~repsep(member, ",")~"}" | |
def arr: Parser[Any] = "["~repsep(value, ",")~"]" | |
def member: Parser[Any] = stringLiteral~":"~value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> ulimit -a | |
core file size (blocks, -c) 0 | |
data seg size (kbytes, -d) 6144 | |
file size (blocks, -f) unlimited | |
max locked memory (kbytes, -l) unlimited | |
max memory size (kbytes, -m) unlimited | |
open files (-n) 256 | |
pipe size (512 bytes, -p) 1 | |
stack size (kbytes, -s) 8192 | |
cpu time (seconds, -t) unlimited |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// unless: ala ruby | |
def unless(bool: => Boolean)(fn: => Any) = if(!bool) fn | |
val milkIsSpoiled = false | |
unless(milkIsSpoiled) { | |
println("mmmm. milk") | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(List(1,2,3,4,5) /: (0 to 5)) ((l,r) => r :: l) | |
// List[Int] = List(5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list = [1,2,3,4,5,6,7,8,9] | |
list[0..3] # => [1, 2, 3, 4] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Quacker = { def apply(msg: String):String } | |
val quacking = new Function[String,String] { | |
def apply(msg: String) = "quack! I am a fn given a %s" format msg | |
} | |
class Duck { | |
def apply(msg: String) = "quack! I am a class given a %s" format msg | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!Array.prototype.any) { | |
Array.prototype.any = function() { | |
return this.length != 0; | |
}; | |
} | |
if(!Array.prototype.empty) { | |
Array.prototype.empty = function() { | |
return this.length == 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// how do you convert a Map to a List and back to a Map? | |
val m = Map( | |
'unagi -> "big cat", | |
'maki -> "lil cat" | |
) | |
val l = m.toList // List(('unagi,"big cat"), ('maki,"lil cat")) | |
val m2 = Map(l: _*) // Map('unagi -> "big cat",'maki -> "lil cat") |