Skip to content

Instantly share code, notes, and snippets.

function simpleMerge (baseObj, extensionObj){
return Object.keys(extensionObj).reduce(function (baseObj, propertyKey) {
baseObj[propertyKey] = extensionObj[propertyKey];
return baseObj;
}, baseObj);
}
'use strict';
var routeFunctions = {
delete: {},
get: {},
post: {},
put: {}
};
function routeStub(method, path, action) {
@cmstead
cmstead / Vector.js
Last active February 24, 2016 04:57
Vector type for Javascript -- built for discussion on types and functions in Javascript
(function () {
'use strict';
function Vector() {
Vector.attachPoints(this, arguments);
}
// Inherted behaviors
Vector.prototype = {
@cmstead
cmstead / grunt-file-globbing.json
Created December 13, 2015 20:00
Grunt file object a handy reference for performing file globbing in Grunt
{
"src": "path/to/source",
"defaultEncoding": "utf8",
"preserveBOM": false,
"dest": "path/to/destionation/",
"ext": ".extensions.must.contain.dots",
"cwd": "start/in/this/directory/",
"expand": {
"cwd": true,
"match": ["file globbing patterns"],
@cmstead
cmstead / express-static-files.js
Created December 13, 2015 19:45
Express serving static files from a directory
// Serving static files in a named directory, served from the root path
app.use(express.static('path/to/static/files')); // This will pick up deep references within named directory
// http://localhost:3000/js/foo.js <- foo.js lives in path/to/static/files/js/foo.js
// Serving files from a virtual directory
app.use('/blar', express.static('path/to/static/files'));
@cmstead
cmstead / xhr-request.js
Last active November 17, 2015 01:40
XHR Request Module (non-browserify-export, no guarantees)
var xhr = (function () {
'use strict';
function buildParamPair (requestData, paramList, key) {
paramList.push(key + '=' + requestData[key].toString());
return paramList;
}
function buildGetParams (requestData) {
return Object.keys(requestData).reduce(buildParamPair.bind(null, requestData)).join('&');
@cmstead
cmstead / j.clone.source.js
Created October 24, 2015 20:15
Clone method from JFP 2.4.0
function clone (originalValue, depth) {
var depthOkay = j.isUndefined(depth) || j.geq(depth, 0),
copyOkay = j.isType('object', originalValue) || j.isType('array', originalValue);
function copy () {
var keys = Object.keys(originalValue),
container = j.isArray(originalValue) ? [] : {};
j.each(function (key) {
var newDepth = j.isNumber(depth) ? depth - 1 : undefined;
@cmstead
cmstead / request-cache-factory.js
Created September 20, 2015 19:49
Request cache factory in Javascript
var cacheFactory = (function(){
'use strict';
function RequestCache(requestFn){
this.callQueue = queueFactory.build();
this.requestFn = requestFn;
this.dataCache = {
requestSent: false,
response: null
@cmstead
cmstead / queue-factory.js
Created September 20, 2015 19:49
A queue factory in Javascript
var queueFactory = (function(){
'use strict';
function Queue(){
this.queueHead = null;
this.queueLast = null
}
Queue.prototype = {
getHeadValue: function(){
@cmstead
cmstead / linked-list-factory.js
Created September 20, 2015 19:36
A linked list factory in Javascript
var listItemFactory = (function(){
'use strict';
function ListItem(value){
this.value = value;
this.nextPointer = null;
}
ListItem.prototype = {
val: function(){