Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'A Perl^h^h^h^hRuby script to create Tiny URLs' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A Perl^h^h^h^hRuby script to create Tiny URLs
Authored by: jeff_lamarche on Jul 05, '06 11:58:54AM
And for those of us who can't stand PERL and CPAN, here's a Ruby script that does the same thing, but with no reliance on libraries that have to be installed:

#!/usr/bin/env ruby
require 'net/http'
require 'uri'

in_url = ARGV[0]
url = URI.parse('http://tinyurl.com')
res = Net::HTTP.start(url.host, url.port) {|http|
  http.get("/create.php?url=#{in_url}")
}
search_string = "<input type=hidden name=tinyurl value="
body = res.body

url_index = body.index(search_string) + search_string.length + 1

search_end = body.index("\">", url_index)
puts body[url_index, search_end - url_index]


[ Reply to This | # ]
A Perl^h^h^h^hRuby script to create Tiny URLs
Authored by: pkishor on Jul 05, '06 04:08:43PM
now, now... that is not nice... to disparage Perl and CPAN...

#!/usr/bin/perl

use LWP;
my $a = LWP::UserAgent->new;

my $q = HTTP::Request->new(POST => 'http://tinyurl.com/create.php');
$q->content_type('application/x-www-form-urlencoded');
$q->content("url=$ARGV[0]");

my $r = $a->request($q);

if ($r->is_success) {
  my $h = $r->decoded_content;
  $h =~ /<blockquote><b>http:\/\/tinyurl.com\/(.*?)<\/b>/;
  print "http://tinyurl.com/$1";
}

>perl tinyurl.pl http://www.macosxhints.com
http://tinyurl.com/4oh69
>


[ Reply to This | # ]
A Perl^h^h^h^hRuby script to create Tiny URLs
Authored by: luomat on Aug 24, '06 01:14:08PM

AH!

Thank God for freedom from the damned CPAN!

This one "Just Worked"!



[ Reply to This | # ]