Skip to content

Instantly share code, notes, and snippets.

View eiriklv's full-sized avatar

Eirik L. Vullum eiriklv

View GitHub Profile
@donnut
donnut / main.js
Created November 1, 2012 12:28
populating a referenced mongoose model, three levels deep
var mongoose = require('mongoose'),
assert = require('assert')
mongoose.connect('localhost/mydb');
var Schema = mongoose.Schema;
var ContainerSchema = new Schema({
name: String,
})
@JohanObrink
JohanObrink / gist:5796334
Last active December 18, 2015 14:19
Fix for Array.prototype.slice.call not working on NodeLists in IE8
(function() {
if(navigator.appVersion.indexOf('MSIE 8') > 0) {
var _slice = Array.prototype.slice;
Array.prototype.slice = function() {
if(this instanceof Array) {
return _slice.apply(this, arguments);
} else {
var result = [];
var start = (arguments.length >= 1) ? arguments[0] : 0;
var end = (arguments.length >= 2) ? arguments[1] : this.length;
@donnut
donnut / populate_nested_docs.js
Last active December 21, 2015 21:28
populating nested subdocuments
// mongoose v3.6.18
//
var mongoose = require('mongoose');
mongoose.connect('localhost/mydb');
var Schema = mongoose.Schema;
var MasterSchema = new Schema({
name: String,
});
@jozsefDevs
jozsefDevs / validation_curry.js
Created October 22, 2013 20:17
A simple way to implement a validation by JavaScript currying
var above = function(limit){
return function(value){
return value > limit;
};
};
var isAbove10 = above(10);
console.log(isAbove10(5)); // false
console.log(isAbove10(8)); // false
@jlongster
jlongster / testgen.js
Created June 7, 2013 04:25
basic generator async lib
// based off of https://gist.github.com/creationix/5544019
// these could probably be condensed more, but I'm just doing this
// quickly
function call(func) {
var args = Array.prototype.slice.call(arguments, 1);
return function(callback) {
args.push(callback);
@geowarin
geowarin / index-template.html
Created August 5, 2015 14:33
Template index for the html-webpack-plugin and react
<!DOCTYPE html>
<html{% if(o.htmlWebpackPlugin.files.manifest) { %} manifest="{%= o.htmlWebpackPlugin.files.manifest %}"{% } %}>
<head>
<meta charset="UTF-8">
<title>{%=o.htmlWebpackPlugin.options.title || 'Webpack App'%}</title>
{% if (o.htmlWebpackPlugin.files.favicon) { %}
<link rel="shortcut icon" href="{%=o.htmlWebpackPlugin.files.favicon%}">
{% } %}
{% for (var css in o.htmlWebpackPlugin.files.css) { %}
<link href="{%=o.htmlWebpackPlugin.files.css[css] %}" rel="stylesheet">
// devDependencies in package.json:
"require-reload": "0.2.2",
"react-transform-hmr-no-accept": "1.0.1", // not published, get it here: https://github.com/brandonbloom/react-transform-hmr
// in babelrc:
"env": {
"development": {
"plugins": [
@getify
getify / gist:5254459
Last active March 30, 2016 06:31
a rather inefficient, but workable, "polyfill" (of sorts) for `currentThis` as proposed in: https://gist.github.com/getify/5253319
// a sort-of-polyfill for `currentThis` as proposed in: https://gist.github.com/getify/5253319
function lookupFn(oThis,fn) {
var ptr = oThis, i, keys;
while (ptr) {
keys = Object.keys(ptr);
for (i=0; i<keys.length; i++) {
if (ptr[keys[i]] === fn) {
return ptr;
}
}
@alexanderGugel
alexanderGugel / ied-0.1.0
Created November 16, 2015 23:24
ied-0.1.0 vs npm-2.14.7 vs npm-3.4.0
.
├── node_modules
│   ├── 00963d697b2adf0c185c4e04e73174ba9b288eb2
│   │   ├── node_modules
│   │   │   └── xml-escape -> ../../00963d697b2adf0c185c4e04e73174ba9b288eb2/package
│   │   └── package
│   │   ├── LICENSE
│   │   ├── README.md
│   │   ├── index.js
│   │   ├── package.json