Skip to content

Instantly share code, notes, and snippets.

@chrif
chrif / WhitespaceMatchTest.php
Last active October 9, 2020 15:24
How to correctly match all whitespaces in PHP
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
class WhitespaceMatchTest extends TestCase {
const SLASH_S = "#\s#";
const SLASH_S_U = "#\s#u";
Ext.override(Ext.data.Store, {
constructor: function(config) {
this.initConfig(config);
this.callParent(arguments);
this.addEvents(
/**
* @event clone
* Fires when a store is cloned
* @param {Ext.data.Store} this
* @param {Ext.data.Store} clone The new clone
@chrif
chrif / InspectExtension.php
Created August 21, 2012 16:29
Set a breakpoint in Twig templates and debug some or all variables ( equivalent to {{ dump() }} )
<?php
namespace Acme\HelloBundle\Extensions;
/**
* Inspect Twig templates with a debugger.
* Usages:
* {{ inspect() }}
* {{ inspect(myVar) }}
*/
@chrif
chrif / NumberToStringTransformer.php
Created August 21, 2012 02:57 — forked from fain182/gist:3394880
Workaround for Issue #2059 in Symfony 2.0
<?php
namespace Acme\HelloBundle\Form\DataTransformer;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
use Symfony\Component\Form\Exception\TransformationFailedException;
/**
* A simple number transformer that allows either comma or dot as decimal separator.
*
@chrif
chrif / mists.js
Created March 19, 2012 00:40
Mists
var Mists = {};
Mists.ready = function () {
var user = new Mists.User();
user.login(function () {
var wall = new Mists.Wall(user);
var wallButton = Mists.Menu.getInstance().getWallButton();
if (wallButton.length) {
wallButton.attr('href', wall.getUrl());
wall.checkNewMessages(function (data) {
@chrif
chrif / xpath_escape.php
Created February 10, 2012 02:15 — forked from iaindooley/xpath_escape.php
Function to escape single and double quotes in XPath queries using PHP
<?php
function xpathEscape($query, $default_delim = '"')
{
if (strpos($query, $default_delim) === false)
return $default_delim . $query . $default_delim;
preg_match_all("#(?:('+)|[^']+)#", $query, $matches);
list($parts, $apos) = $matches;
foreach ($parts as $i => &$part) {
$delim = $apos[$i] ? '"' : "'";
$part = $delim . $part . $delim;