Skip to content

Instantly share code, notes, and snippets.

View bebraw's full-sized avatar

Juho Vepsäläinen bebraw

View GitHub Profile
@bebraw
bebraw / compile_plugin.js
Created June 28, 2013 18:25
Generic compiler plugin for james.js.
var james = require('james');
module.exports = function(options) {
return james.createStream(function(file, callback) {
callback(options.compiler.compile(file, options)(options.context));
});
};
@bebraw
bebraw / notify.js
Created June 22, 2013 14:17
Pipe to OS X notifier. Requires https://npmjs.org/package/node-notifier and https://github.com/alloy/terminal-notifier . You can install latter through MacPorts (port install terminal-notifier). Usage: foo | ./notify.js
#!/usr/bin/env node
var notifier = require('node-notifier');
var stdin = process.openStdin();
stdin.setEncoding('utf8');
stdin.on('data', function(chunk) {
notifier.notify({message: chunk});
});
$ ping cdn.jsdelivr.net
PING 531151672.r.worldcdn.net (94.254.0.25): 56 data bytes
64 bytes from 94.254.0.25: icmp_seq=0 ttl=55 time=31.281 ms
64 bytes from 94.254.0.25: icmp_seq=1 ttl=55 time=29.416 ms
64 bytes from 94.254.0.25: icmp_seq=2 ttl=55 time=31.258 ms
64 bytes from 94.254.0.25: icmp_seq=3 ttl=55 time=28.973 ms
64 bytes from 94.254.0.25: icmp_seq=4 ttl=55 time=28.925 ms
64 bytes from 94.254.0.25: icmp_seq=5 ttl=55 time=31.554 ms
64 bytes from 94.254.0.25: icmp_seq=6 ttl=55 time=31.247 ms
64 bytes from 94.254.0.25: icmp_seq=7 ttl=55 time=34.498 ms
.container
h1.header
ul.items
li
a.name
.empty
var context, directives;
context = {
"header": "Colors",
"items": [
{"name": "red", "first": true, "url": "#Red"},
{"name": "green", "link": true, "url": "#Green"},
{"name": "blue", "link": true, "url": "#Blue"}
],
"empty": false
var ctx = {
name: 'jude'
};
var tpl = "hey {{ name }}, don't make it bad";
var res = tpl.replace(/\{\{([a-zA-Z ]*)\}\}/g, function(m, g) {
return ctx[g.trim()];
});
console.log(res);
<h1>{{header}}</h1>
{{#items}}
{{#first}}
<li><strong>{{name}}</strong></li>
{{/first}}
{{#link}}
<li><a href="{{url}}">{{name}}</a></li>
{{/link}}
{{/items}}
h1= header
for item in items
if item.first
li: strong= item.name
if item.link
li: a(href= item.url)= item.name
if empty
p The list is empty.
@bebraw
bebraw / data.json
Last active December 15, 2015 14:08
{
"header": "Colors",
"items": [
{"name": "red", "first": true, "url": "#Red"},
{"name": "green", "link": true, "url": "#Green"},
{"name": "blue", "link": true, "url": "#Blue"}
],
"empty": false
}
@bebraw
bebraw / partial.js
Last active December 12, 2015 09:09
Partial test.
var gt = partialize(function(a, b) {
return a < b;
}, 2);
function partialize(fn, amount) {
return function() {
return partial(fn, arguments);
}
};