Skip to content

Instantly share code, notes, and snippets.

@xsyn
xsyn / gist:985550
Created May 22, 2011 15:03
Cradle callback issue
DreamModel.prototype.findAll = function(callback) {
this.db.view('dream/all', function(err, res) {
if (err) {
console.log(err)
} else {
var docs = [];
res.forEach(function (row) {
docs.push(row);
});
callback(null, docs);
@xsyn
xsyn / gist:992780
Created May 26, 2011 08:36
Callback with res
== model/dreamModel.js
DreamModel.prototype.save = function(articles, callback) {
if( typeof(articles.length) == 'undefined') {
articles = [articles];
}
for(var i=0;i<articles.length;i++) {
article = articles[i];
articles.created = new Date();
var app = require('common').app,
common = require('common'),
db = require('common').db,
io = require('common').socket,
//form = require('common').form;
formidable = require('formidable'),
util = require('util'),
fs = require('fs');
Launching '/Applications/Couchbase Single Server.app/Contents/Resources/couchdbx-core/bin/couchdb'
{error_logger,{{2011,11,1},{21,9,27}},"Protocol: ~p: register error: ~p~n",["inet_tcp",{{badmatch,{error,econnrefused}},[{inet_tcp_dist,listen,1},{net_kernel,start_protos,4},{net_kernel,start_protos,3},{net_kernel,init_node,2},{net_kernel,init,1},{gen_server,init_it,6},{proc_lib,init_p_do_apply,3}]}]}
{error_logger,{{2011,11,1},{21,9,27}},crash_report,[[{initial_call,{net_kernel,init,['Argument__1']}},{pid,<0.20.0>},{registered_name,[]},{error_info,{exit,{error,badarg},[{gen_server,init_it,6},{proc_lib,init_p_do_apply,3}]}},{ancestors,[net_sup,kernel_sup,<0.10.0>]},{messages,[]},{links,[#Port<0.59>,<0.17.0>]},{dictionary,[{longnames,false}]},{trap_exit,true},{status,running},{heap_size,377},{stack_size,24},{reductions,458}],[]]}
{error_logger,{{2011,11,1},{21,9,27}},supervisor_report,[{supervisor,{local,net_sup}},{errorContext,start_error},{reason,{'EXIT',nodistribution}},{offender,[{pid,undefined},{name,net_ker
Kant held that "free will" is essential; human dignity is related to human agency, the ability of humans to choose their own actions
// View a dream
app.get('/dreams/:id?.:format?', function(req, res) {
dreamModel.findById(req.params.id, function(err, docs) {
// Try and get images returning from db
console.log("Returning docs object for attachments: " + eyes.inspect(docs))
console.log("Checking for Attachments!!!");
if (docs._attachments) {
var promise = new(events.EventEmitter), response = {};
var streamer = db.getAttachment(docs._id, docs.filename);
streamer.addListener('response', function (res) {
@xsyn
xsyn / gist:2593326
Created May 4, 2012 08:33
Problem is the response in res.send is undefined.
app.get('/products', function(req, res) {
var Client = http.createClient(80, 'local.10layer.com');
var request = Client.request("GET", '/workers/api/section/products', {'host' : 'local.10layer.com'});
request.addListener("response", function(response) {
var body = "";
response.addListener("data", function(data) { //Add listener for the actual data
body += data; //Append all data coming from api to the body variable
});
@xsyn
xsyn / gist:2762534
Created May 21, 2012 14:15
Flotsum
// This is the original object:
{"total_rows":2,"offset":0,"rows":[
{"id":"202638c9041c87a2e01e1a320600074d","key":"202638c9041c87a2e01e1a320600074d","value":{"_id":"202638c9041c87a2e01e1a320600074d","_rev":"6-b28aa64f065a183c86c9d2097a1c81a7","company":"SAPA","project":"Replace wires system","contact":"Munetsi Chiunda","created":"","nextStep":"Roll-out prototype","value":"300000.00","state":{"0":"2012/3/15","1":"2012/4/19"},"type":"global"}},
{"id":"202638c9041c87a2e01e1a320600098c","key":"202638c9041c87a2e01e1a320600098c","value":{"_id":"202638c9041c87a2e01e1a320600098c","_rev":"7-7db0c0d4640bf7f070f4c34d7f746d2d","company":"ITWeb","project":"News diary","contact":"Jon Tullet","created":"2012/5/15","state":{"0":"2012/5/15","1":"2012/5/19"},"nextStep":"Get functional specficiation","value":"150000.00","type":"global"}}
]}
// This is the object I want to create:
{"title": "SAPA", "data":"[[1331762400000, 0], [1334786400000, 1], [1337608923775, 1]},
@xsyn
xsyn / data
Created May 23, 2012 06:11
home.jade
{"total_rows":2,"offset":0,"rows":[
{"id":"202638c9041c87a2e01e1a320600074d","key":"202638c9041c87a2e01e1a320600074d","value":{"_id":"202638c9041c87a2e01e1a320600074d","_rev":"6-b28aa64f065a183c86c9d2097a1c81a7","company":"SAPA","project":"Replace wires system","contact":"Munetsi Chiunda","created":"","nextStep":"Roll-out prototype","value":"300000.00","state":{"0":"2012/3/15","1":"2012/4/19"},"type":"global"}},
{"id":"202638c9041c87a2e01e1a320600098c","key":"202638c9041c87a2e01e1a320600098c","value":{"_id":"202638c9041c87a2e01e1a320600098c","_rev":"7-7db0c0d4640bf7f070f4c34d7f746d2d","company":"ITWeb","project":"News diary","contact":"Jon Tullet","created":"2012/5/15","state":{"0":"2012/5/15","1":"2012/5/19"},"nextStep":"Get functional specficiation","value":"150000.00","type":"global"}}
]}
@xsyn
xsyn / account.rb
Created October 30, 2012 12:58
Debug
cattr_accessor :current_account
self.authorizer_name = 'AccountAuthorizer'
77: after_create do
78: RuoteKit.engine.launch(ProcessDefinition.account_creation, account_id: self.id.to_s, :object_type => 'Account')
79: end