Skip to content

Instantly share code, notes, and snippets.

View bebraw's full-sized avatar

Juho Vepsäläinen bebraw

View GitHub Profile
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);
@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
}
<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 / 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);
}
};
@bebraw
bebraw / structure.md
Last active December 11, 2015 14:58

JS Developer's Survival Guide

  • Welcome to the Jungle - Guns N' Roses - jungle.asyncjs.com
  • JavaScript Garden?
  • Special Features
    • Hoisting (scope!)
    • Closures (and how to get most out of those)
    • Prototypes (vs. classes as in Java etc.)
    • ???
  • Common Problems
@bebraw
bebraw / actions.js
Last active October 28, 2015 10:23
Reflux + Axios.
'use strict';
var Reflux = require('reflux');
var axios = require('axios');
var Actions = Reflux.createActions({
load: {
children: ['completed', 'failed']
}
});
@bebraw
bebraw / 3-colorpickers.yml
Created December 5, 2012 19:06
Color picker blog post
type: rating
title: JavaScript Color Pickers
user: bebraw
slug: javascript-color-pickers
includes: [nativeColorPicker, colorjoe, Flexi Colorpicker, SimpleColor, ExColor, JavaScript Colorpicker, Farbtastic, mooRainbow, jPicker]
body: |
If you are building an application that deals with graphics somehow, you are likely going to need a color picker. Fortunately
there are quite a few of those available for JavaScript. HTML5 includes `color` input type even. One color picker, aptly
named `nativeColorPicker`, provides a shim for Internet Explorer so that you have got all bases covered. Other pickers
available are more specialized.
@bebraw
bebraw / chunk.js
Created November 28, 2012 16:02
Type annotations + QC
define(['../common/annotate', '../math/range', '../functional/map', '../operators/gt'], function(annotate, range, map, gt) {
function chunk(len, a) {
return map(function(k) {
return a.slice(k, k + len);
}, range(0, a.length, len));
}
return annotate(chunk, gt(0), Array);
});