Skip to content

Instantly share code, notes, and snippets.

View JeffML's full-sized avatar
🏠
Barely working

Jeff Lowery JeffML

🏠
Barely working
View GitHub Profile
@JeffML
JeffML / js-inheritance
Created May 30, 2015 19:58
Javascript inheritance example, using Object.create(), ctors, and super method calls
/* refs:
* http://oli.me.uk/2013/06/01/prototypical-inheritance-done-right/
* http://davidshariff.com/blog/javascript-inheritance-patterns/
*/
"use strict";
function Human(name, gender) {
this.name = name;
this.gender = gender;
}
@JeffML
JeffML / borken.groovy
Last active August 29, 2015 14:22
Example of using threaded Geb test for Broken Links
package tests
import static groovy.json.JsonOutput.*
import static org.junit.Assert.*
import geb.Browser
import java.util.concurrent.*
import org.junit.Before
import org.junit.Test
swagger: '2.0'
info:
version: '1.0.0'
title: Swagger Petstore (Simple)
description: A sample API that uses a petstore as an example to demonstrate features in the swagger-2.0 specification
termsOfService: http://helloreverb.com/terms/
contact:
name: Swagger API team
email: foo@example.com
url: http://swagger.io
@JeffML
JeffML / menu.js
Last active January 7, 2017 14:01
icecream menu
var menu = {
iceCream: {min: 1, max: 2, values: ["CHOCOLATE", "STRAWBERRY", "VANILLA"]},
topping: {min: 0, max: 2, values: ["pineapple", "strawberry", "coconut flakes", "pecans"]},
syrup: {min:0, max: 1, values: ["chocolate", "marshmallow", "butterscotch", "maple"]}
}
var allChoices = [];
_.each(iceCreamChoices, function(ic) {
_.each(toppingChoices, function(tp) {
_.each(syrupChoices, function(sy) {
allChoices.push([ic,tp,sy]);
})
})
})
var count = 0;
_.each(iceCreamChoices, function(ic) {
_.each(toppingChoices, function(tp) {
_.each(syrupChoices, function(sy) {
//allChoices.push([ic,tp,sy]);
db.post({choice: [ic,tp,sy]}, function(err, doc){
if (err) console.error(err);
else console.log(`stored ${++count}`);
});
@JeffML
JeffML / run.js
Last active January 9, 2017 00:16
function run() {
var menu = { //...
}
var iceCreamChoices = new Combinator({ //...
});
var toppingChoices = new Combinator({ //...
});
var syrupChoices = new Combinator({ //...
});
var _ = require('lodash');
var PouchDB = require('pouchdb');
var db = new PouchDB('choices');
db.allDocs({
include_docs: true
})
.then(docs => {
_.each(docs.rows, r => {
const crypto = require('crypto');
const _ = require('lodash')
function hash(choice) {
var str = _.chain(choice)
.flatten()
.sortBy()
.join('|')
.value();
const _ = require('lodash');
const hash = require('./hash');
const PouchDB = require('pouchdb');
const db = new PouchDB('choices');
db.allDocs({
include_docs: true
})
.then(docs => {