Skip to content

Instantly share code, notes, and snippets.

View andrewlorenz's full-sized avatar

Andy Lorenz andrewlorenz

View GitHub Profile
@andrewlorenz
andrewlorenz / gist:8f8420f7d0645a2254609b6bce14b63c
Last active November 1, 2018 17:33
Meteor methods calling async server code
Meteor methods are a means by which a client can execute synchronous code on the server as if it was local, and wait for the result before continuing.
The important word to note here is "synchronous" - meteor methods are only good "out of the box" if the server-side code it is executing is non-blocking. So what do we do when we need to execute asynchronous code on the server?
There are 3 possible approaches:
a) Meteor.wrapAsync
b) async/await
c) fibers/future
@andrewlorenz
andrewlorenz / gist:ac13b6a9200f2ed85bca071a3fcbff6d
Last active January 5, 2017 16:07
mongo cheat sheet - various cope snippets for manipulating databases and collections
Increment counter:
db.analytics.update({"url" : "www.example.com"},{"$inc" : {"pageviews" : 1}})
Adding/Updating a field in a document:
db.blog.posts.update({"author.name" : "joe"}, {"$set" : {"author.name" : "joe schmoe"}})
db.positions.update({},{$set:{pos_short_status:"O"}},{upsert:false,multi:true});
db.clients.update({cli_status:"N"},{$set:{cli_status:"A"}},{upsert:false,multi:true});
Removing a field from a document:
db.users.update({"name" : "joe"}, ... {"$unset" : {"favorite book" : 1}})
@andrewlorenz
andrewlorenz / gist:16be3d318ec6c3937677a1fb637ce1f3
Created November 15, 2016 16:59
meteor data subscriptions using promise to ensure all data has been delivered to the client
Meteor data subscription
how to ensure all data has been delivered to the client before continuing
(e.g. in order to initialise a jQuery object that must have all UI elements present)
//-------------------------------------------------------------------
Template.sample.onCreated(function() {
//-------------------------------------------------------------------