This file contains 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
case class TjalleBalle(dblOpt: Option[Double]) | |
//Og her skal det skje magi | |
TjalleBalle("1.080") // men det gjør det altså ikke, og den whiner på feil type. | |
case class StringConverter[T](f: String => T) | |
implicit val convDouble = StringConverter[Double](_.toDouble) | |
implicit val convInt = StringConverter[Int](_.toInt) | |
implicit val convString = StringConverter[String](_) |
This file contains 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
implicit val convDouble = convOption[Double](_.toDouble)_ | |
implicit val convInt = convOption[Int](_.toInt)_ | |
implicit val convString = convOption[String](_.toString)_ | |
def convOption[T](f: String => T)(s: String) = try { Some(f(s)) } catch { case _ => None } |
This file contains 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
val intent = TryCatch({ | |
case e: IllegalArgumentException => logger.warn(e.getMessage, e); BadRequest ~> ResponseString(e.getMessage) | |
case e: UnsupportedOperationException => logger.warn(e.getMessage, e); NotImplemented ~> ResponseString(e.getMessage) | |
case e => logger.error(e.getMessage, e); InternalServerError | |
}).apply(intentImpl) | |
private lazy val intentImpl: Plan.Intent = { |
This file contains 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 unfilteredx.kit | |
import unfiltered.request._ | |
import unfiltered.response._ | |
object Secure { | |
def secure[A,B](intent: unfiltered.Cycle.Intent[A,B]) = { | |
case req@ForwardedProto(proto) if (intent.isDefinedAt(req)) => intent(wrap(req, "https" == proto.toLowerCase)) | |
case req if (intent.isDefinedAt(req)) => intent(req) | |
} |
This file contains 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
def load(id: Long)(profile: ProfileWrapper): Either[Exception, StoredSearch] = { | |
try { | |
val alert = Option(alertService.getAlert(id)) | |
alert.map { | |
a: AlertBeanSpringJDBC => | |
if (a.getLoginId != profile.id) { | |
Left(new SecurityException("This is not owned by the logged in user.")) | |
} | |
Right(StoredSearch( | |
Some(a.getAlertId), |
This file contains 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 JsonParser extends BodyParserModule { | |
def parse[String, O <: Parsable[O]](a: String): O = a match { | |
case O(o) => o | |
case _ => ??? | |
} | |
} | |
sealed trait Parsable[A] { | |
def parse(a: String): A |
This file contains 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
rm -rf ~/Library/Preferences/com.jetbrains.intellij.plist | |
rm -rf ~/Library/Preferences/com.jetbrains.intellij.plist.lockfile | |
rm -rf ~/Library/Preferences/IntelliJIdea* | |
rm -rf ~/Library/Caches/IntelliJIdea* | |
rm -rf ~/Library/Application Support/IntelliJIdea* | |
rm -rf ~/Library/Caches/com.jetbrains.intellij | |
rm -rf ~/Library/Logs/IntelliJIdea | |
rm -rf ~/Library/Saved Application State/com.jetbrains.intellij.savedState | |
rm -rf ~/Library/Preferences/Idea* | |
rm -rf ~/Library/Preferences/com.jetbrains* |
This file contains 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
scala> case class Pair[A,B](head: A, tail: B) | |
defined class Pair | |
scala> type HeadlessPair[B] = Pair[Any, B] // Setting it to any, so the compiler wont care when type view is accessed | |
defined type alias HeadlessPair | |
scala> def f[A[_], B](ab: A[B]) {} | |
warning: there were 1 feature warning(s); re-run with -feature for details | |
f: [A[_], B](ab: A[B])Unit |
This file contains 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 FuncConversions { | |
//Nay | |
implicit def guavaFunction2function[A, R](fn: (A) => R) = { | |
new com.google.common.base.Function[A, R]{ | |
def apply(input: A): R = fn(input) | |
} | |
} | |
//Yay | |
class Func[A, B](fn: (A) => B) extends com.google.common.base.Function[A, B] { |
This file contains 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
1. | |
(x,y)[5] | |
= (y, x)[4] | |
(y,x)[1] = (y,z)[4] | |
= (x, z)[4] | |
(x,z)[4] | |
2. |
OlderNewer