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 TypeHelper { | |
import scala.reflect.runtime.universe.TypeTag | |
def getTypeTag[T : TypeTag](t: T): TypeTag[T] = implicitly[TypeTag[T]] | |
/** | |
* Checks if the object matches the type of the typed object. | |
* | |
* @param obj An object instance. | |
* @param typedObj A type object with a 'val argTypeTypeTag: TypeTag[_]' property. |
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
/* | |
Using a for-expression (not comprehension!!) works different then expected! | |
When running with lists, see below, the 'println' is run 4 times as expected. | |
But when using Futures, the second failing Future is not 'run' and the result is still a success! | |
Only when 1st Future is a failure, the result is a failure. | |
BUT !!! In case of Future's the 'println' is NEVER run!! Why?? | |
Note: this is tested using Twitter Futures. Don't know about Scala Future. | |
*/ |
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
# Run this command in terminal to get webcam back in OSX | |
sudo Killall VDCAssistant |
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
#!/bin/bash | |
sayJoke() | |
{ | |
while [ true ] | |
do | |
sleep $((RANDOM%600+15)) | |
curl -s http://chuck.cach.in/text | say | |
done | |
} |
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 com.philips.flexc.player_runtime.rest | |
import com.twitter.finagle.http.{Request, Status} | |
import com.twitter.finatra.http.response.ResponseBuilder | |
import com.twitter.finatra.http.routing.HttpRouter | |
import com.twitter.finatra.http.{Controller, HttpServer} | |
import com.twitter.util.Future | |
import org.scalactic.{Bad, Good, Or} | |
/** |
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
/** | |
* Create an instane of a class of type T with given arguments. | |
* | |
* @param args Arguments to create instance with. The order of arguments must match the constructor! | |
* @tparam T Type of class to create. | |
* @return Instance of T constructed with given arguments. | |
*/ | |
def createInstanceOf[T : reflect.runtime.universe.TypeTag](args: Any*): util.Try[T] = { | |
import reflect.runtime.{universe => ru} |
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
/** | |
* Since using a Java8 Stream in Scala is not easy since Scala functions do not map to Java8 functions (yet, is experimental). | |
* While apparently using lambda's in other parts like Swing callbacks is possible, defining a java.util.function.Function[A,B] | |
* in Scala code does not work. Compiler keeps complaining: | |
* {{{ | |
Error:(52, 10) no type parameters for method map: (x$1: java.util.function.Function[_ >: A, _ <: R])java.util.stream.Stream[R] exist so that it can be applied to arguments (java.util.function.Function[A,B]) | |
--- because --- | |
argument expression's type is not compatible with formal parameter type; | |
found : java.util.function.Function[A,B] | |
required: java.util.function.Function[_ >: A, _ <: ?R] |
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
09:27:01.107 [main] DEBUG slick.ast.Node$.debug[32] - Assigned type Option[Int'] to node Path @599984672.id | |
09:27:01.160 [main] DEBUG slick.ast.Node$.debug[32] - Assigned type Option[Int'] to node Path s3.id | |
09:27:01.180 [main] DEBUG slick.ast.Node$.debug[32] - Assigned type Int' to node Path s2.user_id | |
09:27:01.181 [main] DEBUG slick.ast.Node$.debug[32] - Assigned type Int' to node Path s2.company_id | |
09:27:01.182 [main] DEBUG slick.ast.Node$.debug[32] - Assigned type String' to node Path s2.content_type | |
09:27:01.184 [main] DEBUG slick.ast.Node$.debug[32] - Assigned type java.sql.Timestamp' to node Path s2.from_date | |
09:27:01.185 [main] DEBUG slick.ast.Node$.debug[32] - Assigned type Int' to node Path s2.numberofdays | |
09:27:01.185 [main] DEBUG slick.ast.Node$.debug[32] - Assigned type java.sql.Timestamp' to node Path s2.upto_end_date | |
09:27:01.188 [main] DEBUG slick.ast.Node$.debug[32] - Assigned type Option[Int'] to node Path s2.created_by | |
09:27:01.189 [main] DEBUG slick. |
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
/** | |
* Extends a List[A] with a 'distinctOn' method to be able to distinct the elements | |
* of a list based on an element property. | |
* | |
* For example: | |
* In a List of Subscription's, we only want to send a certain Subscription.subscriber | |
* a message once even though the subscriber has multiple subscriptions. | |
* {{{ | |
* subscriptions.distinctOn(_.subscriber) // returns List[Subscription] with unique subscribers | |
* }}} |
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
import scalaz._ | |
import Scalaz._ | |
val m1 = Map(1 -> Set(2)) | |
val m2 = Map(2 -> Set(5)) | |
val m3 = Map(1 -> Set(3)) | |
val tot = m1 |+| m2 |+| m3 | |
tot.keySet -- m1.keySet | |
m1.keySet -- tot.keySet |