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
import play.api.libs.json._ | |
import play.api.libs.functional.syntax._ | |
import play.api.data.validation.ValidationError | |
implicit class JsPathPimps(path: JsPath) extends JsPath { | |
def readOrError[T](error: => String)(implicit r: Reads[T]): Reads[T] = new Reads[T] { | |
def reads(json: JsValue): JsResult[T] = path.readNullable(r).reads(json) match { | |
case JsSuccess(Some(value), _) => JsSuccess(value, path) | |
case JsSuccess(None, _) => JsError((path, ValidationError(error))) | |
case err@JsError(_) => err |
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
app.filter('bytes', function() { | |
return function(bytes, precision) { | |
if (isNaN(parseFloat(bytes)) || !isFinite(bytes)) return '-'; | |
if (typeof precision === 'undefined') precision = 1; | |
var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB'], | |
number = Math.floor(Math.log(bytes) / Math.log(1024)); | |
return (bytes / Math.pow(1024, Math.floor(number))).toFixed(precision) + ' ' + units[number]; | |
} | |
}); |