Skip to content

Instantly share code, notes, and snippets.

<?php
// ****************************************************************
// Please note: An improved version of the class has been added to:
//
// https://github.com/mermshaus/kaloa-filesystem
//
// The code in this Gist is deprecated.
// ****************************************************************
#!/bin/bash
# marc-watchphp -- Executes a PHP script file when its content changes.
#
# Usage: $ marc-watchphp <file>
#
# Working directory MUST be file's directory. Press Ctrl-C to stop.
inotifywait -q -m -e close_write,moved_to --format %e/%f . |
while IFS=/ read -r events file; do
@mermshaus
mermshaus / find-intersection.php
Last active August 29, 2015 14:07
findIntersection - Tries to find the first intersection of functions $f and $g within a given interval
<?php
/**
* Tries to find the first intersection of functions $f and $g within a given
* interval
*
* $discardExceptions allows $f and $g to reject/skip certain values (e. g.
* because of division by zero) by throwing an exception without having to stop
* the whole calculation.
*
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
@mermshaus
mermshaus / addUrlTagsToTextFilter.php
Created April 13, 2013 12:25
addUrlTagsToTextFilter
<?php
function addUrlTagsToTextFilter($text)
{
// Positionen aller url-BBCode-Elemente ermitteln
$matches = array();
preg_match_all('~\[url(?:.*?)\](?:.*?)\[/url\]~', $text, $matches, PREG_OFFSET_CAPTURE);
$bbCodeElements = $matches[0];
// Positionen aller URLs ermitteln
@mermshaus
mermshaus / org.ermshaus.Counter.bundle.php
Created March 24, 2013 17:19
A file-based hit counter implementation
<?php // File: org.ermshaus.Counter.bundle.php
namespace org\ermshaus;
use Exception;
/**
*
*/
class CounterException extends Exception
@mermshaus
mermshaus / .gitignore
Created December 7, 2012 17:12
PHP source code obfuscator
obfuscate
@mermshaus
mermshaus / phermin
Created November 4, 2012 22:32
phermin (PHP Version Manager)
#!/bin/bash
##
# phermin -- PHP Version Manager
#
# *** USE AT OWN RISK! ***
#
# Usage: phermin [<task>] [<args>]
# Author: Marc Ermshaus <marc@ermshaus.org>
# License: MIT <http://opensource.org/licenses/mit-license.php>
@mermshaus
mermshaus / SchemaValidator.java
Created August 31, 2012 09:17
Snippet for running Apache Xerces (Java version) to validate XML files with catalog and schema support
import java.io.File;
import javax.xml.XMLConstants;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.*;
import org.xml.sax.SAXException;
import com.sun.org.apache.xerces.internal.util.XMLCatalogResolver;
public class SchemaValidator
{
@mermshaus
mermshaus / groupbalances.php
Created February 5, 2012 01:41
Calculates who gets how much money back when paying expenses for a group of people
<?php
/**
* When you travel in a group and, for practical reasons, some people pay
* expenses for the whole group (hotel rooms, train tickets, ...), this class
* will help you to sort out who gets how much money back in the end.
*/
namespace foo;
use Exception;