Skip to content

Instantly share code, notes, and snippets.

@pavelkucera
pavelkucera / keybase.md
Created January 18, 2021 15:30
keybase.md

Keybase proof

I hereby claim:

  • I am pavelkucera on github.
  • I am pavelkucera (https://keybase.io/pavelkucera) on keybase.
  • I have a public key whose fingerprint is 0005 24EB E07A F7B5 0FD8 1F58 7CC7 013E D3CD 526B

To claim this, I am signing this object:

@pavelkucera
pavelkucera / CacheExecutingPromise.js
Last active October 30, 2020 14:59
How to implement a simple lock to prevent an expensive promise from executing multiple times.
const expensiveOperation = () => new Promise((resolve) => {
console.log('Executing expensive operation')
setTimeout(resolve, 1000)
})
let expensiveOperationPromise = null
let expensiveOperationResult = null
const cacheExpensiveOperation = async () => {
if (expensiveOperationResult !== null) {
@pavelkucera
pavelkucera / Extension.php
Last active December 20, 2015 22:59
How to add a factory taking parameter into Nette DIC. Both ways, using config.neon and compiler extension, have the same result.
<?php
class Extension extends \Nette\DI\CompilerExtension
{
public function loadConfiguration()
{
$container = $this->getContainerBuilder();
$container->addDefinition($this->prefix('formMapperFactory'))
->setImplement('Namespace\IFactory')
@pavelkucera
pavelkucera / MyPresenter.php
Created June 28, 2013 14:39
How @Inject works in Nette (development only for now)
<?php
class MyPresenter extends \Nette\Application\UI\Presenter
{
/**
* @var \Some\Class
* @inject
*/
public $dependency;
}
failure: foo hitchhiker Earth exists
test.php(10)
$.nette.ext('page', {
load: function() {
for (var i in this.callbacks) {
var callback = this.callbacks[i];
callback();
}
}
}, {
callbacks: [],
register: function(callback) {
<?php
namespace RS\Doctrine\Config;
use RS\Doctrine\DBAL\Types\Type;
use Nette\Diagnostics\Debugger;
/**
* @author Pavel Kučera
*/
<?php
namespace Nodlehs\Doctrine;
/**
* @author Pavel Kučera
*/
class EntityManager extends \Doctrine\ORM\EntityManager
{
/************************************************************************************
@pavelkucera
pavelkucera / gist:1302248
Created October 20, 2011 20:23
Trable s kódem
Nette mi pravděpodobně kvůli Nelle vyhazuje fatal error v kešovaném konfigu, k odstranění stačí:
1) přidat na začátek kešovaného souboru die('G');
2) soubor spustit, ať zemře na lajně přidané v kroku 1)
3) zakomentovat řádek se smrtí
Po této proceduře se fatal error přestane objevovat! Žádný racionální důvod proč to tak je mě fakt nenapadá :/.
/**
* Beta
*
* Sibling of netteForms.js "rewritten to jQuery"
* @author Pavel Kučera
* @author David Grudl author of netteForms.js, of the idea and the one who I copied from
*
* Disclaimer: I'm not a javascript programmer, actually I hate javascript, so consider that please if you want to complain about quality of this utility.
*
* Dependencies