Skip to content

Instantly share code, notes, and snippets.

View ralt's full-sized avatar

Florian Margaine ralt

View GitHub Profile
@ralt
ralt / gist:5484237
Last active December 16, 2015 19:19
MD to HTML

The tokenizer

First, the markdown goes through the tokenizer.

The tokenizer splits by paragraphs, which gives this kind of structure:

(("text of paragraph 1") ("text of paragraph 2"))

Then, the tokenizer finds the special characters to split up words. There is then this kind of structure:

@ralt
ralt / local.js
Created March 23, 2013 21:56
LocalStorage bug?
localStorage.setItem('getItem', 4)
undefined
localStorage.getItem
function getItem() { [native code] }
localStorage['getItem'] = 'user'
"user"
localStorage.getItem
"user"
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'install',
1 verbose cli '--link' ]
2 info using npm@1.2.15
3 info using node@v0.10.1
4 verbose read json /home/florian/tmp/package.json
5 warn package.json npm-test2@1.0.0 No README.md file found!
6 verbose readDependencies using package.json deps
@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) $@
@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 / 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 / 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 / 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 / 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 / test.js
Created December 7, 2012 15:31
information hiding in closures
var hidden;
module.exports = {
public: function() {
return hidden;
}
};