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
<?php
/**
* This file is part of the Nette Tester.
* Copyright (c) 2009 David Grudl (http://davidgrudl.com)
*/
namespace Tester;
@dg
dg / gist:9932198
Created April 2, 2014 11:18
Latte example
<table n:if="$items">
<tr n:foreach="$items as $item">
<td>{$item->title}</td>
...
</tr>
</table>
<?php
class FooControl extends Nette\Application\UIControl
{
public function render()
{
MyTemplate::registerFilters($this->template)
->render(__DIR__ . '/control.latte');
}
services:
- RouterFactory()::createRouter(%mode%)::start()
- MyClass( @service(123)::foo(), abc )
@dg
dg / gist:dbe8c58e5866d9fe5bf9
Created May 21, 2014 11:20
Bullet & tabs problem in NEON http://ne-on.org
# spaces are OK
- key1: # empty means NULL
key2: hello
key3: 123
# tabs are confusing
- key1:
key2: hello
<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 February 12, 2015 19:59
Weak typing in 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 March 17, 2015 12:01
Arrays in classes can't have more than 32767 items
<?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 July 7, 2015 19:04
Nette Sandbox ala React
<?php
namespace App\Presenters;
use Nette;
use App\Model;
class HomepagePresenter extends BasePresenter
{
@dg
dg / remotepick.bat
Created April 4, 2011 10:25
usage: remotepick nette kravco e7a90dd
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