Skip to content

Instantly share code, notes, and snippets.

From Meteor's documentation:

In Meteor, your server code runs in a single thread per request, not in the asynchronous callback style typical of Node. We find the linear execution model a better fit for the typical server code in a Meteor application.

This guide serves as a mini-tour of tools, trix and patterns that can be used to run async code in Meteor.

Basic async

Sometimes we need to run async code in Meteor.methods. For this we create a Future to block until the async code has finished. This pattern can be seen all over Meteor's own codebase:

@joscha
joscha / css-animation-keframes.sass
Created February 1, 2014 13:12
CSS animation and keyframes mixins
=keyframes($name)
@-webkit-keyframes #{$name}
@content
@-moz-keyframes #{$name}
@content
@-ms-keyframes #{$name}
@content
@-o-keyframes #{$name}
@content
@keyframes #{$name}
// jQuery Deparam - v0.1.0 - 6/14/2011
// http://benalman.com/
// Copyright (c) 2011 Ben Alman; Licensed MIT, GPL
(function($) {
// Creating an internal undef value is safer than using undefined, in case it
// was ever overwritten.
var undef;
// A handy reference.
var decode = decodeURIComponent;
@joscha
joscha / .travis.yml
Created May 27, 2014 18:14
Sample travis file for typesafe activator
language: java
env:
- ACTIVATOR_VERSION=1.1.3 \
ACTIVATOR_ZIP_FILE=typesafe-activator-${ACTIVATOR_VERSION}-minimal.zip \
ACTIVATOR_ZIP_URL=http://downloads.typesafe.com/typesafe-activator/${ACTIVATOR_VERSION}/${ACTIVATOR_ZIP_FILE} \
ACTIVATOR_BIN=${TRAVIS_BUILD_DIR}/activator-${ACTIVATOR_VERSION}-minimal/activator
install:
- wget ${ACTIVATOR_ZIP_URL}
- unzip -q ${ACTIVATOR_ZIP_FILE}
script:
@joscha
joscha / bower.json
Last active August 29, 2015 14:07 — forked from Xiphe/bower.json
{
"name": "jasmine-moar-matchers",
"authors": [
"Hannes Diercks"
],
"description": "Some additional Jasmine 2.0 Matchers.",
"main": ["toBeInstanceOf.js", "toBeTypeOf.js", "promises.js"],
"keywords": [
"jasmine",
"matcher"
@joscha
joscha / typesquare.fontlist.json
Created December 10, 2014 14:01
Tyesquare font list
{
"リュウミン": {
"familyName": "リュウミン",
"fonts": [{
"fontNum": "1",
"japaneseName": "リュウミン L-KL",
"englishName": "Ryumin Light KL",
"fontfamily": "リュウミン",
"fontfamilyMainfont": "Ryumin Light KL",
"style": "明朝体"
@joscha
joscha / install_bcm2385.sh
Last active August 29, 2015 14:13 — forked from annem/gist:3183536
Install BCM2385 library
#!/bin/sh
set -o errexit
bcm2385_version=1.38
rm bcm2835-$bcm2385_version.tar.gz
wget http://www.airspayce.com/mikem/bcm2835/bcm2835-$bcm2385_version.tar.gz
tar zxvf bcm2835-$bcm2385_version.tar.gz
cd bcm2835-$bcm2385_version
./configure
make
function prettifySpreadsheetJSON(data) {
var prefix = 'gsx$';
for (var i = 0; i < data.feed.entry.length; i++) {
for (var key in data.feed.entry[i]) {
if (data.feed.entry[i].hasOwnProperty(key) && key.substr(0,prefix.length) === prefix) {
data.feed.entry[i][key.substr(prefix.length)] = data.feed.entry[i][key].$t;
delete data.feed.entry[i][key];
}
}
}
// file X depending on EventEmitter
var EventEmitter = __webpack_require__(16);
// EventEmitter module
/***/ },
/* 16 */
/***/ function(module, exports, __webpack_require__) { ...
module.exports = EventEmitter;
@joscha
joscha / README.md
Created January 1, 2016 06:08
Automated bisect for node projects

Script to run an automated git bisect in a node project.

This script assumes a standard location of node_modules and a defined test script.

$ git bisect bad # mark current revision as bad
$ git bisect good origin/master # mark origin/master as good
$ git bisect run ./test.sh # run automated bisection
$ git bisect reset # reset the bisect