Skip to content

Instantly share code, notes, and snippets.

View rodneyrehm's full-sized avatar

Rodney Rehm rodneyrehm

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