Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

David Grudl dg

🏠
Working from home
View GitHub Profile
@dg
dg / counter.php
Created Apr 6, 2022
Pair / unpair {label} counter
View counter.php
<?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 / git2json.py
Last active Oct 27, 2021
Git log to JSON
View git2json.py
# 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 / example.php
Created Sep 27, 2021
Standalone Nette Forms example [cs]
View example.php
<?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 / example.php
Created Sep 27, 2021
Standalone Nette Forms example [en]
View example.php
<?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 / benchmark.php
Created Feb 2, 2021
Benchmark Tracy Dumper vs Symfony VarDumper
View benchmark.php
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
// create container
$configurator = new Nette\Configurator;
$configurator->setTempDirectory(__DIR__ . '/temp');
@dg
dg / composer-frontline.php
Last active Feb 9, 2022
Composer Frontline: Updates all the version constraints of dependencies in the composer.json file to their latest version.
View composer-frontline.php
<?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 / patch-CVE-2020-15227.php
Last active Dec 22, 2020
CVE-2020-15227 nette/application RCE in-place patch
View patch-CVE-2020-15227.php
<?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 / typehints.php
Created May 27, 2020
Typehints for PHP 7.4
View typehints.php
<?php
declare(strict_types=1);
require '/nette.phar';
class TypeHints
{
public $ignoredTypes = ['mixed', 'resource'];
@dg
dg / StrictObject.php
Created Jun 11, 2018
Nette\StrictObject, simplified alternative for Nette\SmartObject (compatible with nette/utils 2.4)
View StrictObject.php
<?php
/**
* This file is part of the Nette Framework (https://nette.org)
* Copyright (c) 2004 David Grudl (https://davidgrudl.com)
*/
namespace Nette;
use Nette\Utils\ObjectHelpers;
@dg
dg / composing.presenters.php
Created May 31, 2018
Composing presenters without inheritance
View composing.presenters.php
<?php
// composing presenters without inheritance
// (requires nette/application 2.4.11)
trait RequireLoggedUser
{
public function injectRequireLoggedUser()
{