Skip to content

Instantly share code, notes, and snippets.

/**
* 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:
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,
class EntryMerge(em: EntryMaster,
revisionIn: ProposedRevision,
entryIn: Entry,
parentRevision: Option[EntryRevision]) extends Loggable with DayOneInjectable {
// CODE AND THINGS!
}
@bigjason
bigjason / base64.js
Last active August 29, 2015 14:05
Copy of couchbase decodeBase64 for debugging
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('=');
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)
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)
implicit class UUIDExtensions(wrapped: UUID) {
def pretty: String = formatUUID(wrapped)
def toBytes: Array[Byte] = uuidToBytes(wrapped)
}
@bigjason
bigjason / util.scala
Created March 31, 2015 21:20
Scala exception `safely`
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()
}
@bigjason
bigjason / DayOneMapOps.scala
Last active August 29, 2015 14:18
Extension to add missing `Map` transformers.
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`.
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 _)