Skip to content

Instantly share code, notes, and snippets.

@jakzal
jakzal / es-snapshot.sh
Last active May 11, 2016 11:14
Manage elasticsearch snapshots
#!/bin/bash
set -e
set -u
set -o pipefail
COMMAND=${1:-"help"}
ES="http://localhost:9200"
SNAPSHOT_DIR=$(dirname $(readlink -f $0))"/var/elasticsearch"
@jakzal
jakzal / drun.sh
Last active July 19, 2016 13:07
Run an aliased or a regular command on a docker container
#!/bin/bash
set -e
set -u
set -o pipefail
CONTAINER_OR_ALIAS=${1:-""}
COMMAND=${2:-""}
ARGUMENTS="${@:3}"
@jakzal
jakzal / list-namespaces-top.sh
Last active August 12, 2016 12:35
List PHP namespaces in a src directory
#!/bin/bash
SRC=${1:-"src/"}
if [ ! -d "$SRC" ]; then
echo "Usage: $0 src/path"
exit 1
fi
list-namespaces "$SRC" | sed -e 's/^\([^\\]*\\[^\\]*\).*/\1/g' | sort -u
@jakzal
jakzal / BackgroundProcess.php
Last active March 1, 2019 20:19
Starting a PHP built in server in phpunit tests
<?php
namespace Zalas\Test;
use Symfony\Component\Process\Process;
trait BackgroundProcess
{
/**
* @var Process
@jakzal
jakzal / Doctrine.php
Last active September 14, 2020 13:19
Use Doctrine and Symfony Kernel in phpunit tests
<?php
declare(strict_types=1);
namespace SymfonyLive\Mastermind\Adapters\Database;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\Tools\SchemaTool;
use RuntimeException;
@jakzal
jakzal / dom.patch
Created October 27, 2015 15:59
DOM extension patch for legacy PHP compiled with a recent libxml2 version
--- ext/dom/node.c 2012-08-06 17:49:48.826716692 +0800
+++ ext/dom/node.c 2012-08-06 17:52:47.633484660 +0800
@@ -1895,9 +1895,17 @@ static void dom_canonicalization(INTERNA
RETVAL_FALSE;
} else {
if (mode == 0) {
+#ifdef LIBXML2_NEW_BUFFER
+ ret = xmlOutputBufferGetSize(buf);
+#else
ret = buf->buffer->use;
@jakzal
jakzal / deploy.rb
Created October 12, 2015 08:25
Enable/disable a Symfony dev controller with capistrano
namespace :web do
namespace :dev do
desc <<-DESC
Opens the development controller to everyone.
DESC
task :enable do
dev_controller = current_release+"/"+web_path+"/app_dev.php"
run "sed -e 's/^\\([^\\/]\\{1,\\}.*403 Forbidden.*\\)/\\/\\/ \\1/' -e 's/^\\([^\\/]\\{1,\\}exit.*\\)/\\/\\/ \\1/' -i #{dev_controller}"
end
@jakzal
jakzal / .package.yml
Last active June 9, 2020 15:20
Build an rpm/deb package for a Symfony project
config:
packagename: symfony-demo
version: 1.0.0
arch: all
maintainer: Bob The Builder <bob@example.com>
description: Symfony demo project
url: http://symfony.com
packagetype: rpm
depends: ''
# - apache2
@jakzal
jakzal / behat.sh
Last active October 1, 2015 20:22
Running Behat 3 in parallel
#!/bin/sh
FEATURE_ARGUMENTS=()
for suite in $(./bin/behat -dl | cut -d ' ' -f 1 | sort -u | grep -e '^$' -v); do
echo "Looking for "$suite" suite features..."
for feature in $(./bin/behat --dry-run --suite $suite | grep -e 'features/.*\.feature' | sed -e 's/^.*\(features\/.*\.feature\).*$/\1/g' | sort -u); do
FEATURE_ARGUMENTS+=("--format=junit --out=build/$feature --suite=$suite $feature")
done
done
@jakzal
jakzal / find-unused.sh
Created April 2, 2015 13:37
Find unused methods in a PHP code base
#!/bin/bash
ag 'function.*\(' | \
sed -e 's/.*function \([^(]*\)(.*/\1/g' | \
sort -u | \
xargs -I% bash -c "[ `ag '%\(' | wc -l` == 1 ] && echo %"