Skip to content

Instantly share code, notes, and snippets.

View Majkl578's full-sized avatar
💥
breaking builds

Michael Moravec Majkl578

💥
breaking builds
View GitHub Profile
<?php
$H = '[0-9a-fA-F]';
$NL = '\n|\r\n|\r|\f';
$UNICODE = '\\\\' . $H . '{1,6}[ \t\r\n\f]?';
$s = '\x{80}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}';
//$s = '\X'; // tmp
$NONASCII = '[' . $s . ']';
$ESCAPE = $UNICODE . '|\\[ -~' . $s . ']';
$NMSTART = '[_a-zA-Z]|' . $NONASCII . '|' . $ESCAPE;
@Majkl578
Majkl578 / gist:1267600
Created October 6, 2011 14:54
Hosiplanova šílenost
<?php
$input = '1r3e56f8';
$merge = '6f8g';
$res = NULL;
for ($i = min(strlen($input), strlen($merge)), $l = strlen($merge); $i > 0; $i--) {
$iPart = substr($input, -$i);
$mPart = substr($merge, 0, $i);
if (substr_compare($iPart, $mPart, 0) === 0) {
@Majkl578
Majkl578 / gist:1306559
Created October 22, 2011 22:23 — forked from Solution/gist:1306541
Price
<?php
function cutPrice($price)
{
return number_format($price, is_float($price) ? 2 : 0, '.', ' ');
}
var_dump(cutPrice(12185418));
var_dump(cutPrice(12185418.4841));
@Majkl578
Majkl578 / a.php
Created December 5, 2011 02:35
PHP 5.4 (php5.4-201112050130) segmentation fault (https://bugs.php.net/bug.php?id=60444)
<?php
class Foo {
public function __construct() {
require_once __DIR__ . '/b.php';
Some::foo($this);
}
}
new Foo;
@Majkl578
Majkl578 / gist:1673061
Created January 24, 2012 22:16
PHP 5.4 traits
<?php
trait T {
public function xyz()
{
echo __TRAIT__, PHP_EOL;
}
}
class A {
@Majkl578
Majkl578 / gist:1932200
Created February 28, 2012 12:18
Standalone Nette\Http\Session
<?php
use Nette\Http;
require $libsDir . '/Nette/loader.php';
// init
$requestFactory = new Http\RequestFactory();
$session = new Http\Session($requestFactory->createHttpRequest(), new Http\Response());
@Majkl578
Majkl578 / gist:2304479
Created April 4, 2012 18:25
Tiny php script to generate simple directory index.
#!/usr/local/bin/php
<?php
/**
* @author Michael Moravec
*/
$targetDir = $argc > 1 ? $argv[1] : getcwd();
if (!is_dir($targetDir)) throw new \InvalidArgumentException("Invalid dir '$targetDir'.");
<?php
if (is_array($value) && (!isset($value['class']) || !is_scalar($value['class']))) {
throw new \InvalidArgumentException("Repository $name doesn't have defined 'class' parameter");
}
$className = is_array($value) ? $value['class'] : $value;
<?php
trait T
{
public function foo(array $x)
{
echo __METHOD__;
}
}
@Majkl578
Majkl578 / gist:2931361
Created June 14, 2012 16:33
PHP ./configure
./configure --prefix=/usr/local --localstatedir=/var --with-layout=GNU --with-config-file-path=/usr/local/etc/php --with-config-file-scan-dir=/usr/local/etc/php/conf.d --enable-shared --enable-debug --with-pear --enable-cli --enable-cgi --enable-fpm --disable-short-tags --enable-bcmath --enable-calendar --enable-exif --enable-ftp --enable-gd-native-ttf --enable-intl --enable-json --enable-mbstring --enable-soap --enable-sockets --enable-xml --enable-zip --with-bz2 --with-curl --with-enchant --with-gd --with-gettext --with-gmp --with-iconv --with-imap --with-imap-ssl --with-mcrypt --with-mhash --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-mhash --with-mysql-sock=/var/run/mysqld/mysqld.sock --with-openssl --with-pcre-regex --enable-pdo --with-pdo-mysql=mysqlnd --with-pdo-pgsql --with-pdo-sqlite --with-pgsql --with-pspell --with-readline --with-snmp --with-sqlite3 --with-tidy --with-xmlrpc --with-xsl --with-zlib --without-db2 --without-db3 --with-kerberos --with-jpeg-dir=/usr/lib