Skip to content

Instantly share code, notes, and snippets.

View rodneyrehm's full-sized avatar

Rodney Rehm rodneyrehm

View GitHub Profile
@rodneyrehm
rodneyrehm / gist:2645722
Created May 9, 2012 15:44
jQuery.phase (to improve performance of heavy dom-manipulation)
/*
The point of this uitlity is to detach nodes while preserving their original
position (which $.fn.detach() doesn't) so they can be re-injected later on.
naming stuff is a bitch and "phase" ("shift phase in/out")
is the "best" (science-finctiony) word I could come up with.
got a better Idea? tell me on twitter: @rodneyrehm
ideas so far:
dompulate, teleport, phase, manipulateOffscreen
@rodneyrehm
rodneyrehm / demo-list.html
Created May 28, 2012 11:08
jQuery Snippets - jQuery.sortChildren()
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>sorting lists</title>
<script src="jquery-1.7.2.min.js"></script>
<script src="jquery.sortChildren.js"></script>
<script>
@rodneyrehm
rodneyrehm / prefilter.whitespace_control.php
Created June 28, 2012 20:44
Smarty: Whitespace Control - Prefilter Plugin
<?php
/**
* Smarty Whitespace Control
*
* {-tag} remove white space infront of tag up to the previous non-whitespace character or beginning of the line
* "text \n\n\t {-tag}" -> "text \n\n{tag}"
* "text \n\n\t text\t {-tag}" -> "text \n\n\t text{tag}"
* {--tag} remove white space infront of tag up to the previous non-whitespace character
* "text \n\n\t {--tag}" -> "text{tag}"
@rodneyrehm
rodneyrehm / parseAttributes.php
Created July 8, 2012 09:20
PHP: parse HTML element attributes
<?php
function parseAttributes($text) {
$attributes = array();
$pattern = '#(?(DEFINE)
(?<name>[a-zA-Z][a-zA-Z0-9-:]*)
(?<value_double>"[^"]+")
(?<value_single>\'[^\']+\')
(?<value_none>[^\s>]+)
(?<value>((?&value_double)|(?&value_single)|(?&value_none)))
@rodneyrehm
rodneyrehm / LazyLoad.53.php
Created July 8, 2012 12:16
PHP: Possible LazyLoad approach allowing PHP5.4 optimizations
<?php
// Transparent Lazy Loading as used up to PHP 5.3
class Foo {
public function __get($name) {
if ($name == 'lazy') {
echo "<getting>\n";
$this->lazy = $this->getLazy();
@rodneyrehm
rodneyrehm / uri-template-extracting.md
Created August 11, 2012 14:58
URI Template - extracting data

Extracting Data Through URI Templates

the following list is far from complete. It just lists what I could immediately think of…

Templates that cannot be used for extracting values:

  • http://example.com/{foo}{bar}
  • http://example.com/{foo,bar}
  • http://example.com/{?foo*}{&bar*}
  • ?one=alpha&two=bravo ~ ?two=bravo&one=alpha - while they are different URIs by way of RFC 3986, most web applications neither differentiate them, nor enforce one or the other. Since applications (usually) don't fail on "wrong parameter order", developers tend to handle this rather lax
// original
var methods = {
front: function (col) {
return this.each(function () {
$(this).css('color', col || plugin.statics.random());
});
},
back: function (col) {
return this.each(function () {
$(this).css('background-color', col || plugin.statics.random());
@rodneyrehm
rodneyrehm / README.md
Created October 29, 2012 11:53
Javascript: removing nested functions

Avoid Nesting Of Functions

Need a clear statement why: Memory issues, declaration issue, nested functions being "registered" on every invocation of containing function, …

@rodneyrehm
rodneyrehm / external-resource.php
Last active December 11, 2015 11:58
W3C-Test helper for remote resources on demand (CSS/JS/JSON/IMG, delayed response, http response code)
<?php
// moved to https://github.com/rodneyrehm/test-resource
@rodneyrehm
rodneyrehm / anti-keygrabber.user.js
Last active May 26, 2024 17:50
GreaseMonkey: Prevent Web Applications From Grabbing Certain HotKeys
// ==UserScript==
// @name anti key-grabber
// @description Prevent web apps from capturing and muting vital keyboard shortcuts
// @grant none
// @version 1.1
// ==/UserScript==
(function(){
var isMac = unsafeWindow.navigator.oscpu.toLowerCase().contains("mac os x");
unsafeWindow.document.addEventListener('keydown', function(e) {
if (e.keyCode === 116) {