Skip to content

Instantly share code, notes, and snippets.

View dg's full-sized avatar
🏠
Working from home

David Grudl dg

🏠
Working from home
View GitHub Profile
@dg
dg / typehints.php
Created May 27, 2020 18:35
Typehints for PHP 7.4
<?php
declare(strict_types=1);
require '/nette.phar';
class TypeHints
{
public $ignoredTypes = ['mixed', 'resource'];
@dg
dg / patch-CVE-2020-15227.php
Last active January 2, 2025 00:18
CVE-2020-15227 nette/application RCE in-place patch
<?php
# In-place apply the CVE-2020-15227 nette/application patch
# This is a universal patcher for all affected versions.
# Run with `php patch-CVE-2020-15227.php`
# Inspiration: @spazef0rze
@dg
dg / composer-frontline.php
Last active May 17, 2025 20:05
Composer Frontline: Updates all the version constraints of dependencies in the composer.json file to their latest version.
<?php
declare(strict_types=1);
// Updates all the version constraints of dependencies in the composer.json file to their latest version.
//
// usage: composer-frontline.php (updates all Nette packages)
// composer-frontline.php doctrine/* (updates all Doctrine packages)
// composer-frontline.php * (updates all packages)
@dg
dg / benchmark.php
Created February 2, 2021 18:23
Benchmark Tracy Dumper vs Symfony VarDumper
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
// create container
$configurator = new Nette\Configurator;
$configurator->setTempDirectory(__DIR__ . '/temp');
@dg
dg / example.php
Created September 27, 2021 11:51
Standalone Nette Forms example [en]
<?php
declare(strict_types=1);
if (@!include __DIR__ . '/../vendor/autoload.php') {
die('Install packages using `composer require nette/forms`');
}
use Nette\Forms\Form;
@dg
dg / example.php
Created September 27, 2021 11:51
Standalone Nette Forms example [cs]
<?php
declare(strict_types=1);
if (@!include __DIR__ . '/../vendor/autoload.php') {
die('Nainstalujte balíčky pomocí `composer require nette/forms`');
}
use Nette\Forms\Form;
@dg
dg / git2json.py
Last active October 27, 2021 19:50
Git log to JSON
# install pygit2: pip install pygit2
import pygit2
import json
repo = pygit2.Repository('path/to/repository')
last = repo[repo.head.target]
data = []
for commit in repo.walk(last.id):
@dg
dg / counter.php
Created April 6, 2022 14:26
Pair / unpair {label} counter
<?php
$path = getcwd();
echo "Scanning $path\n";
$it = new RecursiveDirectoryIterator($path);
$it = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::LEAVES_ONLY);
$it = new RegexIterator($it, '~\.latte$~');
$countPair = 0;
$countUnpair = 0;
foreach ($it as $file) {
@dg
dg / nette-events.php
Created February 8, 2023 17:22
Nette Events
<?php
class Circle
{
public array $onChange = [];
public float $radius = 0;
public function setRadius(float $radius): void
{
foreach ($this->onChange as $handler) {
@dg
dg / Psr11ContainerAdapter.php
Last active December 10, 2024 00:04
PSR-11 adapter for Nette DI Container
<?php
declare(strict_types=1);
use Nette\DI\Container;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
// ↓ For the sake of this example, I'm implementing these two ↓