Skip to content

Instantly share code, notes, and snippets.

View Chandler's full-sized avatar

Chandler Abraham Chandler

View GitHub Profile
def myMethod {
val a: Option[Int] = someOption()
if (a.isNone){
//do a side effect (like increment a hadoop counter)
}
return a
}
case class MyException(errorCode: Int) extends RuntimeException
def onThrow[T <: Throwable](check: Check[T])(implicit m: Manifest[T]): Check[Try[_]] =
expected("A Throw(e: %s)".format(m.erasure)).exceptWhen { case Throw(NonFatal(e: T)) => check(e) }
val check = onThrow {
hasType[Unauthorized.type].on { e: ClientError => e.errorCause }
}
check(Throw(MyException(5)))
//this works
def checkUnauthorizedException[T](t: Try[T]): TestResult =
t match {
case Throw(e) if e.isInstanceOf[UnauthorizedException] => TestResult.Success
case _ => TestResult.fail("found " + t.toString() + " but expected Throw[UnauthorizedException]")
}
//possible to make this more generic? e.g. something like..
class myException extends Exception
object myObj {
val ex = myException
}
// <console>:11: error: not found: value myException
// val ex = myException
update, I have a test case here: https://gist.github.com/Chandler/7766963
I'm running it with multiple files as the input and cascading.hadoop.hfs.combine.files=true
When I run it against stock elephant bird it fails with the original error
"com.twitter.elephantbird.mapred.input.DeprecatedLzoTextInputFormat cannot be cast to org.apache.hadoop.mapred.FileInputFormat"
https://github.com/kevinweil/elephant-bird/pull/359
When I run it with Dmitriy's elephant bird patch it fails with "DeprecatedInputFormatWrapper can not support RecordReaders that don't return same key & value objects. current reader class : class com.twitter.elephantbird.mapreduce.input.LzoLineRecordReader"
type PrintSomething = (String) => String
val printer1: PrintSomething = (s: String) => {
print("\nI love " + s)
s
}
val printer2: PrintSomething = (s: String) => {
print("\nI hate " + s)
s
@Chandler
Chandler / gist:11013054
Last active August 29, 2015 14:00
function composition
abstract class PrintSomething() {
def apply(s: String): Unit
}
object PrintSomething {
/**
* @param printMethod a method that prints something
* @return a PrintSomething with an apply method
* equal to your printMethod
class Try
attr_accessor :error, :success
#shortcuts
def self.error(error)
self.new({error: error})
end
def self.success(success)
self.new({success: success})
class Api::StatsController < Api::ApiController
def self.timeseries(game_id)
data = []
game = Game.find(game_id)
day = game.registration_start.to_date
# loop in 1 day increments from registration_start
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA6gAAALKCAYAAAA/CnzNAAAgAElEQVR4Xu3aW5Yct7EF0OZo5FlanqU9mr5XtL1kUiQLQAWQEYGtX2bisQ8yq06Xvnz+/38f/iNAgAABAgQIECBAgAABAg8LfFFQH07A9AQIECBAgAABAgQIECDwVUBBdRAIECBAgAABAgQIECBAIIWAgpoiBosgQIAAAQIECBAgQIAAAQXVGSBAgAABAgQIECBAgACBFAIKaooYLIIAAQIECBAgQIAAAQIEFFRngAABAgQIECBAgAABAgRSCCioKWKwCAIECBAgQIAAAQIECBBQUJ0BAgQIECBAgAABAgQIEEghoKCmiMEiCBAgQIAAAQIECBAgQEBBdQYIECBAgAABAgQIECBAIIWAgpoiBosgQIAAAQJ5Bb7868v04j5/+5y+xw0ECBAgQEBBdQYIECBAgACBXwooqA4IAQIECJwSUFBPSZuHAAECBAgUFVBQiwZn2QQIECgooKAWDM2SCRAgQIDASQEF9aS2uQgQIHC3gIJ6d/52T4AAAQIEXgooqC+JXECAAAECQQIKahCkYQgQIECAQFcBBbVrsvZFgACBfAIKar5MrIgAAQIECKQSUFBTxWExBAgQaC2goLaO1+YIECBAgMD7Agrq+4ZGIECAAIExAQV1zMlVBAgQIEDgWgEF9drobZwAAQLHBRTU4+QmJECAAAECtQQU1Fp5WS0BAgQqCyioldOzdgIECBAgcEBAQT2AbAoCBAgQ+CqgoDoIBAgQIECAwC8FFFQHhAABAgROCSiop6TNQ4AAAQIEigooqEWDs2wCBAgUFFBQC4ZmyQQIECBA4KSAgnpS21wECBC4W0BBvTt/uydAgAABAi8FFNSXRC4gQIAAgSABBTUI0jAECBAgQKCrgILaNVn7IkCAQD4BBTVfJlZEgAABAgRSCSioqeKwGAIECLQWUFBbx2tzBAgQIEDgfQEF9X1DIxAgQIDAmICCOu