Reputation Top 1%
Matteo Porru
25 Snippets  (22nd place)
3 Channels
2 Channels
8637 points  (11st place)
Top 5% Publisher
Junior Code Generator
Serious Code Generator
Senior Code Generator
Junior Publisher
Serious Publisher
Senior Publisher
Junior Topic Creator
Serious Topic Creator
Senior Topic Creator
Junior Topic Hub
Serious Topic Hub
Senior Topic Hub
Master Topic Hub
Junior Trend Maker
Serious Trend Maker
Senior Trend Maker
Master Trend Maker
Junior Commenter
Junior Judge
Serious Judge
Junior Popular Coder
Serious Popular Coder
Senior Popular Coder
Master Popular Coder
Junior Autobiographer
Serious Autobiographer
Senior Autobiographer
Master Autobiographer
Serious Famous Coder
Master Famous Coder
Serious Wise Coder

Recent Snippets See all snippets by mporru

public by mporru  2780  2  4  2

Windows - kill a program from command line

How to kill a program, with a given command launch string. Note: to run in a bat file replace % with %%
wmic process Where "Caption Like '%myexe.exe%' AND CommandLine Like '%mycommandline%'" delete

public by mporru  13515  23  4  0

ANT: Dynamic Variables (properties with a variable name)

This is how we can prepare a variable, with a variable name
<!-- Dynamic variables -->
<macrodef name="propertycopy">
  <attribute name="name"/>
  <attribute name="from"/>
    <property name="@{name}" value="${@{from}}"/>

<!-- USAGE -->
<property name="" value= "This is the composite var" /> 
<property name="tmp" value= "bar" /> 
<propertycopy name="testVar" from="${tmp}.foo"/>
This will print: "This is the composite var"

public by mporru @ Amazon_AWS_PHP_API  3971  1  4  1

Amazon AWS - PHP: Generate public download URL

This snippet demonstrates how to generate a public download URL for a file stored in your S3 Bucket. Target file must have ACL public permissions set. In order to use this service you must enable Amazon Simple Storage Service (Amazon S3) in your account.
$s3 = new AmazonS3();

$fileName = 'LighthouseNew.jpg';
$bucketName = 'myBucketName';

$url = $s3->get_object_url($bucketName, $fileName);

echo("Download url: <a href=\"$url\">$url</a>\n");

public by mporru @ Amazon_AWS_PHP_API  3025  0  4  0

Amazon AWS - PHP: Create a new text file inside a bucket.

This snippet demonstrates how to use the create_object API. In this case, we create a new text file, filling it up with some text. Taken from:
require_once 'sdk.class.php';
$s3 = new AmazonS3();
// Create Object is pretty self explanatory:
// Arg 1: The bucket where your file will be created.
// Arg 2: The name of your file.
// Arg 3: An array of Options.
//        In this case we're specifying the &quot;body&quot; option
//        and the ACL setting to allow this file to be read by anyone.
$response = $s3->create_object('MyBucketName', 'newtextfile.txt', array(
'body' => 'Hello world. Nice to meet you.',
if ((int) $response->isOK()) echo 'I Created a File!';

public by mporru @ Amazon_AWS_PHP_API  2781  0  4  0

Installing the PHP SDK

Actually, this is not a snippet, just some simple instructions on how to setup the PHP SDK.
Apache HTTP Server (or any other suitable web server)
PHP with curl library
A valid Amazon AWS account

- Download the SDK from here:

- Extract the zip file in the root of your web server application.
- Rename the file to
- Edit the file putting your key and secret
To obtain those values, log-in to your AWS management console.
Click "Account", then "Security Credentials".
Scroll down to find your AWS Key and Secret Key. 

- Write any PHP script, including the SDK at the very beginning of your application:
require_once 'sdk.class.php';
// ...
// make any API call
// ...