Skip to content

Instantly share code, notes, and snippets.

View enov's full-sized avatar

Samuel Demirdjian enov

View GitHub Profile
@wilmoore
wilmoore / SplClassLoader.php
Created June 5, 2010 04:25 — forked from jwage/SplClassLoader.php
PHP 5.3 Namespace Autoloader
<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.
@loonies
loonies / 1_phpunit-api.md
Last active January 19, 2024 07:34
PHPUnit Cheat Sheet

PHPUnit API reference

  • version 3.6

TODO

Check those constraints:

$this-&gt;anything()
@kemo
kemo / Cached.php
Created April 27, 2012 21:36
Cache-powered ORM model extension (Kohana 3.3) - [!!] Not tested
<?php defined('SYSPATH') or die('No direct script access.');
/**
* Extend this class if you want your model cached. Example usage:
*
* 1. Model
* class Model_User extends ORM_Cached {}
*
* 2. Usage
*
@joni
joni / STRINGDECODE.sql
Created June 19, 2012 19:35
STRINGDECODE: MySQL function to decode unicode escapes to utf8
CREATE FUNCTION STRINGDECODE(str TEXT CHARSET utf8)
RETURNS text CHARSET utf8 DETERMINISTIC
BEGIN
declare pos int;
declare escape char(6) charset utf8;
declare unescape char(3) charset utf8;
set pos = locate('\\u', str);
while pos > 0 do
set escape = substring(str, pos, 6);
set unescape = char(conv(substring(escape,3),16,10) using ucs2);
@mindplay-dk
mindplay-dk / reflection-bench.php
Created August 15, 2012 12:40
A benchmark of reflection API performance in PHP
<?php
/**
* Benchmark: Reflection Performance
*
* Conclusion: there is no performance-gain from caching reflection-objects.
*/
define('NUM_TESTS', 10);
@leedavis81
leedavis81 / ShutdownProcess.php
Created October 17, 2012 10:05
PHP Register shutdown handler - allows unregistering
<?php
/**
* Shutdown process handler, allows you to unregister a process (not supported natively in PHP)
* Usage:
* $sd = new System_ShutdownProcess($callable);
* $sd->register() /// $sd->unregister()
* or via factory
* $sd = System_ShutdownProcess::factory($callable)->register()
*/
@atannus
atannus / kohana.php
Created July 6, 2013 19:38
Quick hack to allow Kohana to handle memory_limit and max_execution_time violations.
<?php defined('SYSPATH') or die('No direct script access.');
class Kohana extends Kohana_Core {
/**
* Augments the core method for two reasons:
* 1) Reserve an extra 1M memory to allow handling memory_limit violation.
* 2) Reserve more exec time to allow max_execution_time violation.
*
* Note: keep variable creation at a minimum.
@ha1t
ha1t / array_walk_test.php
Created August 11, 2013 06:39
array_walk() to destroy the internal array pointer
<?php
echo phpversion() . PHP_EOL;
$lists = array('hoge');
array_walk($lists, 'trim');
if (current($lists) !== false) {
echo 'o';
} else {
echo 'x';
}
@birkir
birkir / multiquery.php
Created November 28, 2013 10:05
Multiquery adapter for MySQLi database driver
<?php
class MySQLi_Database extends Database {
...
public function multiquery($sql)
{
// Make sure the database is connected
@birkir
birkir / Result.php
Last active December 29, 2015 15:19
Fix mysql Database driver for hhvm
<?php
class Database_MySQL_HHVM_Result {
protected $_ref;
public function current()
{
if ($this->_current_row !== $this->_internal_row AND ! $this->seek($this->_current_row))
return NULL;