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
scala> val mayBeLong: Option[Long] = Option(null: java.lang.Long) | |
java.lang.NullPointerException | |
at scala.Predef$.Long2long(Predef.scala:358) | |
... 33 elided | |
scala> val mayBeLong: Option[Long] = Option(null: java.lang.Long).flatMap(Option.apply _) | |
<console>:7: error: type mismatch; | |
found : java.lang.Long => Option[java.lang.Long] | |
required: java.lang.Long => Option[scala.Long] | |
val mayBeLong: Option[Long] = Option(null: java.lang.Long).flatMap(Option.apply _) |
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 mapops { | |
implicit class DayOneMapOps[A, +B](wrapped: Map[A, B]) { | |
// Scalaz has `mapKeys` to just change keys | |
// Scala has `mapValues` to just change values | |
// Scala has `transform` to just change values but provides key as a parameter | |
/** | |
* This function transforms all the keys and values of mappings contained in this map with function `f`. |
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
def safely[T](f: PartialFunction[Throwable, T]): PartialFunction[Throwable, T] = new PartialFunction[Throwable, T] { | |
override def isDefinedAt(x: Throwable): Boolean = NonFatal(x) && f.isDefinedAt(x) | |
override def apply(v1: Throwable): T = f(v1) | |
} | |
try throw new InvalidParameterException("Test") | |
catch safely { | |
case exc => exc.printStackTrace() | |
} |
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
implicit class UUIDExtensions(wrapped: UUID) { | |
def pretty: String = formatUUID(wrapped) | |
def toBytes: Array[Byte] = uuidToBytes(wrapped) | |
} |
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 services | |
import play.api.mvc.RequestHeader | |
object ConcatService { | |
object PublishPage { | |
val name = "publish-page.js" | |
val files = Vector("javascripts/vendor/sidr.js", "javascripts/vendor/plugins.js", "javascripts/entry/entry.js", "javascripts/entry/entry-stats.js") | |
def path(implicit context: AssetContext, rh: RequestHeader) = AssetService.at(name) |
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 services | |
import play.api.mvc.RequestHeader | |
object ConcatService { | |
object PublishPage { | |
val name = "publish-page.js" | |
val files = Vector("javascripts/vendor/sidr.js", "javascripts/vendor/plugins.js", "javascripts/entry/entry.js", "javascripts/entry/entry-stats.js") | |
def path(implicit context: AssetContext, rh: RequestHeader) = AssetService.at(name) |
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
var decodeBase64 = (function(b64) { | |
var i, j, l, tmp, scratch, arr = []; | |
var lookup = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; | |
if (typeof b64 !== 'string') { | |
throw 'Input is not a string'; | |
} | |
if (b64.length % 4 > 0) { | |
throw 'Invalid base64 source.'; | |
} | |
scratch = b64.indexOf('='); |
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 EntryMerge(em: EntryMaster, | |
revisionIn: ProposedRevision, | |
entryIn: Entry, | |
parentRevision: Option[EntryRevision]) extends Loggable with DayOneInjectable { | |
// CODE AND THINGS! | |
} |
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 EntryMasterSerializer { | |
def EntryProposedRevisionReader(entryId: UUID)(implicit request: DayOneAuthenticatedRequest[_]): Reads[(ProposedRevision, Entry)] = ( | |
(__ \ "type").read[RevisionOutcome] and | |
(__ \ "editDate").readOrElse(DateTime.now(DateTimeZone.UTC)) and | |
(__ \ "entry").read(entryReads(entryId.some)) | |
).tupled.map { | |
case (outcome, editDate, entry) => | |
val revision = ProposedRevision( | |
outcome = outcome, | |
user = request.user, |
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
/** | |
* Copyright (C) 2006-2009 Dustin Sallings | |
* Copyright (C) 2009-2013 Couchbase, Inc. | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a copy | |
* of this software and associated documentation files (the "Software"), to deal | |
* in the Software without restriction, including without limitation the rights | |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
* copies of the Software, and to permit persons to whom the Software is | |
* furnished to do so, subject to the following conditions: |