Skip to content

Instantly share code, notes, and snippets.

View ralt's full-sized avatar

Florian Margaine ralt

View GitHub Profile
@ralt
ralt / gist:4061749
Created November 12, 2012 20:42
My Library when IE8 won't be supported anymore
NodeList.prototype.forEach = HTMLCollection.prototype.forEach = Array.prototype.forEach;
NodeList.prototype.map = HTMLCollection.prototype.map = Array.prototype.map;
NodeList.prototype.filter = HTMLCollection.prototype.filter = Array.prototype.filter;
NodeList.prototype.reduce = HTMLCollection.prototype.reduce = Array.prototype.reduce;
NodeList.prototype.every = HTMLCollection.prototype.every = Array.prototype.every;
NodeList.prototype.some = HTMLCollection.prototype.some = Array.prototype.some;
var By = {
id: function (id) { return document.getElementById(id) },
tag: function (tag, context) {
return (context || document).getElementsByTagName(tag)
@ralt
ralt / amd.js
Created November 22, 2012 12:46
AMD vs CommonJS
define(['some', 'dep'], function(some, dep) {
'use strict';
some.code = dep();
});
define(function () {
function getAllPaths() {
return [{
path: "",
url: "ui/notifications",
callback: function (notifications) {
notifications.init()
}
}, {
path: "option=com_community&view=profile",
@ralt
ralt / test.js
Created December 7, 2012 15:31
information hiding in closures
var hidden;
module.exports = {
public: function() {
return hidden;
}
};
@ralt
ralt / app.js
Created December 7, 2012 15:38
Cached exports example
var lib = require('./lib'),
lib2 = require('./lib2');
lib2.f();
console.log(lib.a); // 2
@ralt
ralt / gist:4380167
Created December 26, 2012 12:48
How to install node.js on ubuntu
#!/bin/bash
## Because the apt-get's version is way too old
sudo apt-get install g++ make git-core
git clone https://github.com/joyent/node
cd node/
git checkout v0.8.16
./configure
make
@ralt
ralt / rl-input.user.js
Last active December 11, 2015 17:28 — forked from rlemon/rl-input.user.js
// ==UserScript==
// @name rlInput box
// @author Robert Lemon
// @version 0.1
// @namespace http://rlemon.com
// @description Produces a small input area for you to execute Javascript on the page. Saves scripts in LocalStorage and executes on page load.
// @include *
// ==/UserScript==
(function () {
@ralt
ralt / mk_awsm.js
Last active December 12, 2015 01:29 — forked from Zirak/mk_awsm.js
//ths fnctn tks sntnc nd trns t t awsm
//md fr jvscrpt rm
// http://chat.stackoverflow.com/transcript/message/7491494#7491494
var mk_awsm = function(sntnc) {
return sntnc.split(' ').map(function(wrd) {
return 1 >= wrd.length ?
wrd :
2 == wrd.length ?
wrd[0] :
/:.*(.)/.test(wrd) ?
@ralt
ralt / gist:5033490
Last active December 14, 2015 05:09
Event delegation
function delegate(evt, parent, selector, fn) {
parent.addEventListener(evt, function(e) {
var elt = function find(el) {
if (el.matchesSelector(selector)) {
return el;
}
else {
if (el.parentNode !== parent) {
return find(el.parentNode);
}
@ralt
ralt / git-co
Last active December 15, 2015 00:59
Easier git checkout
#!/bin/bash
branch=$1
shift
git checkout $(git branch -a | grep $branch | head -n1) $@