Skip to content

Instantly share code, notes, and snippets.

View rodneyrehm's full-sized avatar

Rodney Rehm rodneyrehm

View GitHub Profile
@rodneyrehm
rodneyrehm / datauri.php
Created November 17, 2011 09:12
PHP: datauri.php - convert image to data-uri
#!/opt/local/bin/php
<?php
/*
1) replace the shebang (first line) with the path to your php binary
(probably something like /usr/bin/php)
2) move the file to /usr/local/bin/datauri.php
(this should be in your PATH)
3) chmod ugo+rx /usr/local/bin/datauri.php
(make the script executable for everyone)
@rodneyrehm
rodneyrehm / html5-video.sh
Created December 6, 2011 20:14 — forked from yellowled/ffmpeg-html5
Convert videos to proper formats for HTML5 video on Linux shell using ffmpeg.
#!/bin/sh
# configure stuff
width=640
height=320
size=$width"x"$height
# show help
if [[ "$1" == "" || "$1" == "-h" || "$1" == "--help" ]]; then
echo "USAGE: ";
@rodneyrehm
rodneyrehm / URL.php
Created December 19, 2011 22:40
PHP: URL wrangler class
<?php
declare( encoding = 'UTF-8' );
namespace shurlook\net
{
class URL
{
const PROTOCOL = 'scheme';
const HOST = 'host';
@rodneyrehm
rodneyrehm / .htaccess
Created December 25, 2011 14:07
URL-Rewriting: Peter Kröner
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/excluded-directories-like-css-or-js/
RewriteRule ^(.*)$ not-found.php [QSA,L]
@rodneyrehm
rodneyrehm / test.php
Created February 22, 2012 10:40
PHPGangsta: Doppelte Array-Einträge entfernen
<?php
if (extension_loaded('xdebug')) {
echo "WARNING: xdebug is enabled\n";
}
function _count()
{
$array = array(1, 5, 8, 'Michael', 5, 4, 9, 'Martin', 18, 12, 'Michael', 4, 12);
@rodneyrehm
rodneyrehm / prefilter.whitespace_control.php
Created March 7, 2012 17:36
Smarty: Whitespace Control
<?php
$string = '{foreach $element->children as $c}
{-if $c->max_count == 1}
{-$c->getClassName()} {$c->getMemberVariableName()-};
{-else-}
{$c->getClassName()} {$c->getMemberVariableName()};
std::vector<{$c->getClassName()}> {$c->getMemberVariableName()}s;
{-/if-}
{-/foreach} hello
@rodneyrehm
rodneyrehm / smarty.recompiling-file-resource.php
Created March 27, 2012 11:19
Smarty: Recompiling File Resource
<?php
/*
This hack is supposed to help using regular file-based templates without writing to compiled_c directory. This should only be used in installers or similar!
*/
// load smarty
require_once '…/Smarty.class.php';
// extend regular File Resource to suggest a source must be recompiled on every invocation
@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';
@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 / urlify.js
Last active October 4, 2015 07:37
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);