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
@dg
dg / gist:5616877
Created May 21, 2013 01:09
Workaround for missing ::class in PHP < 5.5
<?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 ;)
@dg
dg / output detector.php
Created June 20, 2013 18:59
How can I find out where my output started?
<?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 / websocket.html
Created August 11, 2013 15:54
WebSocket communication between PHP and single client
<!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) {
<?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
@dg
dg / Nette
Created August 19, 2014 21:32
DI: Symfony versus Nette
services:
newsletter_factory: NewsletterFactory
newsletter_manager: @newsletter_factory::get(@templating)
<td><span class=select>[email protected]</span></td>
<script>
$('.select').click(function(){
var range = document.createRange();
range.selectNodeContents(this);
window.getSelection().addRange(range);
});