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 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)
View gist:dbe8c58e5866d9fe5bf9
# spaces are OK
- key1: # empty means NULL
key2: hello
key3: 123
# tabs are confusing
- key1:
key2: hello
View gist:7d503bbe93874309ddfa
services:
- RouterFactory()::createRouter(%mode%)::start()
- MyClass( @service(123)::foo(), abc )
View after.php
<?php
class FooControl extends Nette\Application\UIControl
{
public function render()
{
MyTemplate::registerFilters($this->template)
->render(__DIR__ . '/control.latte');
}
@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 TestCase.php
<?php
/**
* This file is part of the Nette Tester.
* Copyright (c) 2009 David Grudl (http://davidgrudl.com)
*/
namespace Tester;
@dg
dg / websocket.html
Created Aug 11, 2013
WebSocket communication between PHP and single client
View websocket.html
<!doctype html>
<script>
if ("WebSocket" in window) {
var ws = new WebSocket("ws://127.0.0.1:31339");
ws.onopen = function() {
console.log('connected');
};
ws.onerror = function(e) {
@dg
dg / output detector.php
Created Jun 20, 2013
How can I find out where my output started?
View output detector.php
<?php
ob_start(function($s, $flag) {
if ($flag & PHP_OUTPUT_HANDLER_START) {
$e = new \Exception;
$s = nl2br("Output started here:\n{$e->getTraceAsString()}\n\n") . $s;
}
return $s;
}, 2);
@dg
dg / gist:5616877
Created May 21, 2013
Workaround for missing ::class in PHP < 5.5
View gist:5616877
<?php
use Nette\Http;
echo Http\Request::class; // prints 'Nette\Http\Request' since PHP 5.5
echo Http\Request\type::of; // prints 'Nette\Http\Request' alwyas ;)
You can’t perform that action at this time.