challenge LL Golf Hole 1 - tinyurl.comを使ってURLを短縮する

tinyurl.com( http://tinyurl.com/ )のサービスを利用し、 http://ll.jus.or.jp/2008/info/xgihyo というURLを短縮しなさい。tinyurl.comのalias機能は使わないものとする。 なお、参考までに短縮したURLは http://tinyurl.com/5mngx8 となる。

余力のあるものはこのプログラムを短くしてみたり、短くしてみたり、短くしてみよ。

※LL Future実行委員の高野光弘です。この出題は LL Future公式の出題であり、優れたものについてはLL Golfのセッションでご紹介させていただくかもしれません。ご理解の上、ご投稿ください。また、LL Futureのチケットは現在も発売中です。よろしければ、メインイベントの方にもぜひご参加ください。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env ruby

require 'rubygems'
require 'mechanize'

def tinyurl(url, _alias = nil)
    m = WWW::Mechanize.new
    res = m.get('http://tinyurl.com/')
    form = res.forms[1]
    form['url'] = url
    form['alias'] = _alias if _alias
    res = m.submit(form)
    regexp = Regexp.new('.*(http\:\//tinyurl.com/[a-z0-9-]+).*')
    match = regexp.match(res.body)
    return match[1] if match
end

if __FILE__ == $0 then
    puts tinyurl('http://ll.jus.or.jp/2008/info/xgihyo')
end

Posted feedbacks - Bash

ごめんなさいごめんなさい

1
2
#/bin/sh
wget -qO - http://tinyurl.com/api-create.php?url=$0

ではpure bashで。要enable-net-redirections。

1
(echo -ne 'GET /api-create.php?url=http://ll.jus.or.jp/2008/info/xgihyo\r\nHost: tinyurl.com\r\n\r\n';while read s;do :;done<&1;echo $s>&2)>/dev/tcp/tinyurl.com/80

どれだけ圧縮できるサービスを利用するかって話に帰着しちゃうのかな

1
curl url.ms/qJI

Index

Feed

Other

Link

Pathtraq

loading...