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
| const { uniq, map, range, zip, mapValues, groupBy, flatMap } = require('lodash'); | |
| const expandWordToDeletions = (word) => { | |
| const wordArray = word.split(""); | |
| const deletionList = map( | |
| range(word.length), | |
| i => { | |
| const copied = [...wordArray]; | |
| copied.splice(i, 1); | |
| return copied.join(""); |
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
| package util | |
| object FutureOption { | |
| implicit class WithFutureOption[A](self: Future[Option[A]]) { | |
| def flatMapOption[T](e: => Exception)(f: A => Future[T]): Future[T] = { | |
| self flatMap { | |
| _ map f getOrElse Future.failed(e) | |
| } | |
| } |
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
| trait Base[T] { | |
| val id: Option[String] | |
| def copyId(id: String): T | |
| } | |
| case class Test2(id: Option[String], other: String) extends Base[Test2] { | |
| def copyId(id: String) = copy(id=Some(id)) | |
| } |
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
| // file 1 | |
| package active_column.driver | |
| import me.prettyprint.cassandra.serializers.ByteBufferSerializer | |
| import me.prettyprint.cassandra.serializers.DoubleSerializer | |
| import me.prettyprint.cassandra.serializers.DynamicCompositeSerializer | |
| import me.prettyprint.cassandra.serializers.IntegerSerializer | |
| import me.prettyprint.cassandra.serializers.LongSerializer | |
| import me.prettyprint.cassandra.serializers.SerializerTypeInferer |
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
| object Serializers { | |
| trait Serializable[T] { | |
| def serialize(t: T): String | |
| def fromSerialized(s: String): Option[T] | |
| } | |
| object Serializable { | |
| implicit object SerializableInt extends Serializable[Int] { | |
| def serialize(t: Int) = s"int: $t" | |
| def fromSerialized(s: String): Option[Int] = try { |
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
| -module(fizzBuzz). | |
| -export([fizzBuzz/0]). | |
| fizzBuzz() -> | |
| fizzBuzz(1,3,5). | |
| fizzBuzz(100, _, _) -> | |
| io:format("buzz~n"); | |
| fizzBuzz(Count, Count, Count) -> | |
| io:format("fizzbuzz~n"), |
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
| // Usage: | |
| // p(instance)('privateMethod)(arg1, arg2, arg3) | |
| class PrivateMethodCaller(x: AnyRef, methodName: String) { | |
| def apply(_args: Any*): Any = { | |
| val args = _args.map(_.asInstanceOf[AnyRef]) | |
| def _parents: Stream[Class[_]] = Stream(x.getClass) #::: _parents.map(_.getSuperclass) | |
| val parents = _parents.takeWhile(_ != null).toList | |
| val methods = parents.flatMap(_.getDeclaredMethods) | |
| val method = methods.find(_.getName == methodName).getOrElse(throw new IllegalArgumentException("Method " + methodName + " not found")) |
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 Test { | |
| def pullOutType[V](f:Map[String, V] => Unit) { | |
| var map = Map[String, V]() | |
| val params = Map("string" -> "string", "int" -> 20, "list" -> List("ok", "then")) | |
| params.foreach { | |
| case (field, value) => value match { | |
| case v:V => map = map + (field -> v) | |
| case _ => null | |
| } |
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
| object Holder { | |
| var companions = Set[AnyRef]() | |
| def companionFor[M](m:M) = { | |
| companions.find { | |
| case found:M => true | |
| case _ => false | |
| } | |
| } | |
| } |
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
| abstract class SuperClass { | |
| var initialized = false | |
| def initialize { | |
| initialized = true | |
| } | |
| } | |
| abstract trait SubclassCompanion { | |
| def create:Any |
NewerOlder