Skip to content

Instantly share code, notes, and snippets.

View mklabs's full-sized avatar

Mickael Daniel mklabs

View GitHub Profile
// http://www.nczonline.net/blog/2009/07/28/the-best-way-to-load-external-javascript/
function loadScript(url, callback){
var script = document.createElement("script")
script.type = "text/javascript";
if (script.readyState){ //IE
script.onreadystatechange = function(){
if (script.readyState == "loaded" ||
script.readyState == "complete"){
@mklabs
mklabs / h5b-docs-headings.md
Created February 26, 2011 00:48
Direct links to headings on the docs page

Direct links to headings on the docs page

Currently, the wiki is already using hash anchor to manage page state. Had quickly worked a first iteration to implement this feature. We use a second # to indicate the headings we want to scroll to when the content comes in (we could use another delimiter if we want to).

  • The url part after the second # was case sensitive (internally use :contains selector) and had to match the exact heading text you'll want to refer (even with blank spaces leading to urls escaped).

Not confortable with the use of blank spaces on header (most of time got escaped), has changed to something like:

/docs/#FAQs#no-seriously-its-boilerplate-fault instead of /docs/#FAQs#No Seriously, its Boilerplate's fault!

@mklabs
mklabs / simple-cache-system.js
Created February 12, 2011 14:23
A module that acts as a service to request localy stored markdown file, this version includes a simple cache wrapper
var markdownService =(function(){
var cache = function(fn){
var c = {};
return function(file, cb) {
var item = c[file],
_cb = cb,
cb = function(r) {
var cFile = c[file];
@mklabs
mklabs / googletranslate-jquery-blog.js
Created December 28, 2010 06:31
Some DOM centric code to easily provide a raw translation using REST Google Translate API.
$.each($('#main').find('.content article').find('p, li, :header'), function(i, p){
var p = $(p);
var html = $(p).html();
$.getJSON('https://www.googleapis.com/language/translate/v2?key=AIzaSyCzfAwza3eYYFg2ketfePOAVznG4Oz0CXM&q='+html+'&source=fr&target=en&callback=?', function(results){
console.log(results);
p.html(results.data.translations[0].translatedText);
});
});
@mklabs
mklabs / get-rid-of-new.js
Created December 16, 2010 12:34
Blog post snippet.
var global = (function(){
return this;
})()
var Citizen = function Citizen(firstname, lastname){
if (this === global) {
return new Citizen(firstname, lastname);
}
@mklabs
mklabs / basic-oo.js
Created December 16, 2010 12:33
Blog post snippet.
var Citizen = function Citizen(name){
this.name = name;
};
var george = new Citizen('Abitbol');
george.name
// > "Abitbol"
@mklabs
mklabs / prototype-call.js
Created December 16, 2010 12:31
Blog post snippet.
var Citizen = function Citizen(name){
this.name = name;
};
(function(){
this.getName = function getName(){
return this.name;
};
}).call(Citizen.prototype);
@mklabs
mklabs / function-invoc.js
Created December 16, 2010 12:30
Blog post snippet.
var r = f();
<?php
header('content-type: application/json; charset=utf-8');
/* * /
$phi = array('okey' => 0, 'object' => array ("firstName"=> 'Philippe', 'lastName'=> 'Charriere'));
$j = array('okey' => 1, 'object' => array ('firstName'=> 'John', 'lastName'=> 'Resig'));
$v = array('okey' => 2, 'object' => array ('firstName'=> 'Linus', 'lastName'=> 'Torvald'));
$m = array('okey' => 3, 'object' => array ('firstName'=> 'Douglas', 'lastName'=> 'Crockford'));
/* */
function list_return(return_values){
this.Objects = return_values;
function add_li(list, text) {
var list = document.getElementById(list);
var li = document.createElement("li");
li.innerHTML = text;
list.appendChild(li);
}