Skip to content

Instantly share code, notes, and snippets.

View ithinkihaveacat's full-sized avatar

Michael Stillwell ithinkihaveacat

View GitHub Profile
@zarino
zarino / pseudolocalize.js
Last active February 20, 2016 16:15
A simple JavaScript function that doubles every character on a web page – useful when testing layouts for i18n issues
// Paste this function to your browser’s JavaScript console,
// and then run it, passing in a CSS selector, eg:
// > pseudolocalize('body')
var pseudolocalize = function pseudolocalize(arg){
if(typeof arg === 'string'){
var elements = document.querySelectorAll(arg);
for(var i=0, len=elements.length; i<len; i++){
pseudolocalize(elements[i]);
}
@ithinkihaveacat
ithinkihaveacat / child-process-event-helper.js
Created February 15, 2013 23:15
Creates event-listener-style communication between parent and child.
function onChild(child, event, callback) {
child.on('message', (function (args) {
if (args[0] === event) {
callback.apply(null, Array.prototype.slice.call(args, 1));
}
}));
}
function emitChild(/* child, event, [arg1], [arg2], [...] */) {
var args = Array.prototype.slice.call(arguments);
@ithinkihaveacat
ithinkihaveacat / sync-and-async-map.js
Last active September 25, 2015 02:17
Map an array, where the map function, and the result of the map, are asynchronous.
// SYNCHRONOUS MAP
function smap(src, fn) {
if (src.length == 0) {
return [];
} else {
return [fn(src[0])].concat(smap(src.slice(1), fn));
}
}