Skip to content

Instantly share code, notes, and snippets.

View rodneyrehm's full-sized avatar

Rodney Rehm rodneyrehm

View GitHub Profile
// 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 / 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
@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 / 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 / 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 / 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 / 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 / urlify.js
Last active May 8, 2024 09:36
Reduce (UTF-8) strings to alphanumeric
// port of https://gist.github.com/909692
// TODO: check char-map of https://github.com/jbroadway/urlify/blob/master/URLify.php for characters we've missed
// TODO: check performance against http://stackoverflow.com/questions/1946040/using-javascript-to-normalize-url-rewriting-strings-entered-by-users
var Urlifyer = function(options) {
var _key, _code, i, _source, _sources;
// Allow instantiation without the 'new' keyword
if (!(this instanceof Urlifyer)) {
return new Urlifyer(options);
@rodneyrehm
rodneyrehm / gist:2412756
Created April 18, 2012 10:46
PHPGangsta: Strings in String suchen
<?php
// http://www.phpgangsta.de/algorithmus-gesucht-strings-in-string-suchen
function _outputStringPositionsFunction($longText, $searchTexts) {
// of 10000 tokens only 9143 are unique
$tokens = array_unique($searchTexts);
$positions = array();
// make similar tokens appear in order
@rodneyrehm
rodneyrehm / function.booster.php
Created April 11, 2012 11:14
Smarty Booster Plugin
<?php
// tested on PHP 5.3 / Smarty 3.1
// Plugin wasn't exactly developed for convenience, more a proof of concept thingy
// This code is provided under the MIT License - http://www.opensource.org/licenses/mit-license.php
// define the (absolute) path to document_root
define('BOOSTER_HTDOCS', realpath(__DIR__ . '/../../htdocs/') . '/');
require_once BOOSTER_HTDOCS . 'booster/booster_inc.php';