Skip to content

Instantly share code, notes, and snippets.

(function () {
window.Templates = {
templateX: Handlebars.compile("<div>{{ foo }}</div>");
}
})();
@cdmckay
cdmckay / cmInclude.js
Last active December 21, 2015 02:59
The working 1.0.7 Angular.js ngInclude that works with Angular.js 1.2.0rc1 (which has a broken ngInclude). Just change "angularApp" to your app's name and use "cm-include" where you would use "ng-include".
'use strict';
angular.module('angularApp')
.directive('cmInclude', ['$http', '$templateCache', '$anchorScroll', '$compile',
function($http, $templateCache, $anchorScroll, $compile) {
return {
restrict: 'ECA',
terminal: true,
compile: function(element, attr) {
var srcExp = attr.ngInclude || attr.src,
@cdmckay
cdmckay / gist:7530967
Created November 18, 2013 16:37
A temporary fix for a bug in the Rhinofly s3-play library
def uploadPart(bucket: Bucket, uploadTicket: BucketFileUploadTicket, bucketFilePart: BucketFilePart): Future[BucketFilePartUploadTicket] = {
require(bucketFilePart.partNumber > 0, "The partNumber must be greater than 0")
require(bucketFilePart.partNumber < 10001, "The partNumber must be lesser than 10001")
// A hack way to get access to private httpUrl method
val url = bucket.s3.url(bucket.name, uploadTicket.name, 0).split('?')(0)
val uploadPart = bucket.s3.awsWithSigner
.url(url)
.withQueryString(
"partNumber" -> bucketFilePart.partNumber.toString,
@cdmckay
cdmckay / HttpsAction.scala
Last active November 1, 2015 13:27
HttpsAction
package actions
import play.api.Play
import play.api.Play.current
import play.api.mvc._
import scala.concurrent.Future
object HttpsAction extends ActionBuilder[Request] with Results {
def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[Result]) = {
@cdmckay
cdmckay / Users.scala
Last active August 29, 2015 14:06
HttpsAction... in action
package controllers
object Users extends Controller {
def add = HttpsAction {
implicit request => Ok
}
}
var iterationsData;
var results = document.getElementById('results');
(function () {
if (!('localStorage' in window)) {
results.innerHTML = 'Your browser has no localStorage support.';
return;
}
@cdmckay
cdmckay / local-storage-size.js
Last active May 8, 2022 11:03
Detects the size of the browser's localStorage
if (localStorage && !localStorage.getItem('size')) {
var i = 0;
try {
// Test up to 10 MB
for (i = 250; i <= 10000; i += 250) {
localStorage.setItem('test', new Array((i * 1024) + 1).join('a'));
}
} catch (e) {
localStorage.removeItem('test');
localStorage.setItem('size', i - 250);
@cdmckay
cdmckay / uuid_to_bytea.sql
Last active December 23, 2022 02:13
How to convert a PostgreSQL UUID to bytea
select decode(replace('45774962-e6f7-41f6-b940-72ef63fa1943'::text, '-', ''), 'hex');
-- And here's how to convert it to the ShortUUID format used in Process Street
select replace(encode(substring(decode(replace('45774962-e6f7-41f6-b940-72ef63fa1943'::text, '-', ''), 'hex') from 9 for 8) ||
substring(decode(replace('45774962-e6f7-41f6-b940-72ef63fa1943'::text, '-', ''), 'hex') from 1 for 8), 'base64'), '=', '');
@cdmckay
cdmckay / datetime-picker.js
Created December 8, 2014 18:53
Angular directive for eonasdan's Bootstrap DateTime picker
'use strict';
angular.module('frontStreetApp.directives')
.directive('psDatetimePicker', function (moment) {
var format = 'MM/DD/YYYY hh:mm A';
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, element, attributes, ctrl) {
@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">