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 / typehints.php
Last active May 31, 2018 15:21
Converts @param & @return to native PHP typehints
<?php
declare(strict_types=1);
require '/nette.phar';
class TypeHints
{
public $php71 = true;
@dg
dg / gist:92b041f0315a5fe5745819b180bf7237
Created April 20, 2017 18:12
Chrome DevTools failing example
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<div style="width: 300px; height: 300px; background: blue"></div>
@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 / 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 / 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 / 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: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: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 / 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:2338940
Created April 8, 2012 18:22
Stylus error
body {
color: blue;
}