Skip to content

Instantly share code, notes, and snippets.

View vojtech-dobes's full-sized avatar

Vojtěch Dobeš vojtech-dobes

View GitHub Profile
<?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();
<?php
class CredentialsAuthenticator
{
/** @var Nette\Security\User */
private $user;
@vojtech-dobes
vojtech-dobes / validatedButton.ajax.js
Last active January 4, 2016 05:29
Keeps form buttons with [data-button-validated] data attribute in disabled state, until the form passes validation. Extension for nette.ajax.js.
$.nette.ext('validatedButton', {
load: function () {
var that = this;
$('[data-button-validated]').each(function () {
var button = $(this);
var form = button.closest('form');
that.tryEnable(form, button);
form.find('input, select').on('change input', function () {
that.tryEnable(form, button);
});
@vojtech-dobes
vojtech-dobes / debug.php
Created April 29, 2013 14:19
Getting to stacktrace in n-iteration easily
<?php
function stop($step = 1) {
static $i = 0;
$i++;
if ($i >= $step) {
$stop();
}
}
$.nette.init(function (rh) {
$(this.linkSelector).off('click.nette', rh).on('click.nette', rh);
$(this.formSelector).off('submit.nette', rh).on('submit.nette', rh);
$(this.buttonSelector).off('click.nette', rh).on('click.nette', rh);
}, {
linkSelector: 'a.ajax',
formSelector: 'form.ajax',
buttonSelector: 'input.ajax[type="submit"], button.ajax[type="submit"], input.ajax[type="image"]'
});
@vojtech-dobes
vojtech-dobes / Usage.md
Created October 19, 2012 10:31
Require.js + Mocha + Sinon
var load = requirejs('bootstrap')('nameOfTestedThing', {
	nameOfDependency: mockOfDependency
}, function (test) {

describe('foo', function () {
	test('bar', function (testedThing, mockOfDependency) {
		...
 test.done();
@vojtech-dobes
vojtech-dobes / gist:3775104
Created September 24, 2012 09:24
Flush DNS cache on Mac
dscacheutil -flushcache
@vojtech-dobes
vojtech-dobes / build.xml
Created September 21, 2012 12:53
Composer via Ant
<exec executable="bash" failonerror="true">
<arg value="-c" />
<arg value="curl -s https://getcomposer.org/installer | php" />
</exec>
<exec executable="php" failonerror="true">
<arg value="composer.phar" />
<arg value="install" />
</exec>