Skip to content

Instantly share code, notes, and snippets.

View ezimuel's full-sized avatar
🇮🇹
Working remotely, since 2008

Enrico Zimuel ezimuel

🇮🇹
Working remotely, since 2008
View GitHub Profile
@ezimuel
ezimuel / sign.sh
Created March 14, 2016 15:50
Sign and verify a file using OpenSSL command line tool. It exports the digital signature in Base64 format.
#!/bin/bash
# Sign a file with a private key using OpenSSL
# Encode the signature in Base64 format
#
# Usage: sign <file> <private_key>
#
# NOTE: to generate a public/private key use the following commands:
#
# openssl genrsa -aes128 -passout pass:<passphrase> -out private.pem 2048
# openssl rsa -in private.pem -passin pass:<passphrase> -pubout -out public.pem
@ezimuel
ezimuel / pluginmanager.php
Last active November 7, 2015 16:54
Experimental plugin manager compliant with ContainerInterface
<?php
/**
* Experimantal plugin manager complaint with ContainerInterface with options support
* using the optional Interface rule of PHP
*/
use Interop\Container\ContainerInterface;
class PluginManager implements ContainerInterface
{
@ezimuel
ezimuel / test.php
Created August 10, 2015 13:29
Unit test for RouteMiddlewareTest issue #40 zend-expressive
<?php
/**
* Get the router adapters installed
*/
public function getRouterAdapters()
{
$adapters = [];
if (class_exists('Aura\Router\Router')) {
$adapters[] = [ 'Zend\Expressive\Router\Aura' ];
}
@ezimuel
ezimuel / gist:f34b22f347d4a0c985a1
Created June 25, 2015 07:38
New stratigility example, updated with PR zendframework/zend-stratigility#12
<?php
use Zend\Stratigility\MiddlewarePipe;
use Zend\Diactoros\Server;
require 'vendor/autoload.php';
$app = new MiddlewarePipe();
$server = Server::createServer($app, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
// Injected for all the URL
@ezimuel
ezimuel / CatalogEntity.php
Created December 9, 2014 14:53
Example of Entity for Apigility
namespace Ecommerce\V1\Rest\Catalog;
class CatalogEntity
{
public $id;
public $name;
public $description;
public $picture;
public $price;
public $quantity;
@ezimuel
ezimuel / global.php
Created December 9, 2014 12:33
Example: OAuth2 configuration for Apigility
// config/autoload/global.php
// ...
'router' => array(
'routes' => array(
'oauth' => array(
'options' => array(
'route' => '/oauth',
),
),
@ezimuel
ezimuel / gist:0769f99e45a04e124cf0
Created August 25, 2014 13:30
Benchmark Pbkdf2 iterations with ZF2
<?php
// Benchmark the Pbkdf2 iteration (10'000 = 50 ms, using an Intel i5 CPU at 2)
use Zend\Crypt\Key\Derivation\Pbkdf2;
use Zend\Math\Rand;
$salt = Rand::getBytes(32);
$pass = 'this is the password of the user';
$start = microtime(true);
@ezimuel
ezimuel / gist:92d9f6b8ed62f9fd71c7
Created June 18, 2014 08:31
Optional language parameter in a ZF2 route
<?php
// route configuration, for instance in a module.config.php
// ...
'home' => array(
'type' => 'segment',
'options' => array(
'route' => '/[:lang/]',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
@ezimuel
ezimuel / gist:eff5072ef7ccd0298a6b
Created June 16, 2014 10:10
Testing ORDER BY for Zend_Db_Select of ZF1
<?php
set_include_path('path/to/zf1/library');
require_once 'Zend/Db.php';
$db = Zend_Db::factory('Pdo_Mysql', array(
'host' => '127.0.0.1',
'username' => '',
'password' => '',
'dbname' => 'test'
));
<?php
namespace Test\V1\Rpc\Test;
use Zend\Mvc\Controller\AbstractActionController;
use ZF\ContentNegotiation\ViewModel;
use ZF\Hal\Entity;
use ZF\Hal\Link\Link;
class TestController extends AbstractActionController
{