This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var calc_item_cost = function (item) { | |
'use strict'; | |
var price = item.price; | |
if (item.modifiers) { | |
var modifiersCost = item.modifiers.reduce(function (totalModifierCost, modifier, index, array) { | |
return totalModifierCost + calc_modifier_cost(modifier); | |
}, 0); | |
return price + modifiersCost; | |
} | |
return price; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
paul@paul-rt7-desktop:~/superblog$ ls | |
app.js app.js~ attachments | |
paul@paul-rt7-desktop:~/superblog$ couchapp push app.js http://localhost:5984/superblog | |
node.js:205 | |
throw e; // process.nextTick error, or 'error' event on first tick | |
^ | |
Error: Cannot find module 'couchapp' | |
at Function._resolveFilename (module.js:318:11) | |
at Function._load (module.js:263:25) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;i want a macro that makes defs for me. examples | |
;;(def stores "localhost:5984/stores") | |
;;(defDB) works the way i want it to, (defDBs) does not | |
;;i get errors of the form (can't resolve do) or (string can't be an IF). i'm not sure what i'm doing wrong. i've tried many variations | |
;; my aim is (do (defDB store) (defDB inv)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var couchapp = require('couchapp') | |
, path = require('path') | |
; | |
ddoc = | |
{ _id:'_design/app' | |
, rewrites : | |
[ {from:"/", to:'index.html'} | |
, {from:"/api", to:'../../'} | |
, {from:"/api/*", to:'../../*'} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"_id": "_design/app", | |
"_rev": "451-ee23989089c184ee50994a03552ce74a", | |
"rewrites": [ | |
{ | |
"from": "/", | |
"to": "index.html" | |
}, | |
{ | |
"from": "/api", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -X POST -H "Content-Type: application/json" -d '{"source":"http://192.168.1.254:5984/campaigns","target":"campaigns", "filter":"app/forLocation", "query_params": {"chain":"hero-burger"}}' http://localhost:5984/_replicate | |
{"error":"json_encode","reason":"{bad_term,<0.10623.4>}"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ddoc.filters.forLocation = function(doc, req) { | |
//req formated as {chain:,store:,terminal:} | |
Array.prototype.contains = function(item){return (this.indexOf(item) != -1);}; | |
isArray = function(obj) {return toString.call(obj) === '[object Array]';}; | |
if(!doc){return false;} | |
if(!doc.location){return false;} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isArray = function(obj) { | |
return toString.call(obj) === '[object Array]'; | |
}; | |
const flatten = function(arr) { | |
return arr.reduce(function(memo, value) { | |
if (isArray(value)) { | |
return memo.concat(flatten(value)); | |
} | |
else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn touch-view [db ddoc view] | |
(db/with-db db (db/get-view ddoc view {:reduce false :limit 0}))) | |
(defn future-touch-view [db ddoc view] | |
(let [f (future (do (touch-view db ddoc view) | |
(Thread/sleep sleepTime) | |
))] | |
@f)) | |
(defn touch-views [views] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn touch-view [db ddoc view] | |
(db/with-db db (db/get-view ddoc view {:reduce false :limit 0}))) | |
(defn future-touch-view [db ddoc view] | |
(println sleepTime) | |
(let [f (future (binding [rest sleepTime](do (touch-view db ddoc view) | |
(Thread/sleep rest))))] | |
@f)) | |
(defn touch-views [views] |