Skip to content

Instantly share code, notes, and snippets.

View gooh's full-sized avatar

Gordon Oheim gooh

View GitHub Profile
### Keybase proof
I hereby claim:
* I am gooh on github.
* I am gooh (https://keybase.io/gooh) on keybase.
* I have a public key whose fingerprint is 729C 589F B492 0AE6 C22C 08F3 73BC 4368 C9EB 252E
To claim this, I am signing this object:
@gooh
gooh / gist:4b8f9eec685f0641834d
Created April 22, 2015 12:39
Universal Data Container
<?php
class DataCollection implements \IteratorAggregate
{
private $data;
public function __construct($data)
{
$this->data = $data;
}
@gooh
gooh / gist:c8e00b99ef02a6eca602
Created June 7, 2015 10:09
Renames all files in a folder having an extension to a sequential numeric name preserving existing numerically named file names
<?php
$baseDir = $argv[1];
if (false === is_dir($argv[1])) {
die ("$baseDir is not a directory");
}
// get all files with an extension
$allFiles = array_filter(
array_map('pathinfo', glob("$baseDir/*")),
@gooh
gooh / main.rs
Created July 27, 2015 12:37
A simple secure password generator
extern crate rand;
extern crate docopt;
extern crate rustc_serialize;
use rand::{OsRng, Rng};
use docopt::Docopt;
static USAGE: &'static str = "
Usage: rpgen [options]
rpgen --help
@gooh
gooh / php_errors.txt
Created July 27, 2011 16:23 — forked from ircmaxell/php_errors.txt
All errors in the 5.3 source code tree (zend_error|php_error_docref)
./ext/bcmath/bcmath.c: php_error_docref(NULL TSRMLS_CC, E_WARNING, "Division by zero");
./ext/bcmath/bcmath.c: php_error_docref(NULL TSRMLS_CC, E_WARNING, "Division by zero");
./ext/bcmath/bcmath.c: php_error_docref(NULL TSRMLS_CC, E_WARNING, "Square root of negative number");
./ext/bz2/bz2.c: php_error_docref(NULL TSRMLS_CC, E_WARNING, "length may not be negative");
./ext/bz2/bz2.c: php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not read valid bz2 data from stream");
./ext/bz2/bz2.c: php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.", mode);
./ext/bz2/bz2.c: php_error_docref(NULL TSRMLS_CC, E_WARNING, "filename cannot be empty");
./ext/bz2/bz2.c: php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot use stream opened in mode '%s'", stream->mode);
./ext/bz2/bz2.c: php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot use stream opened in mode '%s'", stream->mode);
@gooh
gooh / xpath_match_all
Last active September 28, 2015 00:48
function for people whining that preg_match_all is less to type and concluding from it that regex must be better for parsing html than a dom parser
<?php
/**
* Run an XPath query against an HTML string and returns the results
*
* @param string $xpath The XPath query to run on $thml
* @param string $html The HTML to parse. Uses the previously used string if omitted
* @return array
*/
function xpath_match_all($query, $html = '')
{
@gooh
gooh / Dirty Casting
Last active December 13, 2015 18:39
Here be dragons and black magic!
<?php
class Caster
{
/**
* Casts an Array to an instance of a class
*
* This method will return an instance of the given $className with all
* elements in the array being public members of the instance. The method
* uses serialization to work, so no constructor will be called to get the
* instance of $className. The returned instance may behave unexpectedly
@gooh
gooh / Turn all internal functions into Closures
Last active December 13, 2015 18:39
Code to turn all defined internal functions into Closures to be able to pass them around as First Class Citizens. Not that you should do that.
<?php
$functions = get_defined_functions();
foreach($functions['internal'] as $function) {
$GLOBALS[$function] = function() use ($function) {
return call_user_func_array(
$function,
func_get_args()
);
};
@gooh
gooh / Attribute Reader
Created February 15, 2013 12:17
Just a proof of concept for an attribute reader trait
<?php
trait AttributeReader
{
/**
* Interceptor for non-accessible properties
*
* @param string $property
* @returns mixed
*/
public function __get($property)
<?php
for ($i = 1; $i <= 100; $i++) {
echo
$i % 3 === 0 ? 'Fizz' : '',
$i % 5 === 0 ? 'Buzz' : '',
$i % 3 && $i % 5 ? $i : '',
PHP_EOL;
};