Skip to content

Instantly share code, notes, and snippets.

View fearphage's full-sized avatar
⌨️
Cache rules everything around me.

Phred Lane fearphage

⌨️
Cache rules everything around me.
View GitHub Profile
/*
This is a simplified sample of an idea I had today inspired by the fab
project. Event loops currently suck... so I've built this wonky DSL for you.
I'll release a real library later that actually implements some not so easy
things.
*/
(function () {
function detectMutation() {
mutationSupported = true;
this.removeEventListener('DOMAttrModified', detectMutation, false);
}
var forEach = [].forEach,
regex = /^data-(.+)/,
el = document.createElement('div'),
mutationSupported = false,
(function(window, document, undefined) {
// Enable all HTML5 elements in IE. For discussion and comments, see: http://remysharp.com/2009/01/07/html5-enabling-script/
/*@cc_on'abbr article aside audio canvas details figcaption figure footer header hgroup mark menu meter nav output progress section summary time video'.replace(/\w+/g,function(n){document.createElement(n)})@*/
var each = [].forEach || function (fn) {
var len = this.length || 0, that = arguments[1];
if (typeof fn == 'function') {
for (var i = 0; i < len; i++) {
fn.call(that, this[i], i, this);
// ==UserScript==
// @name Reddit Keyboard Navigation
// @namespace http://andrewdupont.net/greasemonkey
// @description Navigate Reddit comments. Expand, collapse, and reply
// without having to pinpoint tiny links with your mouse.
// @author Andrew Dupont
// @include http://reddit.com/*
// @include https://reddit.com/*
// @include http://*.reddit.com/*
// @include https://*.reddit.com/*
// this is how I fixed IE crashing on
// dynamic injections of AtRules inside
// stylesheets (for example @font-face)
function setStyle(rules) {
var d = document,
s = d.createElement('style'),
h = d.getElementsByTagName('head')[0] || d.documentElement;
s.type = 'text/css';
d.createElement('div').appendChild(s).styleSheet.cssText = rules;
.mouse{
position: absolute;
background-image: url('../images/cursor.png');
width: 15px;
height: 22px;
z-index: 100;
}
!function() {
var doc = document,
htm = doc.documentElement,
lct = null, // last click target
nearest = function(elm, tag) {
while (elm && elm.nodeName != tag) {
elm = elm.parentNode;
}
return elm;
};
// This might be useful for certain size-limited JS competitions, or not. #js
function super_shrinkify( str ){
var prefix = 'eval("',
suffix = '".replace(/./g,function(a){return String.fromCharCode((a=a.charCodeAt())/128,a%128)}))',
out = prefix + str.replace( /(.)(.)/g, function(a,b,c){
return String.fromCharCode( 128 * b.charCodeAt() + c.charCodeAt() );
}) + suffix;
console.log( 'overhead: ' + ( prefix.length + suffix.length ) + ' chars' );
(function () {
var forEach = [].forEach,
regex = /^data-(.+)/,
dashChar = /\-([a-z])/ig,
el = document.createElement('div'),
mutationSupported = false,
match
;
function detectMutation() {
// So what I'm doing here seems cool, but I'm not sure exactly what it should be
// called. Is this partial application? Currying? Something else? Vindaloo maybe?
//
// Either way, it's a pretty interesting pattern.. I wonder if it has any
// real-world application. Probably not.
//
// Invoking the partially applied function will always return a function until
// ALL arguments are satisfied, at which point the original function is invoked,
// returning its result. This means that all function arguments are required,
// which also allows the function to be called either like foo( 1, 2, 3 ) or