Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

David Grudl dg

🏠
Working from home
View GitHub Profile
@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;
}
@dg
dg / latte-php-mix.php
Created Jul 7, 2015
Nette Sandbox ala React
View latte-php-mix.php
<?php
namespace App\Presenters;
use Nette;
use App\Model;
class HomepagePresenter extends BasePresenter
{
@dg
dg / verifyIC.php
Created Jun 30, 2015
Ověření rodného čísla a IČ
View verifyIC.php
<?php
function verifyIC($ic)
{
// be liberal in what you receive
$ic = preg_replace('#\s+#', '', $ic);
// má požadovaný tvar?
if (!preg_match('#^\d{8}$#', $ic)) {
return FALSE;
@dg
dg / demo.php
Created Mar 17, 2015
Arrays in classes can't have more than 32767 items
View demo.php
<?php
var_dump(Test::$table); // dumps empty array()
class Test
{
static $table = array(
'_0' => 1, '_1' => 1, '_2' => 1, '_3' => 1, '_4' => 1, '_5' => 1, '_6' => 1, '_7' => 1, '_8' => 1, '_9' => 1,
'_10' => 1, '_11' => 1, '_12' => 1, '_13' => 1, '_14' => 1, '_15' => 1, '_16' => 1, '_17' => 1, '_18' => 1, '_19' => 1,
@dg
dg / weak-typing.php
Created Feb 12, 2015
Weak typing in PHP
View weak-typing.php
<?php
function foo(int $bar) : int {
return $bar * 2;
}
var_dump( foo(2.5) ); // int(4) and triggers E_NOTICE - great!
// but without E_NOTICE it as bad as:
var_dump( foo((int) 2.5) );
View gist:c237aae31147a5e589d1
<td><span class=select>david@example.com</span></td>
<script>
$('.select').click(function(){
var range = document.createRange();
range.selectNodeContents(this);
window.getSelection().addRange(range);
});
@dg
dg / Nette
Created Aug 19, 2014
DI: Symfony versus Nette
View Nette
services:
newsletter_factory: NewsletterFactory
newsletter_manager: @newsletter_factory::get(@templating)