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
def inlineme(f: => Int): Int = { | |
try { | |
f | |
inlineme { | |
return 0 | |
} | |
} catch { | |
case ex: Throwable => println(ex); return 1 | |
} | |
} |
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
setPoint <- 68; | |
function updateTemp() { | |
// Read the ambient temperature | |
temp <- readTemp(); | |
// If it's below what it should be, turn on the heat. | |
if (temp < setPoint) { | |
heatOn(); | |
} else { |
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
// Adapted from: | |
// http://techgurka.blogspot.com/2013/04/quick-temperature-graph-using-electric.html | |
class TemperatureSensor { | |
i2cPort = null; | |
constructor(port) { | |
i2cPort = port; | |
i2cPort.configure(CLOCK_SPEED_100_KHZ); | |
} | |
// Retrieve temperature (from local sensor) in deg F |
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
// Adapted from: | |
// http://techgurka.blogspot.com/2013/04/quick-temperature-graph-using-electric.html | |
class TemperatureSensor { | |
i2cPort = null; | |
constructor(port) { | |
i2cPort = port; | |
i2cPort.configure(CLOCK_SPEED_100_KHZ); | |
} | |
// Retrieve temperature (from local sensor) in deg F |
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
def inlineMeAgain[T](f: => T): T = { | |
f | |
} | |
def inlineme(f: => Int): Int = { | |
try { | |
inlineMeAgain { | |
return f | |
} | |
} catch { |
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
try { | |
aDangerousFunction() | |
} catch { | |
case ex: Throwable => println(ex) | |
// Or even worse | |
case ex => println(ex) | |
} |
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
abstract class RegexExpr | |
// ., a, b | |
case class Literal(c: Char) extends RegexExpr | |
// a|b | |
case class Or(expr1: RegexExpr, expr2: RegexExpr) extends RegexExpr | |
// ab -> Concat(a,b); abc -> Concat(a, Concat(b, c)) | |
case class Concat(first: RegexExpr, second: RegexExpr) extends RegexExpr |
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
object RegexParser extends RegexParsers { | |
def charLit: Parser[RegexExpr] = ("""\w""".r | ".") ^^ { | |
char => Literal(char.head) | |
} |
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
object RegexParser extends RegexParsers { | |
def charLit: Parser[RegexExpr] = ("""\w""".r | ".") ^^ { | |
char => Literal(char.head) | |
} |
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
object RegexParser extends RegexParsers { | |
def charLit: Parser[RegexExpr] = ("""\w""".r | ".") ^^ { | |
char => Literal(char.head) | |
} |
OlderNewer