Skip to content

Instantly share code, notes, and snippets.

@stefanotorresi
stefanotorresi / ansible-playbook-helper.sh
Created September 11, 2014 16:27
Script to run an Ansible playbook inside an Ubuntu virtual machine against a local inventory.
#!/usr/bin/env bash
ANSIBLE_PLAYBOOK=$1
ANSIBLE_HOSTS=$2
INVENTORY_FILE="/tmp/ansible_hosts"
function check_arguments() {
if [ -z ${ANSIBLE_PLAYBOOK} ]; then
echo "Usage: ansible-playbook-helper playbook-file [inventory-file|hostname]"
exit 1
<?php
namespace Application;
use Zend\Mvc\MvcEvent;
use Zend\Validator\AbstractValidator;
class Module
{
public function onBootstrap(MvcEvent $event)
@stefanotorresi
stefanotorresi / FormDirectiveAutofillDecorator.js
Last active August 24, 2016 20:50
angular form directive decorator to fix Safari autofill bug
use 'strict';
/**
* workaround for: https://github.com/angular/angular.js/issues/1460
* source: http://victorblog.com/2014/01/12/fixing-autocomplete-autofill-on-angularjs-form-submit/
* decoration tips: http://angular-tips.com/blog/2013/09/experiment-decorating-directives/
* credits: https://github.com/evictor
*
* note: this directive only fixes the behaviour on form submit event,
* it doesn't fix the bidirectional data binding
@stefanotorresi
stefanotorresi / wp-custom-archives.php
Last active August 29, 2015 13:57
wordpress custom archive hooks
<?php
/**
* archive list join clause
*/
function myArchiveJoin($join)
{
global $wpdb;
$join .= "
@stefanotorresi
stefanotorresi / zf2-service-factory.php
Last active August 29, 2015 13:56
make service factories scope-independent.
<?php
$serviceManager = $serviceLocator instanceof AbstractPluginManager ?
$serviceLocator->getServiceLocator() : $serviceLocator;
@stefanotorresi
stefanotorresi / sm.config.php
Created January 13, 2014 12:01
ZF2 ServiceManager config example
<?php
return [
'factories' => [
'Db' => function ($sm) {
$dbConfig = $sm->get('db_config');
$db = new PDO(
$dbConfig['dsn'],
$dbConfig['user'],
@stefanotorresi
stefanotorresi / bench.php
Last active December 26, 2015 19:59
Zend\Stdlib\ArrayUtils::merge() benchmark
<?php
include '../zf2/vendor/autoload.php';
$array = include 'config.php'; // ZendSkeletonApp merged configuration
$array2 = include 'config2.php'; // zf-apigility-skeleton merged configuration
$array3 = include 'config3.php'; // zf-apigility-skeleton merged configuration with a traversable
$cycle = isset($argv[1]) ? $argv[1] : 1000;
echo 'cycling '.$cycle.' times' . PHP_EOL;
@stefanotorresi
stefanotorresi / form-collection-example.php
Created October 25, 2013 14:48
Using a Zend\Form\Collection of hydrated fieldsets.
<?php
use Zend\Form\Fieldset;
use Zend\Form\Form;
use Zend\Form\View\Helper\Form as FormHelper;
use Zend\Form\View\HelperConfig;
use Zend\Stdlib\ArrayUtils;
use Zend\Stdlib\Hydrator\ObjectProperty;
use Zend\View\Renderer\PhpRenderer;
@stefanotorresi
stefanotorresi / FormFactory.php
Created July 9, 2013 15:29
custom input filter services
<?php
use Zend\Filter\FilterChain;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class FormFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator)
{
$form = new Form();
@stefanotorresi
stefanotorresi / SlideEntity.php
Last active December 19, 2015 12:49
data aware widget with zf2 and doctrine
<?php
/**
* @author Stefano Torresi (http://stefanotorresi.it)
* @license See the file LICENSE.txt for copying permission.
* ************************************************
*/
namespace MySlideshow;
use MyBase\Entity\Entity;