Skip to content

Instantly share code, notes, and snippets.

View danielstreit's full-sized avatar

Daniel Streit danielstreit

View GitHub Profile
@danielstreit
danielstreit / memoize.js
Created February 14, 2015 03:13
a standalone memoize function inspired by lodash
function memoize(func, resolver) {
var memoized = function() {
var cache = memoized.cache;
var key = resolver ?
resolver.apply(this, arguments) :
arguments[0];
if (cache.has(key)) {
return cache.get(key);
}
// a flag to toggle asset pipeline / compass integration
// defaults to true if twbs-font-path function is present (no function => twbs-font-path('') parsed as string == right side)
// in Sass 3.3 this can be improved with: function-exists(twbs-font-path)
$bootstrap-sass-asset-helper: (twbs-font-path("") != unquote('twbs-font-path("")')) !default;
//
// Variables
// --------------------------------------------------
//== Colors
@danielstreit
danielstreit / collectionFactory.js
Last active August 29, 2015 14:06
Add a star to a collection given a user
var addStar = function(data) {
return $http({
method: 'POST',
url: '/api/collection/addStar',
data: data
}).then(function(response) {
return response.data;
});
@danielstreit
danielstreit / Function Declaration vs Function Expression
Created August 20, 2014 17:41
Function Declaration vs Function Expression
// What the difference between:
function declaration() {}; // This is a function declaration
// and
var expression = function() {}; // This is a function expression
// The function declaration is hoisted, definition and all.
// In the expression, only the var declaration is hoisted.
@danielstreit
danielstreit / MongoDB Aggregation Pipeline Primer
Last active August 29, 2015 14:05
A primer on MongoDB Aggregation Pipeline
// In the MongoDB Aggregation Pipeline, each stage is represented by an object.
// The type of stage must be one MongoDB's predefined stage types. There are
// a variety of stage types, but some of the most useful are: $match, $group,
// $project, and $sort. See the MongoDB manual for an exhaustive list.
// Lets look at some examples to see how each works. Then, we'll put them
// together in the pipeline.
// Lets say we have a database of kittens with various information about each.
// A match stage might look like this: