Skip to content

Instantly share code, notes, and snippets.

View rodneyrehm's full-sized avatar

Rodney Rehm rodneyrehm

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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.
*