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
const PouchDB = require('pouchdb');
const db = new PouchDB('choices');
// doc that defines the view
var ddoc = {
_id: '_design/choice',
views: {
by_key: {
map: function (doc) {
emit(doc.key, doc.taste);
const choices = [
[['VANILLA'], ['coconut flakes', 'pecans'], ['marshmallow']],
[['CHOCOLATE'], ['pecans'], ['chocolate']],
[['STRAWBERRY', 'VANILLA'], ['pineapple', 'coconut flakes'], ['marshmallow']],
[['STRAWBERRY'], ['pecans'], ['maple']],
[['VANILLA'], ['coconut flakes', 'pineapple'], ['chocolate']],
[['CHOCOLATE, STRAWBERRY'], ['pineapple', 'pecans'], ['butterscotch']],
];
const keys = _.map(choices, c => {
var Combinator = function (opts) {
var combinations = [];
function combine(current, remainder) {
if (remainder.length === 0) {
if (current.length >= (opts.min || 0) &&
current.length <= (opts.max || current.length))
combinations.push(current);
} else {
combine(current.concat(remainder[0]), remainder.slice(1, remainder.length));
var CombinatorGenerator = function (opts) {
function* combine(current, remainder) {
if (remainder.length === 0) {
if (current.length >= (opts.min || 0) &&
current.length <= (opts.max || current.length)) {
yield(current);
}
} else {
combine(current.concat(remainder[0]), remainder.slice(1, remainder.length))
combine(current, remainder.slice(1, remainder.length))
var menu = require('./menu');
var Combinator = require('./Combinator-generator-naive');
function run() {
var threeCombos = new Combinator({
min: menu.threeItems.min,
max: menu.threeItems.max
})
.combine([], menu.threeItems.values);
@JeffML
JeffML / letsbowl0.groovy
Last active March 18, 2017 20:06
BowlingBall, outer class
class BowlingBall {
private String petName;
BowlingBall() {
}
void setPetName(String petName) {
this.petName = petName;
}
@JeffML
JeffML / letsbowl0.1.groovy
Last active March 18, 2017 20:33
BowlingBall, inner class
interface IBowlingBall {
String getPetName();
}
class Bowler {
static private class BowlingBall implements IBowlingBall{
private String petName;
BowlingBall() {
}
@JeffML
JeffML / BowlingBallFactory.groovy
Created March 18, 2017 21:13
BowlingBallFactory
class BowlingBallFactory {
static private class BowlingBall implements IBowlingBall{
private String petName;
BowlingBall() {
}
private void setPetName(String petName) {
this.petName = petName;
}
@JeffML
JeffML / letsbowl.final.groovy
Last active March 19, 2017 16:38
Bowling Ball ownership, final
import java.util.ArrayList
import java.util.List
interface IBowlingBall {
String getBrand();
String getSerialNumber();
}
abstract class BowlingBall implements IBowlingBall {
private String brand, serialNumber;
this.add({
role: "movement",
cmd: "rawMoves",
}, (msg, reply) => {
var err = null;
var rawMoves = [];
var pos = msg.piece.position;
switch (msg.piece.piece) {