Skip to content

Instantly share code, notes, and snippets.

View stefanocudini's full-sized avatar
🏔️
working from Alps

Stefano Cudini stefanocudini

🏔️
working from Alps
View GitHub Profile
@stefanocudini
stefanocudini / nearValue.php
Created March 24, 2012 23:39
return array value near to a value
<?
//restituisce il valore dell'array piu vicino al valore richiesto!!!!
$value = intval($argv[1]);
$tnsizes = array(10,50,100,150,300);
echo nearValue($value, $tnsizes);
function nearValue($tnsize, $tnsizes)
@stefanocudini
stefanocudini / http_post_request.php
Created March 24, 2012 23:43
send http post request and return http headers in array form
<?
//send http post request and return http headers in array form
function http_post_request($url,$pdata,$getHeaders=false)
{
$pdata = is_array($pdata) ? http_build_query($pdata) : $pdata;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_POSTFIELDS, $pdata);
@stefanocudini
stefanocudini / imagerotateEquivalent.php
Created March 24, 2012 23:44
image rotate Equivalent
<?
function imagerotateEquivalent($srcImg, $angle, $bgcolor, $ignore_transparent = 0) {
function rotateX($x, $y, $theta){
return $x * cos($theta) - $y * sin($theta);
}
function rotateY($x, $y, $theta){
return $x * sin($theta) + $y * cos($theta);
}
@stefanocudini
stefanocudini / imagetext.php
Created March 24, 2012 23:45
image text centered
<?
header('Content-Type: image/png');
$size= 80;
$extImg = imagecreatetruecolor($size,$size);
$targetFileImg = 'mime.png';
$ext = trim($_GET['t']);
$ctext = imagecolorallocate($extImg, 100, 100, 100); //testo
@stefanocudini
stefanocudini / randDesc.php
Created March 24, 2012 23:49
generate random phrase
<?
//generate random phrase
function randDesc($maxDescLen = 100)
{
$desc ='';
while(true)
{
$lwr = rand(2,8);//lunghezza parola
@stefanocudini
stefanocudini / randomtextflow,php
Created March 24, 2012 23:50
random text flow
#!/usr/bin/env php
<?
$alphNums = '<>/:-_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$l = strlen($alphNums);
#$maxl = 100;
while(true)
{
echo $alphNums{rand(0,$l)};
usleep(1000);
<?
function charCodeAt($str, $i)
{
return ord(substr($str, $i, 1));
}
function textToBase64($t)
{
$tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
$r=''; $m=0; $a=0; $tl=strlen($t)-1;
@stefanocudini
stefanocudini / encRC4.php
Created March 25, 2012 00:51
rc4 encode
<?
function encRC4($key, $text)
{
$kl=strlen($key);
$s=array();
for($i=0; $i<256; $i++)
$s[$i]=$i;
$y=0;
@stefanocudini
stefanocudini / SimpleWebsocketClient.php
Created March 25, 2012 00:54
Simple Websocket Client
<?
/* Simple Websocket Client
copyleft Stefano Cudini 2011-01-19
stefano.cudini@gmail.com
inspired by:
http://caucho.com/resin-4.0/examples/websocket-php/
*/
$host = 'localhost'; //where is the websocket server
$port = 9000;
@stefanocudini
stefanocudini / utc2local.php
Created March 25, 2012 00:54
convert time from utc to locale timezone
<?
//convert time from utc to locale timezone
$tz = getenv('TZ'); // Get current server time zone setting
echo "Current timezone setting: $tz <br>";
putenv("TZ=EST5EDT"); // Change to US Eastern time zone or whatever you want
$lt = localtime(time(), TRUE);
echo "EST local time: ".$lt['tm_hour'].':'.$lt['tm_min'].':'.$lt['tm_sec']." <br>";
putenv("TZ=$tz"); // Change it back to the original server time zone
?>