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: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',
@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 / 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: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 / 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"
/GET /user
OK Response (200):
{
"user" : {
"name" : "Foo",
"email" : "foo@bar.com"
}
}
@ezimuel
ezimuel / gist:5301941
Created April 3, 2013 14:58
Db2 connect using ODBC parameters
<?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 March 11, 2013 16:55
DB2 configuration file connect using ZF2 and ODBC using config/autoload/local.php
<?php
$database = '';
$hostname = '';
$port = '';
$user = '';
$password = '';
return array(
'db' => array(
@ezimuel
ezimuel / gist:5091208
Created March 5, 2013 15:45
class_alias experiment
// rename the Zend\Stdlib\ArrayObject in Zend\Stdlib\ArrayObjectPHPFuture
// and copy he Zend\Stdlib\compatibility\ArrayObject in Zend\Stdlib\ArrayObjectPHPLegacy
if (version_compare(PHP_VERSION, '5.3.4', 'lt') {
class_alias('Zend\Stdlib\ArrayObjectPHPLegacy', 'ArrayObject');
} else {
class_alias('Zend\Stdlib\ArrayObjectPHPFuture', 'ArrayObject');
}
$test = new ArrayObject();
@ezimuel
ezimuel / gist:5036694
Last active December 14, 2015 05:39
Proposal for Improvement of ZF2 RND
/**
* Generate random bytes using OpenSSL or Mcrypt and mt_rand() as fallback
*
* @param integer $length
* @param bool $strong true if you need a strong random generator (cryptography)
* @return string
* @throws Exception\RuntimeException
*/
public static function getBytes($length, $strong = false)
{