Skip to content

Instantly share code, notes, and snippets.

Russell Cohen rcoh

View GitHub Profile
@rcoh
rcoh / nothrowable.scala
Created Apr 18, 2014
Why you should never catch throwable.
View nothrowable.scala
def inlineme(f: => Int): Int = {
try {
f
inlineme {
return 0
}
} catch {
case ex: Throwable => println(ex); return 1
}
}
View therm.nut
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 {
@rcoh
rcoh / tmp102.nut
Last active Aug 29, 2015
TMP 102 Electric IMP i2c
View tmp102.nut
// 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
@rcoh
rcoh / post1complete.nut
Last active Aug 29, 2015
Complete code after Post 1
View post1complete.nut
// 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
@rcoh
rcoh / scalaclosures.scala
Last active Aug 29, 2015
Scala Nested Closures
View scalaclosures.scala
def inlineMeAgain[T](f: => T): T = {
f
}
def inlineme(f: => Int): Int = {
try {
inlineMeAgain {
return f
}
} catch {
@rcoh
rcoh / dangerouspattern.scala
Last active Aug 29, 2015
A dangerous pattern
View dangerouspattern.scala
try {
aDangerousFunction()
} catch {
case ex: Throwable => println(ex)
// Or even worse
case ex => println(ex)
}
View regexblog2.scala
object RegexParser extends RegexParsers {
def charLit: Parser[RegexExpr] = ("""\w""".r | ".") ^^ {
char => Literal(char.head)
}
View regexblog2.scala
object RegexParser extends RegexParsers {
def charLit: Parser[RegexExpr] = ("""\w""".r | ".") ^^ {
char => Literal(char.head)
}
View regexblog2.scala
object RegexParser extends RegexParsers {
def charLit: Parser[RegexExpr] = ("""\w""".r | ".") ^^ {
char => Literal(char.head)
}
View blog1.scala
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
You can’t perform that action at this time.