Skip to content

Instantly share code, notes, and snippets.

@pentaphobe
pentaphobe / mergeArrays.js
Created November 13, 2013 17:53
Iteratively merge arrays, preserving relative order
/**
* This seems like a problem which can be solved more elegantly, but I needed this code today
* so despite a strong urge to sit down with pen and paper and relive my Godel, Escher, Bach days
* I must instead move along for now.
*
*
*/
!function() {
@pentaphobe
pentaphobe / Test-for-auto-wrapped-privates.markdown
Last active December 27, 2015 20:49
A Pen by Keili Olsen.
@pentaphobe
pentaphobe / dumpEvents.js
Created November 4, 2013 13:12
DOM Event Usage Dumper (and friends)
/**
* Handy for checking for event spamming
* @returns {Object} A map of event name to number of occurances.
*/
function getEventCounts() {
var eventCounts = {};
function incrementEventCounter( eventName ) {
eventCounts[eventName] || ( eventCounts[eventName] = 0 );
@pentaphobe
pentaphobe / function.prototype.override.js
Created September 14, 2012 13:29
How to override the function call prototype in javascript, originally a stack overflow answer
callLog = [];
/* set up an override for the Function call prototype
* @param func the new function wrapper
*/
function registerOverride(func) {
oldCall = Function.prototype.call;
Function.prototype.call = func;
}
@pentaphobe
pentaphobe / tumblr_multi_image.js
Created August 16, 2012 04:15
A bookmarklet which exposes the tumblr bookmark to multiple photo URLs (WIP)
var f=function () { var photoUrl = document.getElementById("photo_src"); photoUrl.name="external_urls[]"; photoNode = photoUrl.cloneNode(false); photoNode.id = "photo_extra"; photoNode.removeAttribute("onkeydown"); var counter = 1; var linker = document.createElement("a");linker.setAttribute("onclick", "javascript:addUrl()"); linker.innerHTML = '+'; console.log(linker); photoUrl.parentNode.insertBefore(linker, photoUrl); addUrl = function() { var newEntry = photoNode.cloneNode(false); newEntry.id += counter; counter += 1; photoUrl.parentNode.insertBefore(newEntry, photoUrl); }; console.log(photoUrl); console.log(photoNode); console.log(linker); };f()