This file contains hidden or 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
public class Main { | |
public static void main(String[] args) { | |
Integer a = 500; | |
Integer b = 500; | |
System.out.println(a == b); | |
Integer c = 100; | |
Integer d = 100; |
This file contains hidden or 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 util.Random | |
type Point = (Int, Int) | |
case class Direction(dir: Int) { | |
require(dir >= 0 && dir < 4) | |
def left = Direction((dir + 3) % 4) | |
def right = Direction((dir + 1) % 4) | |
def flip = Direction((dir + 2) % 4) |
This file contains hidden or 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
case class Trie[T <: Iterable[_]]( | |
content: T = T.empty, | |
chlds: Map[Char, Trie[T]] = Map().withDefaultValue(Trie[T]()) | |
) { | |
override def toString = | |
content + chlds.map { | |
case (k, v) => s"k: v" | |
}.mkString | |
def update(s: String, f: T => T): Trie[T] = |
This file contains hidden or 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
var users = Map.empty[Int, Set[ActorRef]] | |
def receive = { | |
case AddUser(id) => { | |
users += id -> users.lift(id) match { | |
case None => Set(sender) | |
case Some(prev) => prev + sender | |
} | |
} | |
} |
This file contains hidden or 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
val s = List((1,1,10),(2,3,2)) | |
println({ val r = 2; val c = 3 | |
s.collectFirst { | |
case (r, c, x) => x | |
} | |
}) |
This file contains hidden or 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
case class T(val ops: Seq[Int]) | |
object T { | |
def apply(ops2: Int*): T = T(ops2) | |
} | |
println(T(List(1,2,3)).ops) | |
println(T(1,2,3).ops) |
This file contains hidden or 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
def self.intersect_segment_segment(line1,line2) | |
if result.desc == :line_array | |
case ref_pts.length | |
when 4 | |
# ----- vvvv SECTION TO COMMENT vvv ----- | |
if line1.include?(ref_pts[1]) && line1.include?(ref_pts[2]) | |
PGL_Intersect.new :line,[ref_pts[1],ref_pts[2]] | |
else | |
PGL_Intersect.new :normal, [] |
This file contains hidden or 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 record the *object* from which class was instantiated? | |
class C | |
def parent | |
# stub! | |
end | |
end | |
class P | |
def spawn |
This file contains hidden or 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 Rubko::Asset < Rubko::Controller | |
def initialize(*) | |
p 'Asset init' | |
super | |
end | |
end | |
class FilesController < Rubko::Asset |
This file contains hidden or 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
def work | |
# some I/O and Net calls | |
end | |
100.times { | |
EM.add_timer(rand 10) { | |
work | |
} | |
} |