Skip to content

Instantly share code, notes, and snippets.

View boxxxie's full-sized avatar
👙
disrupting absurdism

Paul Iannazzo boxxxie

👙
disrupting absurdism
View GitHub Profile
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;
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)
;;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))
 var couchapp = require('couchapp')
, path = require('path')
;
ddoc =
{ _id:'_design/app'
, rewrites :
[ {from:"/", to:'index.html'}
, {from:"/api", to:'../../'}
, {from:"/api/*", to:'../../*'}
{
"_id": "_design/app",
"_rev": "451-ee23989089c184ee50994a03552ce74a",
"rewrites": [
{
"from": "/",
"to": "index.html"
},
{
"from": "/api",
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>}"}
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;}
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 {
(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]
(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]