Skip to content

Instantly share code, notes, and snippets.

View vojtech-dobes's full-sized avatar

Vojtěch Dobeš vojtech-dobes

View GitHub Profile
@vojtech-dobes
vojtech-dobes / gist:1297934
Created October 19, 2011 10:36
Fix for snippets rendered via Multiplier (unnecessary since 2.0.1 I guess)
<?php
// Nette/Latte/Macros/UIMacros - after line 507
$httpParams = $control->getPresenter()->getContext()->httpRequest->getQuery();
foreach ($control->getComponents(FALSE, 'Nette\Application\UI\Multiplier') as $multiplier) {
foreach ($httpParams as $param => $signal) {
if ($param == 'do' && Strings::startsWith($signal, $multiplier->getName()) && ($pos = strrpos($signal, '-')) !== FALSE) {
$child = $control->getComponent(substr($signal, 0, $pos));
$child->snippetMode = TRUE;
@vojtech-dobes
vojtech-dobes / example.latte
Created September 10, 2011 00:37
Latte helpers for HTML 5 data-attributes
{* with helper *}
<div id="with-data" data-example="{[a => b]|data}"></div>
{* with macro *}
<div id="with-data" n:data="example, [a => b]"></div>
<script>
var data = parseDataJson($('#with-data'), 'example');
// => data == {a: 'b'}
</script>
@vojtech-dobes
vojtech-dobes / ComponentFactory.php
Created August 3, 2011 15:39
Login Form as service (behavior via event callbacks)
<?php
namespace Clevispace;
use Nette\DI;
class ComponentFactory extends DI\Container
{
@vojtech-dobes
vojtech-dobes / a_mysql-select.sql
Created July 28, 2011 15:03
Fetch the user: MySql vs CouchDB
SELECT `*` FROM `users` WHERE `username` = "john@doe.com" AND `password` = "xxx"
@vojtech-dobes
vojtech-dobes / uimacros.example.latte
Created March 23, 2011 20:45
First draft for UI abstraction - UiMacros for Nette Framework
{*
* All ui:* macros should support basic HTML attributes as modificators,
* because in fact they are only abstractions of common HTML elements
* compatible with proper unobtrusive javascript service.
*}
{*
* Basic link
* 'href' attribute is automatically evaluated as 'n:href'
*}
@vojtech-dobes
vojtech-dobes / feanorm.many-to-many-example.php
Created March 5, 2011 19:58
Articles and categories used in example have many-to-many relation
<?php
# low-level
$feanorm->relate($article)->to($category)->on('categories');
$feanorm->unrelate($article)->to($category)->on('categories');
// The clause 'on' shouldn't be neccessary when only one relation between entities is present.
# practical api
@vojtech-dobes
vojtech-dobes / Questions.php
Created February 8, 2011 21:42
Nette AJAX example (requires jQuery & jquery.nette.js)
<?php
use Nette\Application\AppForm;
use Nette\Application\Control;
use Nette\Environment;
class Questions extends Control
{
const YES = 'yes';
<?php
trait Decorator
{
/** @var object */
private $decorated;
@vojtech-dobes
vojtech-dobes / format-pre.js
Created January 22, 2015 10:00
Make <pre> readable
[].slice.call(document.querySelectorAll('pre'), 0).forEach(function (el) {
el.innerHTML = el.innerHTML.split("\n").join('<br>');
});
var style = document.createElement("style");
style.appendChild(document.createTextNode(""));
document.head.appendChild(style);
style.sheet.insertRule("pre { white-space: normal }", 0);
@vojtech-dobes
vojtech-dobes / Example.php
Last active August 29, 2015 14:02
Filtering helper useful for grids (or dynamic building of conditions)
<?php
// $selection instanceof DibiFluent
$filter = FilterHelper::start($selection, $filter)
->add('start_date')->setRule('[b.start_date] >= %d')
->add('end_date')->setRule('[b.end_date] <= %d')
->end();