Skip to content

Instantly share code, notes, and snippets.

View juliandescottes's full-sized avatar

Julian Descottes juliandescottes

View GitHub Profile
@juliandescottes
juliandescottes / gist:5967554
Last active April 26, 2024 23:02
aria:Template vs html:Template
// html
{@html:Template {
id: "fareFamilies",
type:"div",
classpath: "my.path.Template"
}/}
// aria
{@aria:Template {
id : "fareFamilies",
defaultTemplate : "my.path.Template"
{macro main()}
<h1>Hello Instant Aria Templates !!!!</h1>
{/macro}
// PARADOX ! Inception-style
var paradox = function(setSize,p){
Math.sqrt(2*setSize*Math.log(1/(1-p)))
};
// So that's the generic formula.
// Applied to the usual "over 50% of prob to have 2 people with the same birthday"
paradox(365, 0.5); // => 22.49
@juliandescottes
juliandescottes / cheap-partials.js
Last active April 26, 2024 23:03
HTML partials purely client side. 4 lines of javascript + iframes. Works on Chrome, Firefox, IE7 to IE10. That's probably not new, but I find it pretty cool for small/medium projects.
// SUPER CHEAP TEMPLATES !
window.loadCheapPartial = function (event) {
var iframe=event.target || event.srcElement, div=document.createElement("div");
// using contentWindow.document instead of contentDocument for ie6/7 compatibility
div.innerHTML = iframe.contentWindow.document.body.innerHTML;
if (div.children.length == 1) div = div.children[0];
iframe.parentNode.replaceChild(div, iframe);
};
@juliandescottes
juliandescottes / DebugMacros.tpl
Created August 13, 2013 11:50
Some helpful macros for aria templates.
// Log any object in the console
{macro _log(obj)}
${(function(){console.log(obj)})()}
{/macro}
// create a section with a one-liner : {call _section("mysection", "boundvalue", "div")/}
{macro _section(id, bindings, type, css)}
{var _gb = null /}
${(function(){_gb=function(b){return {inside:data,to:b}}})()}
@juliandescottes
juliandescottes / the-one-bookmarklet.js
Created December 2, 2014 22:19
Spawn a tiny UI to create a bookmarklet. (see comment for the bookmark-ready javascript code)
(function () {
/**
* Adapted from http://ted.mielczarek.org/code/mozilla/bookmarklet.html
*/
//*****************************************************************************
// Do not remove this notice.
//
// Copyright 2001 by Mike Hall.
@juliandescottes
juliandescottes / getpath.js
Last active April 26, 2024 23:04
getPath
module.exports = function (object, path) {
var parts = path.split ? path.split(".") : path;
try {
var node = object;
parts.forEach(function (part) {
node = node[part];
});
return node;
} catch (e) {
@juliandescottes
juliandescottes / gist:a9e9ba1ab8229653109c
Created April 30, 2015 20:57
Moz devtools workflow
hg up fx-team
hg pull -u fx-team
hg up my-feature
hg rebase -d fx-team
[[1,2],[3,4],[5,6]].reduce(function (previous, n) {
return previous.concat(n)
}, [])
http://lorempixel.com/640/480/abstract/