Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
branchlist() {
git for-each-ref -s --format '%(refname:short)' refs/heads/
}
filter_stale() {
while read branch; do
(git rev-parse --verify --quiet "$branch"@{u} > /dev/null 2>&1 && git merge-base --is-ancestor "$branch"@{u} "$branch") || echo "$branch"
done
@xphere
xphere / script.sh
Created April 7, 2016 15:23
Bash script skeleton
#!/bin/bash
settings() {
SCRIPT_DIR="$(dirname "$0")"
}
main() {
request $@
settings
run
@xphere
xphere / Enum.php
Created March 9, 2016 12:29
Trait for Enum's in PHP
<?php
trait Enum
{
private $value;
private function __construct($value)
{
static $constants;
@xphere
xphere / MakeDownloadable.php
Last active January 27, 2016 15:21
Some controller helpers
<?php
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
trait MakeDownloadable
{
/**
* @param Response $response
* @param string $filename
@xphere
xphere / SerializerCompilerPass.php
Created December 17, 2015 10:30
Expands incomplete `jms_serializer.handler` tagged services
<?php
namespace Shopery\Bundle\ShoperyBundle\CompilerPass;
use Shopery\Bundle\ShoperyBundle\Serializer\Deserializer;
use Shopery\Bundle\ShoperyBundle\Serializer\Serializer;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
@xphere
xphere / MyFormType.php
Created November 19, 2015 13:10
Am I using GroupSequence correctly? Constraints aren't called when validating this form.
<?php
class MyFormType extends AbstractType
{
public funcion buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('username', 'text', [
'required' => true,
'validation_groups' => new GroupSequence(['Default', 'Strict']),
@xphere
xphere / is_xdebug_off.sh
Last active October 16, 2015 11:03
Command to test for xdebug listeners
#!/bin/bash
if [[ -n "$ALLOW_XDEBUG" ]]; then
exit 0
fi
QUIET=0
while test $# -gt 0
do
case "$1" in
@xphere
xphere / Configuration.php
Last active September 17, 2022 15:58
Recursive symfony/configuration
<?php
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
/**
* Helper function to create recursive nodes
*/
function recursiveNode(string $name, callable $callback)
@xphere
xphere / split-and-merge.md
Created April 13, 2015 15:34
Instructions for splitting a directory in a repo and merge into another one
  1. Split directory in a branch in source repository

    git subtree split -P <name-of-folder> -b <name-of-new-branch>
    
  2. Add remote of source in destination repository and fetch

    git remote add -f <source> <source-repository>
    
@xphere
xphere / MergeConcatTwigExtension.php
Created February 26, 2015 10:01
Twig filter for `merge_concat` between arrays, making easier to add classes and csv lists as attributes.
<?php
/**
* Copyright © 2015 Berny Cantos <[email protected]>
*
* This work is free. You can redistribute it and/or modify it under the
* terms of the Do What The Fuck You Want To Public License Version 2 as
* published by Sam Hocevar.
*
* See http://www.wtfpl.net/about file for more details.