Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

David Grudl dg

🏠
Working from home
View GitHub Profile
@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 May 12, 2021
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()
{
@dg
dg / persistent.parameter.trait.php
Created May 31, 2018
Transfer of a persistent parameter between two presenters without an inheritance
View persistent.parameter.trait.php
<?php
// transfer of a persistent parameter between two presenters without an inheritance
// (requires nette/application 3.0.0)
trait LangParameter
{
/** @persistent */
public $lang;
@dg
dg / typehints.php
Last active May 31, 2018
Converts @param & @return to native PHP typehints
View typehints.php
<?php
declare(strict_types=1);
require '/nette.phar';
class TypeHints
{
public $php71 = true;
@dg
dg / gist:92b041f0315a5fe5745819b180bf7237
Created Apr 20, 2017
Chrome DevTools failing example
View gist:92b041f0315a5fe5745819b180bf7237
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<div style="width: 300px; height: 300px; background: blue"></div>
@dg
dg / ssl.conf
Created Dec 14, 2015
Redirect to HTTPS for all except Windows XP
View ssl.conf
server {
...
listen 443 ssl;
listen 80;
if ($server_port = 80) {
set $xp A;
}