Skip to content

Instantly share code, notes, and snippets.

@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()
@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 / 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 / Test-for-auto-wrapped-privates.markdown
Last active December 27, 2015 20:49
A Pen by Keili Olsen.
@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 / rapid-stache.js
Last active August 8, 2016 07:14
Rapid-stache
/**
* This doesn't pretend to be a proper, or fully-featured templating library
* it's merely a light-weight one used for rapid prototyping.
* Anti-Features:
* - no precompilation
* - no fancy iteration or repeats
* - pretty much nothing except string replacement
* - basic filters
*
* https://gist.github.com/pentaphobe/7955994
@pentaphobe
pentaphobe / EMES-micro-events.markdown
Last active January 4, 2016 04:39
A Pen by Keili Olsen.
/**
* A dodgy and simple profiler wrapping thingy
*
* It don't do much, but I whipped this up as a basic helper for a coworker so may as well store for later :)
*
*/
/**
* @param {Function} fn The function you wish to profile
* @param {Object} scope The 'this' property to bind
@pentaphobe
pentaphobe / README.md
Created March 5, 2014 01:13
Rudimentary Bash events

Rudimentary Shell Events

Sometimes I want commands in one terminal to happen only after commands in another terminal have finished.

This is a temporary solution to a problem likely better solved by someone else somewhere :)

Usage

In one terminal:

@pentaphobe
pentaphobe / element.filter.js
Created November 15, 2016 06:18
Filter function for Angular's jqlite element
/**
* Adds a filter() method to Angular's jqlite
*/
(function (angular) {
/**
* Polyfill from MDN (mostly to cover IE9 and edge browsers)
* https://developer.mozilla.org/en/docs/Web/API/Element/matches
*/
if (!Element.prototype.matches) {