Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@frak
frak / benchmark.php
Created February 21, 2015 20:21
Please don't use sprintf...
<?php
$maxiter = 10000000;
$value = "1234";
$time_start = microtime(true);
for ($i = 0; $i < $maxiter; ++$i) {
$string = "This is " . $value;
}
@frak
frak / cli
Created January 15, 2015 12:34
CLI xdebug config
export XDEBUG_CONFIG="idekey=PHPSTORM remote_host=172.28.128.1 remote_port=9000"
export PHP_IDE_CONFIG="serverName=your.phpstorm.server.name"
@frak
frak / gist:89218802a0fa5f3dd852
Created December 23, 2014 15:20
Greek question mark
<?php
echo html_entity_decode("Greek question mark: &#x37e;");
@frak
frak / .gitconfig
Created May 15, 2014 15:47
Graphical 3 way merging for Git using P4Merge
# Download and install P4Merge from here: http://www.perforce.com/product/components/perforce-visual-merge-and-diff-tools
# And then add this to your Git config
[merge]
tool = p4mergetool
[mergetool "p4mergetool"]
cmd = /Applications/p4merge.app/Contents/Resources/launchp4merge $PWD/$BASE $PWD/$REMOTE $PWD/$LOCAL $PWD/$MERGED
trustExitCode = false
[diff]
tool = p4mergetool
@frak
frak / dev_magic.sh
Last active August 29, 2015 13:59
Setting up dnsmasq to point *.dev to your dev VM
sudo port install dnsmasq
sudo port load dnsmasq
# add "address=/dev/your.vm.ip.address" to the end of /opt/local/etc/dnsmasq.conf
sudo mkdir -p /etc/resolver
sudo tee /etc/resolver/dev >/dev/null <<EOF
nameserver 127.0.0.1
EOF
@frak
frak / post-checkout
Last active November 14, 2017 15:34 — forked from lyrixx/post-checkout
Check for new dependencies and/or parameters after checkout
#!/bin/bash
# Put this file at: .git/hooks/post-checkout
# and make it executable
# You can install it system wide too, see http://stackoverflow.com/a/2293578/685587
PREV_COMMIT=$1
POST_COMMIT=$2
NOCOLOR='\033[0m'
@frak
frak / YourSymfonyCommand.php
Last active December 28, 2015 16:29
How to lock a CLI script without leaving artefacts
<?php
/**
* Lock files are no end of pain, especially ensuring they are correctly removed when things blow up.
* This way there are never any artifacts left around, so nothing to clean up.
*/
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if($socket === false) {
throw new \Exception("Cannot create a socket, please check system configuration");
}
@frak
frak / Episode.php
Created November 28, 2012 21:44
Handling file uploads with lifecycle callbacks
<?php
namespace Click\SiteBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
* Click\SiteBundle\Entity\Episode
@frak
frak / app.php
Created November 28, 2012 19:22
Symfony2: Remove the need for app_dev.php
<?php
$env = 'prod';
$debug = false;
if(isset($_SERVER['APP_KERNEL'])) {
switch($_SERVER['APP_KERNEL']) {
case 'test':
case 'qa':
case 'dev':