Skip to content

Instantly share code, notes, and snippets.

@horsey
horsey / .js
Created December 16, 2015 20:19 — forked from joepie91/.js
Nested scopes in promises
/* Follow-up from https://gist.github.com/joepie91/211c8e99fb5a83b76079, which shows promise flattening */
Promise.try(function(){
return outerThingOne();
}).then(function(value){
return Promise.try(function(){
return innerThingOne();
}).then(function(subValue){
/* We're using both `value` AND `subValue` here! Both are in scope, because we're nesting. */
return innerThingTwo(value, subValue);
@horsey
horsey / get.js
Created December 16, 2015 20:01 — forked from bennadel/get.js
Shedding The Monolithic Application With AWS Simple Queue Service (SQS) And Node.js
// Require the demo configuration. This contains settings for this demo, including
// the AWS credentials and target queue settings.
var config = require( "./config.json" );
// Require libraries.
var aws = require( "aws-sdk" );
var Q = require( "q" );
var chalk = require( "chalk" );
// Create an instance of our SQS Client.
@horsey
horsey / gist:96ce0a9db9e66090288d
Created December 11, 2015 10:55
Code snippet to demonstrate Promises.
'use strict';
var _ = require('lodash'),
async = require('async'),
moment = require('moment'),
messaging = require('../../messaging'),
patients = require('../patients'),
practitioners = require('../practitioners'),
dataProvider = require('../../database');
function(eventList, next) {
if (_.isEmpty(eventList))
return next(null, eventList);
var tmp = {};
var val = _
.chain(eventList)
@horsey
horsey / record.json
Created August 2, 2015 21:03
Document
{ "_id" : ObjectId("55be8465a54b293f913633ff"), "_key" : "partner:10034", "partnerName" : "XXXXX", "phoneNumber" : "9999999999", "email" : "gc@gc.com", "category" : "small", "modules" : [ "appointments", "video", "audio", "messaging" ], "secretary" : [ { "secretaryName" : "Interesting, Name, Name, True", "phoneNumber" : "9880009000", "email" : "gc1@gc.com", "username" : "name2", "password" : "somepass", "location" : "", "partnerId" : "10034", "ctime" : 1438549120203, "lastlogin" : "", "status" : "pending", "locked" : false, "deleted" : false } ], "partnerId" : 10034, "type" : "partner", "ctime" : 1438549093138, "lastLogin" : "", "status" : "pending", "locked" : false, "deleted" : false, "secretaryCnt" : 1 }
MongoError: Cannot apply $addToSet to a non-array field. Field named '0' has a non-array type Object in the document _id
//variable data is JSON string
db.collection('objects').update({
_key: key,
'secretary.username': options.username
}, {
$addToSet: {
"secretary.$" : data
}
}, {
Disclaimer:
This piece was inspired by: http://code.activestate.com/recipes/146306/
def post_multipart(host, port, selector, fields, files, ownerid):
content_type, body = encode_multipart_formdata(fields, files)
h = httplib.HTTPConnection(host, port)
headers = {
'User-Agent': 'Build Cluster 1.0',
'Content-Type': content_type,
[2014-09-05T10:53:23+00:00] INFO: Forking chef instance to converge...
[2014-09-05T10:53:23+00:00] INFO: *** Chef 11.10.4 ***
[2014-09-05T10:53:23+00:00] INFO: Chef-client pid: 14532
[2014-09-05T10:53:24+00:00] INFO: Setting the run_list to ["opsworks_custom_cookbooks::load", "opsworks_custom_cookbooks::execute"] from JSON
[2014-09-05T10:53:24+00:00] WARN: Run List override has been provided.
[2014-09-05T10:53:24+00:00] WARN: Original Run List: [recipe[opsworks_custom_cookbooks::load], recipe[opsworks_custom_cookbooks::execute]]
[2014-09-05T10:53:24+00:00] WARN: Overridden Run List: [recipe[opsworks_ganglia::configure-client], recipe[ssh_users], recipe[mysql::client], recipe[agent_version], recipe[opsworks_stack_state_sync], recipe[php::configure], recipe[appserver::default], recipe[test_suite], recipe[opsworks_cleanup]]
[2014-09-05T10:53:24+00:00] INFO: Run List is [recipe[opsworks_ganglia::configure-client], recipe[ssh_users], recipe[mysql::client], recipe[agent_version], recipe[opsworks_stack_state_sync],
berks install
Resolving cookbook dependencies...
Fetching 'mysql' from https://github.com/opscode-cookbooks/mysql (at master)
Fetching 'qz-mysql' from source at .
Fetching cookbook index from https://supermarket.getchef.com...
Error retrieving universe from source: https://supermarket.getchef.com
* [Berkshelf::APIClient::TimeoutError] Unable to connect to: https://supermarket.getchef.com
Unable to satisfy constraints on package yum-mysql-community, which does not exist, due to solution constraint (mysql = 5.4.4). Solution constraints that may result in a constraint on yum-mysql-community: [(mysql = 5.4.4) -> (yum-mysql-community >= 0.0.0)]
Missing artifacts: yum-mysql-community
Demand that cannot be met: (mysql = 5.4.4)