Skip to content

Instantly share code, notes, and snippets.

var accentMap = {
'à': 'a', 'á': 'a', 'â': 'a', 'ã': 'a', 'ä': 'a', 'å': 'a', // a
'ç': 'c', // c
'è': 'e', 'é': 'e', 'ê': 'e', 'ë': 'e', // e
'ì': 'i', 'í': 'i', 'î': 'i', 'ï': 'i', // i
'ñ': 'n', // n
'ò': 'o', 'ó': 'o', 'ô': 'o', 'õ': 'o', 'ö': 'o', 'ø': 'o', // o
'ß': 's', // s
'ù': 'u', 'ú': 'u', 'û': 'u', 'ü': 'u', // u
'ÿ': 'y' // y
@gfranko
gfranko / replayYouTubeVideo.js
Last active August 29, 2015 14:08
Replay YouTube Video
(function replayYouTubeVideo() {
var video = document.querySelector('.html5-main-video');
setInterval(function() {
if(video.currentTime === video.duration) {
video.currentTime = 0;
}
}, 5000);
}());
@gfranko
gfranko / webshot.phantom.js
Created May 30, 2014 21:45
node-webshot enhancement
// Handle customCSS option
if (typeof options.customCSS === 'string') {
page.evaluate(function(customCSS) {
var style = document.createElement('style');
var text = document.createTextNode(customCSS);
style.setAttribute('type', 'text/css');
style.appendChild(text);
document.head.insertBefore(style, document.head.firstChild);
}, options.customCSS);
}
@gfranko
gfranko / each.js
Created May 16, 2014 06:37
.each() JavaScript implementation
function each (collection, callback) {
var x, len;
if(Utils.isArray(collection)) {
x = -1;
len = collection.length;
while(++x < len) {
if (callback(x, collection[x]) === false) {
break;
}
}
@gfranko
gfranko / debounce.js
Last active August 29, 2015 14:01
Debounce Implementation
function debounce(func, wait) {
// we need to save these in the closure
var timeout, args, context, timestamp;
return function () {
// save details of latest call
context = this;
args = [].slice.call(arguments, 0);
timestamp = new Date();
// this is where the magic happens
var later = function () {
@gfranko
gfranko / index.js
Created February 11, 2014 22:21
requirebin sketch
// Node.js Environment
var code = 'function jqcon() {}',
esprima = require('esprima'),
ast = esprima.parse(code),
estraverse = require('estraverse');
estraverse.traverse(ast, {
enter: function (node, parent) {
if(node.type === 'Identifier') {
node.name = node.name + '_is_awesome';
@gfranko
gfranko / index.js
Created February 11, 2014 22:10
requirebin sketch
// Node.js Environment
var code = 'function jqcon() {}',
esprima = require('esprima'),
ast = esprima.parse(code),
estraverse = require('estraverse');
estraverse.replace(ast, {
enter: function (node, parent) {
if(node.type === 'Identifier' && node.name === 'jqcon') {
// Changes the 'jqcon' function name to 'jqcon_is_awesome'
@gfranko
gfranko / index.js
Created February 11, 2014 18:44
requirebin sketch
// Node.js Environment
var code = 'function jqcon() {}',
esprima = require('esprima'),
ast = esprima.parse(code),
estraverse = require('estraverse');
estraverse.traverse(ast, {
enter: function (node, parent) {},
leave: function(node, parent) {}
});
@gfranko
gfranko / index.js
Created February 11, 2014 17:26
requirebin sketch
// Node.js Environment
var code = 'function jqcon() {}',
esprima = require('esprima'),
ast = esprima.parse(code);
console.log('ast', ast);
@gfranko
gfranko / index.js
Created February 10, 2014 05:57
requirebin sketch
var esprima = require('esprima'),
estraverse = require('estraverse'),
escodegen = require('escodegen');
console.log('esprima', esprima);
console.log('estraverse', estraverse);
console.log('escodegen', escodegen);