Skip to content

Instantly share code, notes, and snippets.

View bdelespierre's full-sized avatar
🚩
Working from home

Benjamin Delespierre bdelespierre

🚩
Working from home
View GitHub Profile
@bdelespierre
bdelespierre / phpbug#54547_workaround
Created May 9, 2012 09:53
PHP Bug #54547 Workaround
// Case 1
// will display '9223372036854775807 equals 9223372036854775808'
// bug https://bugs.php.net/bug.php?id=54547
$a = '9223372036854775807';
$b = '9223372036854775808';
if ($a == $b)
echo "$a equals $b\n";
@bdelespierre
bdelespierre / md5.php
Last active December 12, 2015 00:29
Get the md5 of your whole PHP application
<?php
function glob_recursive($pattern, $flags = 0) {
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
$files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags));
}
return $files;
}
@bdelespierre
bdelespierre / lines.php
Last active December 12, 2015 01:38
Ever wondered how many lines you've written in your PHP project ? This is almost the most useless script in history but I'm kinda curious so I wrote it anyway...
<?php
set_time_limit(0);
function glob_recursive($pattern, $flags = 0) {
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
$files = array_merge($files, glob_recursive($dir.'/'.basename($pattern), $flags));
}
return $files;
}
@bdelespierre
bdelespierre / singleton.php
Created March 14, 2013 16:57
Singleton (boo) + Adapter (yay)
<?php
class Singleton {
public static $aliases = array();
protected static $_adapters = array();
public function __construct () {
throw new LogicException("you cannot instanciate Singleton");
@bdelespierre
bdelespierre / gist:5533867
Last active February 3, 2017 09:49
A very simple PHP chat on 1 instruction (no loop, no closure, no control structure)
<?php ($_='[["accueil","messages","contact","vider"],["Menu","Votre message","d/m/Y H:i:s","message","Envoyer","Me Contacter","benjamin.delespierre@gmail.com","chat.log","Fichier supprim&eacute;","Messages"]]') &&($_GET+=['p'=>null]) &&in_array($p = $_GET['p'], (($j=json_decode($_,true))&&($s=$j[0])&&($w=$j[1])) ? $s : array()) ?($s[0]==$p &&array_shift($s) &&print('<h1>'.$w[0].'</h1><ul><li>'.implode('</li><li>',array_map('sprintf',array_fill(0, count($s), '<a href="?p=%s">%s</a>'),$s,$s))))||($r=sprintf('<a href="?p=%s">%s</a>',$s[0],$s[0])) &&(($s[1]==$p &&vprintf('<h1>%s</h1>%s<hr/>%s<hr/>'.$r,array($w[3],sprintf('<form action="?p=%s" method="post"><input name="n" placeholder="%s"><button type="submit">%s</button></form>',$p,$w[1],$w[4]),((isset($_POST['n']) &&($h = fopen($w[7],'a+')) &&fwrite($h, date($w[2]).": {$_POST['n']}\n")) ? '' : '').'<p>'. implode('</p><p>',is_file($w[7]) ? array_reverse(file($w[7])) : array()). '</p>')))||($s[2]==$p &&printf('<p><a href="mailto:%s">%s</a></p>'.$r,$w[6],$w[5]))||
@bdelespierre
bdelespierre / gist:5721169
Created June 6, 2013 12:35
DOMReady event, quick'n'dirty.
(function domReady (callback) {
!/in/.test(document.readyState)
? setTimeout(function () { domReady(callback) }, 1000)
: callback();
})(function () {
console && console.log('dom is ready');
});
@bdelespierre
bdelespierre / gist:5876883
Created June 27, 2013 14:29
X11 colors names in JSON
[
{
"name": "Pink",
"hex": "ffc0cb",
"rgb": "255,192,203"
},
{
"name": "LightPink",
"hex": "ffb6c1",
"rgb": "255,182,193"
(function () {
'use strict';
var get_synchronizer = function (delay, callback) {
var pretime = new Date().getTime();
return function () {
var curtime = new Date().getTime();
console.log(curtime - pretime);
if (curtime - pretime >= delay) {
callback();
@bdelespierre
bdelespierre / gist:7004662
Created October 16, 2013 08:47
Easily launch any virtualbox vm in headless mode or stop it using a simple configuration file
#!/bin/bash
function usage {
echo "Usage: $0 [file] [start|stop|status|connect]"
}
if [ -z $1 ]; then
usage
exit 0
fi
<?php
spl_autoload_register(function($classname) {
if (strpos($classname, '\\with') === false)
return false;
list($namespace, $class) = str_split($classname, strrpos($classname, '\\'));
$class = substr($class, 1);
$parts = explode('\\with', $classname);