wesley tanaka

tinyurl command line tool

‹ Trinity vs Millsaps | Holy Crap ›
()
Create an executable file called "tinyurl" in your executable path which contains something like:
#!/bin/sh
wget -q -O - \
-U "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.8) Gecko/20071008 Firefox/2.0.0.8" \
--header="Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1" \
--header="Accept-Language: en" \
--header="Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7" \
--referer="http://tinyurl.com/" \
--header="Content-Type: application/x-www-form-urlencoded" \
--post-data="url=$*" \
http://tinyurl.com/create.php \
| sed -n 's/.*\(http:\/\/tinyurl.com\/[a-z0-9][a-z0-9]*\).*/\1/p' \
| uniq

Then you can create a tinyurl by running:

tinyurl 'http://example.com/some/long/url/goes/here'

The headers were copied from the Firefox TinyUrl Creator source code.

Suggested Links

line continuations in the shell

> | sed -n 's/.*\(http:\/\/tinyurl.com\/[a-z0-9][a-z0-9]*\).*/\1/p' \

You get a free line continuation after a |, so I would rewrite these as

...
http... |
sed -n ... |
uniq

I would understand if you like starting the lines with pipes for stylistic reasons. I wouldn't agree, but I would understand.

cool tip

I didn't know that. I guess I put pipes in front to make it clear at a glance that the command is a continuation and not a new command, especially when the previous line is long. An indent level would work too. Perhaps you originally included one in your comment, not realizing it would get attacked by the HTML sanitizing monster.

indeed

You also get free line continuations after && and ||.

At Google every checkin requires a code review, so I've developed all kinds of persnickety observations like this.

Your way is better

Looking at this again, I think your hanging indent idea is better. Technically, there could be a command called "-U" or a command called "http://tinyurl.com/create.php" somewhere on the path, so all lines -- not just pipes and redirects -- could benefit from the clarity of indentation.

There's got to be some way to convert all those observations into a best selling technical book. You could call it "Google Secrets!: The best of Google's code reviews" or "Tips and Tricks from the Google Trenches" or some other similarly super awesome name.

jtr is lying

Nobody actually does code reviews.

Syndicate content