Skip to content

Instantly share code, notes, and snippets.

@mageekguy
mageekguy / psr4-with-aliasing.php
Last active January 2, 2016 12:59
PSR4 autoloader with aliasing
<?php
call_user_func_array(function($namespaces, $classAliases) {
spl_autoload_register(function($class) use ($namespaces, $classAliases) {
$class = strtolower($class);
$realClass = (isset($classAliases[$class]) === false ? $class : $classAliases[$class]);
foreach ($namespaces as $namespace => $mixed)
{
@mageekguy
mageekguy / path.php
Last active January 2, 2016 11:29
New version…
<?php
namespace mageekguy\atoum\tests\units\fs;
require_once __DIR__ . '/../../runner.php';
use
mageekguy\atoum,
mageekguy\atoum\fs\path as testedClass
;
@mageekguy
mageekguy / gist:8023349
Last active December 31, 2015 17:58
POC of something which must be interesting…
<?php
namespace classception;
class asserter
{
protected $actual = null;
public function __construct($actual)
{
<?php
class logger
{
protected $name = '';
public function __construct($name)
{
$this->name = $name;
}
> Je vous écris afin de paraître dans la liste des blogs sur votre site.
>
> Comme je vous suis depuis un moment et d'autres blogs également, j'ai décidé d'ouvrir le mien.
> Tout nouveau dans la blogosphère PHP, mon blog www.mon.super.blog.de.la.mort s'articule autour du développement web PHP.
> En retour, vous serez présent dans la partner box de mon site.
La sollicitation n’est pas un bon moyen pour obtenir un backlink de ma part, bien au contraire.
Si ton blog a de l’intérêt, s’il apporte une véritable valeur ajoutée par rapport à la « concurrence », il finira par avoir son backling naturellement.
Dans le cas contraire, il n’en aura pas.
public function acceptClient($clientsSocket)
{
$this->pollSocket($clientsSocket)->onRead(array($this, __FUNCTION__));
$clientSocket = new server\socket($this->acceptSocket($clientsSocket), $this);
$timeoutHandler = function() use ($clientSocket) {
$this->writeInfo('Client ' . $clientSocket->getPeer() . ' timeout!');
$clientSocket->close();
$this->listener->onAcceptTracker(function($tracker) use ($server) {
$server->logInfo('tracker ' . $tracker->getNetworkName() . ' knocks on the door');
$tracker
->readRequest(new requests\heartbeat())
->onReadRequestOk(function($heartbeat) use ($server, $tracker) {
$tracker
->setModemId($heartbeat->getModemId())
->writeRequest($heartbeat)
->onWriteRequestOk(function($heartbeat) use ($server, $tracker) {
#!/bin/sh
[ ! -f .tags ] && echo 0 > .tags
version=$((`cat .tags`+1))
git tag 0.0.$version
echo $version > .tags
git push --tags
@mageekguy
mageekguy / gist:7302015
Last active December 27, 2015 09:09
CC
# Indenting and Whitespace
Use only tabs, with no space.
Lines should have no trailing whitespace at the end.
Files should be formatted with \n as the line ending (Unix line endings), not \r\n (Windows line endings).
PHP files should be in UTF-8.
PHP files should begin with `<?php ` and should not have a end tag (no `?>`).
The reasons for this can be summarized as:
* Removing it eliminates the possibility for unwanted whitespace at the end of files which can cause "header already sent" errors, XHTML/XML validation issues, and other problems.
* The closing delimiter at the end of a file is optional.
@mageekguy
mageekguy / gist:7216691
Created October 29, 2013 15:21
Bobo la tête !
$this
->assert('Server should throw an exception is it can not create its socket')
->given(
$server = new testedclass(),
$infoLogger = new \mock\aixia\ka\at\server\logger(),
$this->calling($infoLogger)->log->doesNothing(),
$socketTagger = new \mock\aixia\ka\socket\tagger(),
$server
->setSocketTagger($socketTagger)
->setInfoLogger($infoLogger)