Skip to content

Instantly share code, notes, and snippets.

@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}

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:

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:

function substitute {
if [ -z "$1" -o -z "$2" ]; then
echo "Usage: substitue FROM_STRING TO_STRING [OPTION]..."
echo
echo "Replace all occurances of FROM_STRING (a sed-compatible regular"
echo "expression) with TO_STRING in all files for which ack-grep matches"
echo "FROM_STRING."
echo
echo "Any additional options are passed directly to ack-grep (e.g.,"
echo " --type=html would only run the substitution on html files)."
#!/bin/bash
if [ -z "$1" -o -z "$2" ]; then
echo "Usage: substitue FROM_STRING TO_STRING [OPTION]..."
echo
echo "Replace all occurances of FROM_STRING (a sed-compatible regular"
echo "expression) with TO_STRING in all files for which ack matches"
echo "FROM_STRING."
echo
echo "Any additional options are passed directly to ack (e.g.,"
@joscha
joscha / factory.coffee
Last active December 17, 2015 18:59
Factory pattern for CommonJS, AMD and Browser
((root, ns, factory) ->
'use strict'
# CommonJS
if typeof exports is 'object' and typeof module is 'object'
module.exports = factory()
# AMD
else if typeof define is 'function' and define.amd
define factory
var hash = CryptoJS.HmacSHA1("Message", "Secret Passphrase");
var hashPlusOne = CryptoJS.enc.Hex.parse(BigInteger.parse(hash.toString(),16).add(1).toString(16));
console.log(hash.toString(),hashPlusOne.toString());
@joscha
joscha / config.coffee
Last active December 10, 2015 23:48
run with `coffee server`
exports.db =
host: 'localhost'
name: 'example'
exports.db.url = "mongodb://#{exports.db.host}/#{exports.db.name}"
@joscha
joscha / meteor-async.md
Last active August 29, 2017 06:51 — forked from possibilities/meteor-async.md
Meteor Async Guide

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.

@joscha
joscha / mount.sh
Created August 11, 2012 14:10
Shell file for mounting an encfs volume in OSX by using the keychain password
#!/bin/bash
target=/Volumes/tmp.mytarget
source=/Users/bla/Dropbox/encrypted
volname=EncodedDropbox
keychainPassword=encodedDropbox
mount | grep $target >/dev/null
[[ "$?" -eq "0" ]] && diskutil umount force $target
if [ ! -d $target ]