Skip to content

Instantly share code, notes, and snippets.

View martijndeh's full-sized avatar

Martijn de Haan martijndeh

View GitHub Profile

Keybase proof

I hereby claim:

  • I am martijndeh on github.
  • I am martijndeh (https://keybase.io/martijndeh) on keybase.
  • I have a public key whose fingerprint is B19E 7BB6 30BA DC20 D195 2C20 BEAE 9BAF 1FB1 0E82

To claim this, I am signing this object:

@martijndeh
martijndeh / gist:390c08e1ce91d627a55a
Created April 23, 2015 15:01
Invoke workers from the web process.
app.post('/api/forgot-password', function(request, MailWorker, UserModel) {
return UserModel.getMe(request).then(function(user) {
return MailWorker.sendResetPassword(user, user.resetPassword);
});
});
@martijndeh
martijndeh / gist:b79956ca41e5f23309b5
Created April 23, 2015 14:58
Easily create workers.
function MailWorker() {
//
}
app.worker(MailWorker);
MailWorker.prototype.sendResetPasswordMail = function(user, resetPassword) {
var defer = Q.defer();
mandrill('/messages/send', {
message: {
@martijndeh
martijndeh / gist:95b396b5106ccf180a90
Created April 23, 2015 14:54
Migrations-based schema changes in Node on Fire
exports = module.exports = Migration;
function Migration() {
//
}
Migration.prototype.up = function() {
this.models.createModel('TodoItem', {
id: [this.UUID, this.CanUpdate(false)],
list: [this.BelongsTo(this.models.TodoList), this.Required],
var fire = require('fire');
var app = fire.app('todomvc');
app.model(function TodoItem(TodoListModel) {
this.list = [this.BelongsTo(TodoListModel), this.Required];
this.name = [this.String, this.Required];
this.completed = [this.Boolean, this.Required, this.Default(false)];
this.createdAt = [this.DateTime, this.Default('CURRENT_TIMESTAMP')];
});
@martijndeh
martijndeh / gist:10ce8d6e33ff2cf3f8ad
Created April 23, 2015 14:50
Isomorphic service in Node on Fire
app.service(function TextService() {
this.slugify = function(text) {
return text.toString().toLowerCase()
.replace(/\s+/g, '-')
.replace(/[àáâãäå]+/g, 'a')
.replace(/[èéêë]+/g, 'e')
.replace(/[ìíîï]+/g, 'i')
.replace(/[òóôõö]+/g, 'o')
.replace(/[ùúûü]+/g, 'u')
.replace(/\\s+/g, "")
@martijndeh
martijndeh / gist:203e8f507d4d3783fa6d
Created April 12, 2015 12:15
A/B testing in Node on Fire
app.controller('/', function StartController(TextOfButtonTest, $scope) {
if(TextOfButtonTest.getVariant() == 'A') {
$scope.buttonText = 'Register for FREE';
}
else {
$scope.buttonText = 'Register now';
};
});
@martijndeh
martijndeh / gist:0906538f168f3d1c2e64
Created April 12, 2015 12:14
A/B testing in Node on Fire
app.controller('/', function StartController(TextOfButtonTest, $scope) {
if(TextOfButtonTest.getVariant() == 'A') {
$scope.buttonText = 'Register for FREE';
}
else {
$scope.buttonText = 'Register now';
};
});
@martijndeh
martijndeh / gist:0791a6ec06854e363433
Created April 12, 2015 12:10
Express with dependency injection in Node on Fire
app.post('/api/users', function(UserModel, request) {
return UserModel.create(request.body)
.then(function(user) {
return user;
});
});
@martijndeh
martijndeh / gist:3b74f45dcdab6643c591
Created April 12, 2015 12:05
Isomorphic example in Node on Fire
app.service(function MyService(fire) {
this.doSomething = function() {
if(fire.isServer()) {
console.log('On the server.');
}
else if(fire.isClient()) {
console.log('On the client.');
}
}
});