GOTO

Sunday, December 19, 2010

Tiny4py: make your url shorter using python

Hi everybody,

sorry for missing to write these days, I have lot of work to do....I have also work on new Python libraries to make url shorter using services as goo.gl, bit.ly and Tinyurl...The page on google code is at http://code.google.com/p/tiny4py/ . You can download code using Mercury, I prefer to commit code instead of create an archive everytime an important modification happens ( you can find the "how to" on page ).

Good shorting :)

::See you next post::

Tuesday, November 9, 2010

Yet another emesene plugin

Hi everybody,

after Flickravatar I've released another plugin for emesene: Twitterene. This plugin take my avatar, status and nick from Twitter, putting them into emesene...I really need it :) http://code.google.com/p/twitterene/

::See you next post::

Friday, November 5, 2010

Yet another python blog

Hi everybody,

I just let you know the last blog I'm collaborating with...It'shttp://mypysnippets.blogspot.com/ and will host all python snippets me and others programmers found during programming...cause we love py :)


::See you next post::

Sunday, October 31, 2010

Flickr Avatar

Hi everybody,

I'm back to post here to show my new plugin for emesene ( yeah I'm workin on some plugin these days )...My new work is Flickr Avatar ( http://code.google.com/p/flickravatar/ ) . It can get a photo from flickr and set it as avatar on emesene...Ok, that's the general function, but in realty you can choose one of your sets and rotate images sequentially or randomly..Here's a screenshot:


If something goes wrong report the relative problem here http://forum.emesene.org/index.php/topic,3828.0.html or contact me by email...I hope you'll appreciate Flickr Avatar :) Stay tuned for updates!!!

::See you next post::

Wednesday, September 1, 2010

Stretching...with Php!!

Hi everybody,

are you sports? Well, so you know for sure the stretching...a programmer too, but he think immediately to pictures' stretching... What is this? Pictures' stretching is a set of operations of elongation, shrinking and many other applied to pictures...Usually you need to fit a picture in a smaller image using mathematical proportions...It works, obvious, but If you try this, you'll note that this image is very distorted! There's nothing to do, the only case where the final pictures looks not distorted is when the big image's dimensions ( width and height ) are multiples of the small picture's ones, but this is not always possible..If you have to create thumbnails with php this is not the right way..Keeping in mind the story of multiple dimensions, let's try to proceed in this other way: first we take the big picture and select an area centered in the image as big as the destination image ( yellow rectangle )..


This area is very small...let's try to multiply by 2 both width and height..We get this:


Quite as big as the image...multiplying now by 3 the area will exceed the image, so we consider the area * 2, an area proportioned to the final pictures...What remains to do? Stretch this area and fit it into our target picture, getting:


Here is the code:


function makeThumbNotStretched($src_file,$dest_file,$t,$win_w,$win_h){

@list($width, $height, $type, $attr) = @getimagesize($src_file);

$cw=$width/2;

$ch=$height/2;

$i=1;

$w=$cw-(($win_w*$i)/2);
$h=$ch-(($win_h*$i)/2);

while($w>=0 && $h>=0){
$i++;
$w=$cw-(($win_w*$i)/2);
$h=$ch-(($win_h*$i)/2);
}

$i--;
$w=$cw-(($win_w*$i)/2);
$h=$ch-(($win_h*$i)/2);

$dest = imagecreatetruecolor($win_w*$i, $win_h*$i);

if ($t == 'image/jpeg')
$src = @imagecreatefromjpeg($src_file);

imagecopy($dest,$src,0,0,$w,$h,$win_w*$i,$win_h*$i);

$thumb = imagecreatetruecolor($win_w, $win_h);
imagecopyresampled($thumb,$dest,0,0,0,0,$win_w,$win_h,$win_w*$i,$win_h*$i);

if ($t == 'image/jpeg')
@imagejpeg($thumb,$dest_file, 75);
}


::See you next post::

Wednesday, August 25, 2010

Star Wars on Telnet

Hi everybody,


as you know well, I am a big Star Wars fan and I can't believe in what I've just discovered: a version of the first episode ( IV to be clear :) ) made using Ascii art!! Incredible!! This animation masterpiece is visible using telnet, typing in your terminal

telnet towel.blinkenlights.nl


Enjoy it!! Ah and an advice: if you can, watch this film listening the original soundtrack.. I bought a few days ago a cd where the Utah Symphony Orchestra reinterprets Star Wars' music including the "Fox Fanfare"...Awesome!!

::See you next post::

Sunday, August 22, 2010

Building an Hash Table in c++ - episode I

Hi everybody,

this is a new section dedicated to didactics issues where I try to explain step by step some problems and relative solutions derived from my lessons (I give private lessons). To inaugurate this new section, let's start talkin' about building an Hash Table, one of the most used examples for learning to use template classes. Yes, but what is an hash table, and what we need it for?? Hash table is a container of generic elements (integer, floating, classes...) which we can access using a code (for example a string, a number....), so for every elements corresponds another element. How do we dispose elements?? It should be better with a vector (supposing to use STL libraries) cause the access to elements is faster than other containers..Ok, let's choose a code composed by integer numbers and associate element A with code 54: we can associate A to the 54th element of our vector. Yeah, everytime we want the element with code 54 we get the 54th element, in this case A. First problem: memory is limitated, using this method we could exhaust it!! For example associating element 40000000 we waste too much memory, degrading performances..We need a limited vector and a function that given the code, transform it in an index included in the range of the vector..It's very easy, we have only to use the mod operator ( % in c ) with the maximum dimension of array. If we have a vector with dimension 127 our old code 40000000 will be transformed in 40000000 % 127 = 80. Using a code formed by a string, we have the same thing: we can get a number by a string adding every single char value, after that we can apply the mod operation again. Is that all? No, unfortunately. Using this method we can have collisions, that is have two codes that generate the same vector's position..How can we solve it? We must transform our vector of generic elements in a vector of lists of generic elements, so when we have two elements that generate the same index e.g. I1 we push elements back in the list at I1 position. We'll have a structure like this:

In the next lesson we will write the first draft of code, implementing the class' structure and the supporting functions...

::See you next post::