Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

David Grudl dg

🏠
Working from home
Block or report user

Report or block dg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View TestCase.php
<?php
/**
* This file is part of the Nette Tester.
* Copyright (c) 2009 David Grudl (http://davidgrudl.com)
*/
namespace Tester;
@dg
dg / gist:9932198
Created Apr 2, 2014
Latte example
View gist:9932198
<table n:if="$items">
<tr n:foreach="$items as $item">
<td>{$item->title}</td>
...
</tr>
</table>
View after.php
<?php
class FooControl extends Nette\Application\UIControl
{
public function render()
{
MyTemplate::registerFilters($this->template)
->render(__DIR__ . '/control.latte');
}
View gist:7d503bbe93874309ddfa
services:
- RouterFactory()::createRouter(%mode%)::start()
- MyClass( @service(123)::foo(), abc )
View gist:dbe8c58e5866d9fe5bf9
# spaces are OK
- key1: # empty means NULL
key2: hello
key3: 123
# tabs are confusing
- key1:
key2: hello
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 / 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) );
@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 / 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 / remotepick.bat
Created Apr 4, 2011
usage: remotepick nette kravco e7a90dd
View remotepick.bat
call git remote add temp http://github.com/%2/%1.git
call git fetch temp
call git cherry-pick %3
call git remote rm temp
You can’t perform that action at this time.