Skip to content

Instantly share code, notes, and snippets.

Avatar
🇮🇹
Working remotely, since 2008

Enrico Zimuel ezimuel

🇮🇹
Working remotely, since 2008
View GitHub Profile
@ezimuel
ezimuel / .htaccess
Created Mar 14, 2017
Create a PHP deploy package .zpk for Zend Server
View .htaccess
RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The
# condition ensures that if you are using Apache aliases to do
@ezimuel
ezimuel / test_bench.php
Created Mar 8, 2017
MD5 vs. preg_replace_callback for PDOStament::bindParam() usage in zend-db
View test_bench.php
<?php
// Testing md5 vs. preg_replace_callback()
$execPreg = 0;
$execMd5 = 0;
for ($i=0; $i<100000; $i++) {
$name = randomName(10);
$start = microtime(true);
$result = preg_replace_callback(
@ezimuel
ezimuel / global.php
Created Dec 9, 2014
Example: OAuth2 configuration for Apigility
View global.php
// config/autoload/global.php
// ...
'router' => array(
'routes' => array(
'oauth' => array(
'options' => array(
'route' => '/oauth',
),
),
View gist:f34b22f347d4a0c985a1
<?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 / encrypt_file.php
Created Sep 27, 2013
Example to encrypt a file (even big) using Zend\Filter\Encrypt of ZF2 with a simple block schema (low memory consumption).
View encrypt_file.php
<?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:6138279
Created Aug 2, 2013
ZF2 blog simple schema
View gist:6138279
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 / gist:6071979
Created Jul 24, 2013
API example calls
View gist:6071979
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"
View gist:6071087
/GET /user
OK Response (200):
{
"user" : {
"name" : "Foo",
"email" : "foo@bar.com"
}
}
@ezimuel
ezimuel / gist:5301941
Created Apr 3, 2013
Db2 connect using ODBC parameters
View gist:5301941
<?php
$database = '';
$user = '';
$password = '';
$hostname = '';
$port = 446;
$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;".
"HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;";
@ezimuel
ezimuel / gist:5135662
Created Mar 11, 2013
DB2 configuration file connect using ZF2 and ODBC using config/autoload/local.php
View gist:5135662
<?php
$database = '';
$hostname = '';
$port = '';
$user = '';
$password = '';
return array(
'db' => array(