Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View rodneyrehm's full-sized avatar

Rodney Rehm rodneyrehm

View GitHub Profile
@rodneyrehm
rodneyrehm / urlify.php
Created April 8, 2011 11:52
Reduce (UTF-8) strings to alphanumeric
<?php
/*
consider decomposing the characters to "capture" more "obscure" characters such as ṩ
- http://www.php.net/manual/en/normalizer.normalize.php#92592
*/
/**
* Normalize a string to only contain alphanumeric characters and dashes.
*
@rodneyrehm
rodneyrehm / list.php
Created June 19, 2011 13:11
`ls -alhR` for the SSH-deprived
<?php
if (!empty($argv[1])) {
// directory given by CLI argument: list.php /foo/bar
$dir = $argv[1];
} elseif (!empty($_GET['dir'])) {
// directory given by HTTP: /list.php?dir=/foo/bar
$dir = $_GET['dir'];
} else {
// no directory given, use the one list.php is in
@rodneyrehm
rodneyrehm / jquery.removeAfter.js
Created June 28, 2011 14:35
jQuery.removeAfter()
/*
* adds "remove" event triggered when a DOMNode is removed,
* allowing to register DOM elements to be removed when a
* given other element is removed from dom.
*
* (last tested with jQuery 1.4.4)
*/
(function($,undefined){
// register node to be removed when the base node is removed
@rodneyrehm
rodneyrehm / jquery.removeClass.js
Created August 13, 2011 12:11
$.fn.removeClass(RegExp);
/*
* allow to pass a RegExp to remove class
* Example:
* $('.foobar).removeClass(/some-pattern-[a-z]+/g);
*/
var $removeClass = $.fn.removeClass;
$.fn.removeClass = function(className) {
if (className.constructor.name === "RegExp") {
return $removeClass.call(this, function() {
return (this.className.match(className) || []).join(' ');
@rodneyrehm
rodneyrehm / biolab-continous-fire.js
Created August 16, 2011 19:01
Biolab auto-fire cheat
/*
* cheap Biolab auto-firing cheat
* Shoot 10x per second without hitting the c key
* simply run this in your console
*/
window.setInterval(function() {
// fire the "c" keydown event
var evt = document.createEvent("KeyEvents");
evt.initKeyEvent("keydown", 1, 1, null, false, false, false, false, 67, 0);
document.dispatchEvent(evt);
@rodneyrehm
rodneyrehm / watermark.imagick.php
Created August 22, 2011 09:01
Watermark with IMagick
<?php
// Watermark with Imagick
// load images
$image = new Imagick("image.jpg");
$watermark = new Imagick("watermark.png");
// translate named gravity to pixel position
$position = gravity2coordinates($image, $watermark, 'lowerRight', 5, 5);
// compose watermark onto image
@rodneyrehm
rodneyrehm / extract-attributes.php
Created October 15, 2011 09:45
extracting attributs from <element attr="value" attr2=val attr3='val'>
<?php
// extracting attributes
// http://stackoverflow.com/questions/7776469/preg-match-with-name-being-last-in-input
$expected = array(
'value' => 'joe',
'type' => 'hidden',
'name' => 'firstname',
);
@rodneyrehm
rodneyrehm / mb_range.php
Created October 22, 2011 15:35
PHP: mb_range() - Unicode compatible range('A', 'Z')
<?php
mb_internal_encoding('UTF-8');
/**
* multibyte string compatible range('A', 'Z')
*
* @param string $start Character to start from (included)
* @param string $end Character to end with (included)
* @return array list of characters in unicode alphabet from $start to $end
@rodneyrehm
rodneyrehm / FileDownload.php
Created October 23, 2011 19:26
PHP: FileDownload
<?php
class FileDownload
{
public static $_response_status = array(
200 => 'OK',
201 => 'Created',
204 => 'No Content',
206 => 'Partial',
207 => 'Multi-Status', // WTF ??
@rodneyrehm
rodneyrehm / number.inrange.js
Created October 25, 2011 10:25
JS: Integer Range Validation
// regarding http://stackoverflow.com/questions/7887157/constructing-regular-expressions-to-match-numeric-ranges
function IntRangeTest(expression) {
var tests = [];
/*
possible expressions:
"*" - any integer
"0,3-4" - 0 or between 3 and 4
"0,-10--4" - 0 or between -10 and -4