Skip to content

Instantly share code, notes, and snippets.

@milo
milo / local-composer-deps-bothers.md
Created December 8, 2014 17:12
Why local composer dependencies bothers (sucks)

This is reaction to article Using local packges as composer dependencies.

The described technique bothers for two main things (mentioned on the article end):

  • after every dependency package change (even one single character) you have to commit changes
  • after that you have to call composer update (on big project, you have to wait few seconds for autoload.php is created)

My best technique is:

  • create project by composer with all dependencies
  • drop developed dependencies from composer.json and run composer update (or just delete them in vendor folder)
  • clone all dependencies into project/libs-dev/... subdirecotries (or link them by file system links)
@milo
milo / github-webhook-handler.php
Last active July 26, 2023 15:29
GitHub Webhook Handler
<?php
/**
* GitHub webhook handler template.
*
* @see https://docs.github.com/webhooks/
* @author Miloslav Hůla (https://github.com/milo)
*/
$hookSecret = 's.e.c.r.e.t'; # set NULL to disable check
@milo
milo / nette-addon-compatibility.md
Last active August 29, 2015 14:01
Nette addon compatibility solution

How to keep a Nette addon compatibility with Nette Framework 2.0, 2.1 and 2.2? Here is my fight description:

  1. Nette 2.0 Nette\Utils\PhpGenerator\ClassType vs Nette 2.1+ Nette\PhpGenerator\ClassType strict errors and Nette\Config\CompilerExtension vs. Nette\DI\CompilerExtension. This was a difficult one:
  • Create abstract BC\Extensions like this,
  • and Nette version-dependent loader like this.
  • A target extension will inherit one of them as class Extension extends BC\Extension and
  • the Composer will class-mapping different folder and hard load version-dependent loader like this.
  1. IBarPanel is solved in the same way as 1)
@milo
milo / phar-extract
Created January 4, 2014 16:29
Small PHAR extract script
#!/usr/bin/env php
<?php
error_reporting(E_ALL | E_STRICT);
$opts = getOptions();
# Help
if (array_key_exists('h', $opts)) {
echo "PHAR content extract by Milo (https://github.com/milo)\n";
@milo
milo / unexpected-closure.php
Created September 3, 2013 06:56
Unexpected PHP closure behaviour, at least for me.
<?php
$var = 'INIT';
$fGet = function() use ($var) {
echo "$var\n";
};
$fSet = function($i) use (& $var) {
$var = "I: $i";
@milo
milo / .autoprepend.php
Created August 20, 2013 07:51
Handy Tracy/Nette Debugger in autoprepend file
<?php
function __nette($version = NULL) {
if ($version) {
require "/var/www/lib/nette/$version/Nette/loader.php";
} else {
require '/var/www/dev/nette/Nette/loader.php';
}
}
@milo
milo / terminal.colors
Created May 13, 2013 21:44
Count of colors supported by terminals
# Created by commands
(for t in `find /lib/terminfo -type f`; do TERM=`basename $t`; echo $TERM `tput colors`; done) > terminfo.tmp
(for t in `find /lib/terminfo -type l`; do TERM=`basename $t`; echo $TERM `tput colors`; done) >> terminfo.tmp
sort terminfo.tmp > terminfo.txt
echo >> terminfo.txt
(for t in `find /usr/share/terminfo -type f`; do TERM=`basename $t`; echo $TERM `tput colors`; done) > terminfo.tmp
(for t in `find /usr/share/terminfo -type l`; do TERM=`basename $t`; echo $TERM `tput colors`; done) >> terminfo.tmp
sort terminfo.tmp >> terminfo.txt
<?php
require __DIR__ . '/Nette/loader.php';
debug();
$db = new Nette\Database\Connection('pgsql:host=localhost;dbname=nette_test', 'postgres');
$db->query('DROP SCHEMA IF EXISTS issue288 CASCADE');
$db->query('CREATE SCHEMA issue288');
$db->query('SET search_path TO issue288');
@milo
milo / nette-issue-930.php
Created January 18, 2013 19:29
Nette #930 issue stress code
<?php
use Nette\Diagnostics\Debugger, Nette\Caching\Cache;
require '/home/milo/dev/nette/Nette/loader.php';
set_time_limit(0);
define('TEMP_DIR', __DIR__ . '/temp');
define('LOG_DIR', __DIR__ . '/log');
@milo
milo / DibiResult.php
Created August 29, 2011 21:37
$config['formatDate'] possibility
<?php
/**
* This file is part of the "dibi" - smart database abstraction layer.
*
* Copyright (c) 2005, 2010 David Grudl (http://davidgrudl.com)
*
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
*