July 27, 2007

Resolving TinyURLS to the desination URL

Categories: Programming, hacks
Author: Arun
Time: 5:14 am
Reactions :No comments

After Twitter hugged TinyURL, there happens to be lots of talk about how to enhance TinyURL services.

for example:

http://preview.tinyurl.com/37dz8l

redirects to

http://www.webforth.com/

But how do we understand that the first URL is going to get redirected to the second URL. It is pretty clear that the string 37dz8l does the magic. TinyURL folk has written a smart algorithm to shrink bigger URLs to a hashed string (Anybody know how that works?). For the time being, I wrote a small snippet for resolving a tiny url to its original destination URL. The script will directly contact TinyURL server to see where the URL is getting redirected.

< ?php

// tinyurl.php?c=

$num = $_GET['c'];

if($fp = fsockopen ("tinyurl.com", 80, $errno, $errstr, 30))
{
if ($fp) {
fputs ($fp, "HEAD /$num HTTP/1.0\r\nHost: tinyurl.com\r\n\r\n");
while (!feof($fp)) {$headers .= fgets ($fp,128);}
fclose ($fp);
}
$arr1=explode("Location:",$headers);
$arr=explode("\n",trim($arr1[1]));
echo trim($arr[0]);
}
?>

It is a simple code which plays with http headers rather than HTML. It processes shorter strings and string manipulation is done using non-regexp tricks.

May 15, 2007

Ripping audio cds to MP3 with VLC

Categories: hacks, software
Author: Arun
Time: 4:36 am
Reactions :5 comments

If you aware of, VLC(Video Lan Client) is one of the coolest media players available today. I recently digged out a way to rip Audio CDs to mp3 format using this cute little app. Honestly speaking, with VLC, you can convert CDA files to almost any audio format available.

This is how you can do it:

1) Insert your CD into the drive and open VLC.
2) Select File > Open File. Browse and select the track from the CD.
In the same window, look for Advanced Options


3) Check the Stream/Save checkbox. Click Settings to open the big settings window.
4) In the Output section, check the File checkbox. Click Browse and select your new file name. Check settings I used.

5)
Click OK (OK again) to start the conversion
6) Go back to step 1 for the next track (It is simple. You just have to change the filenames - keep the other settings as it is)

Sorry for the Microsoft style explanation; I am on a windows machine. You can always do all these using shell scripts in Linux, I guess. VLC won’t display any progress untill it finishes with the file. VLC supports conversion with upto 512Kbps stream with a maximum of 5 channels.

Don’t have VLC? Download

Proudly powered by Wordpress 2.1.3 - theme by neuro, styled by webforth.