Skip to content

Instantly share code, notes, and snippets.

@cubicleWar
cubicleWar / SyncController.php
Created October 27, 2017 04:16
Laravel Authentication Proxy Controller for CouchDB/PouchDB Syncing
<?php
//
// SyncController
//
// A controller for Laravel authentication when performing CouchDB syncing.
//
// This controller assumes a user per database approach and that when a user registers with the Laravel
// web app a couchdb_username is generated and stored in the user record. This name is used for the
// creation of a corresponding couchdb user and database.
//
@cubicleWar
cubicleWar / angular.applyFilters.js
Last active October 27, 2017 03:41
A function to apply a string of pipe separated filters to a given value using the angular $filter service.
//
// Applies a sequence of angular filters to a given variable
//
// @param $filter The angular filter service
// @param value The variable to apply the filters on
// @param filterSpec A pipe separated list of filters to apply to the value e.g "filter1|filter2|filerN"
//
function applyFilters($filter, value, filterSpec)
{
@cubicleWar
cubicleWar / utils.readNested.js
Last active October 27, 2017 03:38
Read nested a nested property from an object given a key sequence string like 'location.x.elevation'
function readNested(obj, keys)
{
var parts = keys.split('.'),
curr = obj;
for (var i = 0; i < parts.length; i++)
{
if (!curr[parts[i]])
{
return null;
@cubicleWar
cubicleWar / angular.filter.shuffle.js
Last active October 27, 2017 03:48
AngularJS filter for performing a Fisher-Yates shuffle of an array.
//
// Performs a Fisher-Yates shuffle of an array
//
// @param input An array of items to shuffle
//
angular.module('nd.filters').filter('shuffle', function() {
function shuffle(input)
{
var out = [];