Skip to content

Instantly share code, notes, and snippets.

Avatar

Vojtěch Dobeš vojtech-dobes

View GitHub Profile
View Decorator.php
<?php
trait Decorator
{
/** @var object */
private $decorated;
@vojtech-dobes
vojtech-dobes / format-pre.js
Created Jan 22, 2015
Make <pre> readable
View format-pre.js
[].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 Aug 29, 2015
Filtering helper useful for grids (or dynamic building of conditions)
View Example.php
<?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();
View CredentialsAuthenticator.php
<?php
class CredentialsAuthenticator
{
/** @var Nette\Security\User */
private $user;
@vojtech-dobes
vojtech-dobes / validatedButton.ajax.js
Last active Jan 4, 2016
Keeps form buttons with [data-button-validated] data attribute in disabled state, until the form passes validation. Extension for nette.ajax.js.
View validatedButton.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 Apr 29, 2013
Getting to stacktrace in n-iteration easily
View debug.php
<?php
function stop($step = 1) {
static $i = 0;
$i++;
if ($i >= $step) {
$stop();
}
}
View main.js
$.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 Oct 19, 2012
Require.js + Mocha + Sinon
View Usage.md
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 Sep 24, 2012
Flush DNS cache on Mac
View gist:3775104
dscacheutil -flushcache
View build.xml
<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>
You can’t perform that action at this time.