Skip to content

Instantly share code, notes, and snippets.

View Enome's full-sized avatar

Geert Pasteels Enome

View GitHub Profile
// Node.js
data.find('id', function(err, response){
var one = response[0];
var many = response;
var error = err;
});
// EventEmitter
mixin field(type, name, label)
-var form_model = locals.form_model || {}
if type === 'hidden'
input(name=name, type=type, value=form_model[name])
else
.control-group(class=locals.fieldClass(name, locals.errors))
label.control-label(for='id_' + name) #{label}
- inject: (args)->
|
| { verifyBrowserId } = args if args.verifyBrowserId
| { users } = args if args.users
- checkRedirectUrl: (req, res, next)->
|
| if req.query.redirect_url
|
module.exports = {
bark: function(){
console.log('woof');
},
speak: function(){
{
size: 100,
query: {
query_string: {
fields: ['name', 'author', 'tags'],
query: q
}
}
}
var index = {
package: {
properties: {
name: { type: 'string', store: 'no' },
tags: { type: 'string', store: 'no' },
author: { type: 'string', store: 'no' },
doc: { type: 'object', store: 'yes', index: 'no' }
}
}
};
@Enome
Enome / client.js
Created April 26, 2012 12:41
Fake async file upload using an iframe.
$( function(){
var form = $('<form>');
var iframe = $('<iframe name="upload_iframe">');
var file_upload = $('.file-upload');
// Form
form.attr("target", "upload_iframe");
form.attr("action", '/upload');
balance:
map: (doc)->
if doc.type is 'transaction'
emit( doc.relatedId, doc.amount )
reduce: (keys, values, rereduce)->
total = 0.0
@Enome
Enome / route.js
Created April 18, 2012 09:27
Express: basic route that verifies BrowserId
// This route can be used to complete the tutorial at:
// https://developer.mozilla.org/en/BrowserID/Quick_Setup
app.post('/api/login', function( req, res, next ) {
var options = {
host: 'browserid.org',
path: '/verify',
method: 'POST'
};
#!upstart
description "service.krafters.be"
author "Geert"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
#respawn # restart when job dies