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 / gist:6071979
Created July 24, 2013 16:05
API example calls
RPC: GET /getalbum
Request
{ "id" : 1 }
OK Response (200):
{
"id" : 1,
"artist" : {
"name" : "Metallica",
"history" : "Simply the best heavy metal band ever!",
"genre" : "Heavy metal, Hard rock, Speed metal, Thrash metal"
@ezimuel
ezimuel / gist:6138279
Created August 2, 2013 08:16
ZF2 blog simple schema
CREATE TABLE post (
id int(11) NOT NULL auto_increment,
title varchar(100) NOT NULL,
content TEXT NOT NULL,
user_id int(11),
category_id int(11),
publish_date DATETIME,
PRIMARY KEY (id)
);
@ezimuel
ezimuel / encrypt_file.php
Created September 27, 2013 13:54
Example to encrypt a file (even big) using Zend\Filter\Encrypt of ZF2 with a simple block schema (low memory consumption).
<?php
// include the ZF2 library
use Zend\Filter\Encrypt;
if (!isset($argv[1]) or !isset($argv[2])) {
die("Usage: " . basename(__FILE__) . " <file_to_encrypt> <encryption_key>\n");
}
if (!file_exists($argv[1])) {
die("The file {$argv[1]} specified doesn't exist\n");
@ezimuel
ezimuel / gist:9135151
Created February 21, 2014 14:24
Tesing SimpleXML and DOMDocument to prevent XXE attacks on XML
<?php
// The libxml entity loader is disabled by default
// even setting the libxml_disable_entity_loader to false doesn't works!
//
// @see http://uk3.php.net/manual/en/function.libxml-disable-entity-loader.php
// @see http://stackoverflow.com/a/10213239
$dir = __DIR__;
$content = 'This is a remote content!';
file_put_contents('content.txt', $content);
@ezimuel
ezimuel / gist:11373254
Last active August 29, 2015 14:00
ZendOAuth example for Twitter
<?php
include '/path/to/vendor/autoload.php';
use ZendOAuth\Token\Access as AccessToken;
use Zend\Http\Request;
use Zend\Http\Response;
$config = array(
'callbackUrl' => 'http://example.com/callback.php',
'siteUrl' => 'http://twitter.com/oauth',
<?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
{
@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'
));
@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: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 / 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',
),
),