mporru
mporru
Reputation Top 1%
Matteo Porru
25 Snippets  (19th place)
Published
3 Channels
Created
2 Channels
Following
Feb 28, 2016
Last Visit
May 13, 2012
Registered
1093 points  (12nd place)
Reputation
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
Junior Famous Coder
Serious Famous Coder
Junior Wise Coder

Recent Snippets See all snippets by mporru

public by mporru created Mar 23, 2015  430  3  4  1

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 created Sep 13, 2013  4481  349  4  0

ANT: Dynamic Variables (properties with a variable name)

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

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

public by mporru @ Amazon_AWS_PHP_API created Jul 22, 2013  840  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.
<?php
require_once('sdk.class.php');
$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 created Jul 19, 2013  681  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: http://www.sitepoint.com/getting-started-with-the-aws-php-sdk/
<?php
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.',
'acl'=>AmazonS3::ACL_PUBLIC,
));
if ((int) $response->isOK()) echo 'I Created a File!';
?>
;

public by mporru @ Amazon_AWS_PHP_API created Jul 19, 2013  551  0  4  0

Installing the PHP SDK

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

- Download the SDK from here:
http://pear.amazonwebservices.com/get/sdk-latest.zip

- Extract the zip file in the root of your web server application.
- Rename the file config-sample.inc.php to config.inc.php
- Edit the file config.inc.php 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:
<?php
require_once 'sdk.class.php';
// ...
// make any API call
// ...
?>
;