This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Binds a method to its owner, optionally adding more arguments | |
function bindMethod(_this, method) { | |
method = _this[method]; | |
if (arguments.length <= 2) { | |
return method.bind(_this); | |
} | |
var args = Array.prototype.slice.call(arguments, 2); | |
return args.unshift(_this), method.bind.apply(method, args); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Based on idea of http://millermedeiros.github.com/js-signals/ | |
function Signal(context, remember) { | |
this._bindings = []; | |
this._sorted = true; | |
this._erased = false; | |
this._remember = !!remember; | |
this._params = null; | |
this._propagate = false; | |
this._context = context || this; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SimpleRand as part of C implementation | |
// Usage: | |
// s = new SimpleRand(seed); | |
// v = s.rand(5, 10); | |
function SimpleRand(randState) { | |
var u; | |
function next() { | |
if (randState === u) { | |
randState = 54819; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* This file is part of Twig. | |
* | |
* (c) 2009 Fabien Potencier | |
* (c) 2013 Berny Cantos | |
* | |
* For the full copyright and license information, please view the LICENSE | |
* file that was distributed with this source code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\DemoBundle\Controller; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
use Acme\DemoBundle\Entity; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
class DemoController extends Controller |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# With this security.yml, browsing to /api resolves to root firewall | |
security: | |
# ... | |
firewalls: | |
root: | |
pattern: ^/ | |
anonymous: true | |
api: | |
pattern: ^/api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Returns integer difference between calls to a callback | |
* Mainly for usage with memory_get_usage and memory_get_peak_usage | |
* | |
* Usage: | |
* $memDiff = new Diff(function() { return memory_get_usage(true); }); | |
* do_somethin_memory_intensive(); | |
* echo $memDiff; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input id="search" type="text" /> | |
<h1>Results for search <span id="query">--</span></h1> | |
<ul id="results" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | |
use Symfony\Component\Security\Core\Authorization\Voter\VoterInterface; | |
class OwnershipVoter implements VoterInterface | |
{ | |
public function supportsAttribute($attribute) | |
{ | |
return $attribute === 'ROLE_OWNER'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | |
class ExampleController | |
{ | |
/** | |
* @ParamConverter("user", {"from" = "id"}) | |
*/ | |
public function exampleAction(User $user) | |
{ | |
// … |