Skip to content

Instantly share code, notes, and snippets.

View Chandler's full-sized avatar

Chandler Abraham Chandler

View GitHub Profile
genderGuess: function (a) {
a = a.toLowerCase();
var b = a.charAt(a.length - 1),
c = a.charAt(a.length - 2) + b;
return "a" != b && "e" != b && "y" != b && "i" != b && "in" != c && "ah" != c && "en" != c && "an" != c && "yn" != c && "er" != c && "ux" != c || "steve" == a || 3 == a.length || "sean" == a || "steven" == a || "dimitri" == a || "ravi" == a || "kenny" == a || "naoki" == a || "ayman" == a || "sachin" == a || "edwin" == a || "justin" == a || "nitin" == a || "bryce" == a || "mike" == a || "gary" == a || "dave" == a || "jonathan" == a || "harry" == a || "male" == a ? "male" : "female"
}
@Chandler
Chandler / eitherBuilder.scala
Last active August 29, 2015 13:56
Either Builder
sealed trait NotSatisfied { def reason: String }
case class MissingOption(reason: String) extends NotSatisfied
case class IncorrectBoolean(reason: String) extends NotSatisfied
/**
* Convert Option[T] to Either.RightProjection[MissingOption, T]
* for use in a for comprehension
*
* @param opt the option to consider
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA6gAAALKCAYAAAA/CnzNAAAgAElEQVR4Xu3aW5Yct7EF0OZo5FlanqU9mr5XtL1kUiQLQAWQEYGtX2bisQ8yq06Xvnz+/38f/iNAgAABAgQIECBAgAABAg8LfFFQH07A9AQIECBAgAABAgQIECDwVUBBdRAIECBAgAABAgQIECBAIIWAgpoiBosgQIAAAQIECBAgQIAAAQXVGSBAgAABAgQIECBAgACBFAIKaooYLIIAAQIECBAgQIAAAQIEFFRngAABAgQIECBAgAABAgRSCCioKWKwCAIECBAgQIAAAQIECBBQUJ0BAgQIECBAgAABAgQIEEghoKCmiMEiCBAgQIAAAQIECBAgQEBBdQYIECBAgAABAgQIECBAIIWAgpoiBosgQIAAAQJ5Bb7868v04j5/+5y+xw0ECBAgQEBBdQYIECBAgACBXwooqA4IAQIECJwSUFBPSZuHAAECBAgUFVBQiwZn2QQIECgooKAWDM2SCRAgQIDASQEF9aS2uQgQIHC3gIJ6d/52T4AAAQIEXgooqC+JXECAAAECQQIKahCkYQgQIECAQFcBBbVrsvZFgACBfAIKar5MrIgAAQIECKQSUFBTxWExBAgQaC2goLaO1+YIECBAgMD7Agrq+4ZGIECAAIExAQV1zMlVBAgQIEDgWgEF9drobZwAAQLHBRTU4+QmJECAAAECtQQU1Fp5WS0BAgQqCyioldOzdgIECBAgcEBAQT2AbAoCBAgQ+CqgoDoIBAgQIECAwC8FFFQHhAABAgROCSiop6TNQ4AAAQIEigooqEWDs2wCBAgUFFBQC4ZmyQQIECBA4KSAgnpS21wECBC4W0BBvTt/uydAgAABAi8FFNSXRC4gQIAAgSABBTUI0jAECBAgQKCrgILaNVn7IkCAQD4BBTVfJlZEgAABAgRSCSioqeKwGAIECLQWUFBbx2tzBAgQIEDgfQEF9X1DIxAgQIDAmICCOu
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
class Try
attr_accessor :error, :success
#shortcuts
def self.error(error)
self.new({error: error})
end
def self.success(success)
self.new({success: success})
@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
type PrintSomething = (String) => String
val printer1: PrintSomething = (s: String) => {
print("\nI love " + s)
s
}
val printer2: PrintSomething = (s: String) => {
print("\nI hate " + s)
s
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"
class myException extends Exception
object myObj {
val ex = myException
}
// <console>:11: error: not found: value myException
// val ex = myException
//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..