tglogo.png
0 LIKES

Snippet


is.gd URL Shortener

In Category General IRC Posted by sugarboy On 12/18/10

My first time using sockets. Used to shorten urls using is.gd
Credit Swiftirc forums for the socket tutorial I followed.
alias shorten {
  if (sock(isgd)) {
    sockclose isgd
    sockopen isgd is.gd 80
    set %isgd $$1
  }
  else {
    sockopen isgd is.gd 80
    set %isgd $$1
  }
}
on *:sockopen:isgd:{
  sockwrite -nt $sockname GET /api.php?longurl= $+ %isgd HTTP/1.1
  sockwrite -nt $sockname Host: is.gd
  sockwrite -nt $sockname $crlf
}
on *:sockread:isgd:{
  sockread %temp
  if (http://is.gd/* iswm %temp) {
    echo -a Shortened URL: %temp
  }
}
menu Menubar {
  Shorten URL: /shorten $$?="URL to Shorten?"
}


Comments 3

Fanfare - Saturday, 8 January, 2011
[code]if (sock(isgd)) { sockclose isgd } sockopen isgd is.gd 80 set %isgd $$1 } }[/code]No else condition is needed. [code] var %temp sockread %temp[/code]So that you don't have the data set as a global var in your variable.
sugarboy - Sunday, 19 December, 2010
Thank you err0r. This was my very first try with sockets. I have searched for something like it in the pass, but never found anything. So I figured it would be something to try for my first attempt. Actually quite proud of myself. ^__^
err0r - Sunday, 19 December, 2010
nice snippet

Please note that on our website we use cookies necessary for the functioning of our website, cookies that optimize the performance. To learn more about our cookies, how we use them and their benefits, please read our Cookie Policy.
I Understand