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 / 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
@dg
dg / gist:1009307
Created June 5, 2011 19:29
Routing in Django verus Nette Framework

DJANGO

In urls.py

# urls like "articles/2011/tutorial03" or "articles/2011/tutorial03.html" or "articles/2011/tutorial03.htm"

urlpatterns = patterns('',
    (r'articles/(?P<year>\d+)/(?P<item>[^/]+)(?:\.htm(?:l)?)?/?\$', 'articles.detail'),
)
@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 / template.latte
Created August 26, 2011 04:34
Výhody šablonovacího systému Latte

Zadáním je jednoduchý a zcela běžný úkol:

  • vypisuju nebufferované data z databáze (tj. neznám dopředu počet položek) jako elementy
  • každý lichý bude mít class="lichy"
  • poslední bude mít třídu class="posledni" (tedy class="posledni lichy", bude-li poslední zároveň lichý)
  • protože jsme puntičkáři, nechceme v kódu žádné prázdné
  • apod.
  • a samozřejmě veškerý výstup musí být escapovaný (tj. ošetřený)
@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