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 / ObjectTrait.php
Created July 2, 2011 04:20
Nette\ObjectTrait
<?php
/**
* This file is part of the Nette Framework (http://nette.org)
*
* Copyright (c) 2004, 2011 David Grudl (http://davidgrudl.com)
*
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
*/
@dg
dg / MultiplierControl.php
Created October 6, 2011 15:18
MultiplierControl
<?php
class MultiplierControl extends Nette\Application\UI\Control
{
private $factory;
public function __construct($factory)
{
@dg
dg / gist:2338940
Created April 8, 2012 18:22
Stylus error
body {
color: blue;
}
@dg
dg / fibonacci.js
Last active October 2, 2015 23:07
Fibonacci number benchmark
// fibonacci(40) takes 2 seconds in Node.js 0.6.14
// http://en.wikipedia.org/wiki/Fibonacci_number
function fibonacci(n) {
return n < 2 ? n : fibonacci(n-2) + fibonacci(n-1);
}
@dg
dg / gist:2891542
Created June 7, 2012 21:10
Nette Framework Forms, year 2006
<?php
// history of Nette Framework Forms, year 2006
class NHtml
{
static protected $empty = array('img'=>1,'hr'=>1,'br'=>1,'input'=>1,'meta'=>1,'area'=>1,'base'=>1,'col'=>1,'link'=>1,'param'=>1);
static public function tag($tag, $attrs=NULL, $content=NULL)
@dg
dg / gist:3644321
Created September 5, 2012 20:36
Texy on nette.org
<?php
/**
* Texy parser for wiki page.
*/
class Parser extends Nette\Object
{
/**
* @return void
@dg
dg / gist:5090424
Last active December 14, 2015 12:59
Pár tipů, co by bylo fajn zlepšit na novém Zdroják.cz

Homepage

  • chybí odkaz na zprávičky
  • odkaz "Další články" dole nevede na další články, ale na první články
  • tři hlavní články se opticky slévají
  • není úplně zřejmá souvislost tří horních článků a pravého sloupce (a zpráviček)
  • pouze na homepage je levý sloupec ten vedlejší
  • v levém sloupci je proklikávací pouze nadpis Root.cz
  • odkaz na poštovní obálku vede na jakýsi obrázek
@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 / ssl.conf
Created December 14, 2015 21:37
Redirect to HTTPS for all except Windows XP
server {
...
listen 443 ssl;
listen 80;
if ($server_port = 80) {
set $xp A;
}
@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);