Skip to content

Instantly share code, notes, and snippets.

create or replace function uuid_to_muid(id varchar)
returns varchar as
$$
trim(base64_encode(
substring(hex_decode_binary(replace(id, '-', '')), 9, 8) ||
substring(hex_decode_binary(replace(id, '-', '')), 1, 8),
0,
'-_ '
))
$$;
templateService.getById(id) match {
case Found(template) => ...
case NotFound(message) => // message contains a nice (consistent message)
}
for {
checklist <- checklistService.getById(checklistId).toRight("checklist").right
template <- templateService.getById(checklist.template.id).toRight
} yield {
...
@cdmckay
cdmckay / gist:3fb0007f6fee50fbbda1
Created December 21, 2015 17:42
Codecov error
==> Detecting CI provider
Circle CI Detected
==> Preparing upload
==> Processing gcov (disable by -X gcov)
Executing gcov (find /home/ubuntu/process-street -type f -name '*.gcno' -exec gcov -pb {} +)
==> Collecting reports
+ /home/ubuntu/process-street/target/scala-2.11/scoverage-data/scoverage.coverage.xml bytes=23057648
+ /home/ubuntu/process-street/target/scala-2.11/coverage-report/cobertura.xml bytes=4840129
+ /home/ubuntu/process-street/target/scala-2.11/scoverage-report/scoverage.xml bytes=11752247
==> Appending adjustments (http://bit.ly/1O4eBpt)
@cdmckay
cdmckay / elvis.php
Last active April 20, 2016 17:35
A simple "elvis" operator in PHP
<?php
function elvis($object, $path = null) {
return array_reduce(explode('.', $path), function ($subObject, $segment) {
return isset($subObject[$segment]) ? $subObject[$segment] : null;
}, $object);
}
// Example
$o = [ 'a' => [ 'b' => 1, 'c' => 2 ], 'd' => 3 ];
@cdmckay
cdmckay / format.js
Last active August 29, 2015 14:25
An ES6 template string-compatible format method
if (!String.prototype.format) {
(function() {
'use strict';
var TEMPLATE_REGEXP = /\${\s*([$_a-z][$_a-z0-9]*)\s*}/ig;
var format = function (env) {
return this.replace(TEMPLATE_REGEXP, function (_, expr) {
return env[expr];
});
};
@cdmckay
cdmckay / elvis.js
Created July 15, 2015 03:46
A simple "elvis" operator in JavaScript
function elvis(object, path) {
return path ? path.split('.').reduce(function (value, key) {
return value && value[key];
}, object) : object;
}
// Example
var o = { a: { b: 1, c: 2 }, d: 3 };
elvis(o, 'a');
// = { b: 1, c: 2 }
@cdmckay
cdmckay / serialize.js
Last active August 29, 2015 14:24
A snippet to serialize an object in to query parameters
function serialize(object) {
return Object.keys(object).map(function (key) {
return encodeURIComponent(key) + '=' + encodeURIComponent(object[key]);
}).join('&');
}
// Example
var params = {
username: 'cdmckay',
password: 'hunter2'
@cdmckay
cdmckay / MultipartFormDataWriteableExample.scala
Created June 24, 2015 05:04
An example of how to use MultipartFormDataWriteable
import play.api.libs.ws.WS
import play.api.mvc.MultipartFormData.FilePart
import play.api.mvc.MultipartFormData
import utilities.MultipartFormDataWriteable._
...
val url = "https://example.com"
val dataParts = Map(
@cdmckay
cdmckay / MultipartFormDataWriteable.scala
Created June 24, 2015 04:39
Add support for MultipartFormData to the Play Scala WS library
package utilities
import java.io.{ByteArrayOutputStream, File}
import com.ning.http.client.FluentCaseInsensitiveStringsMap
import com.ning.http.multipart.{MultipartRequestEntity, FilePart, StringPart}
import play.api.http.HeaderNames._
import play.api.http.{ContentTypeOf, Writeable}
import play.api.mvc.{Codec, MultipartFormData}
@cdmckay
cdmckay / datetime-picker-example.html
Created December 8, 2014 19:00
Example of using the DateTime picker in AngularJS
<!-- The dueDate field is a UNIX offset of the date -->
<input type="text"
ng-model="dueDate"
ps-datetime-picker
class="form-control">