Beer pouring robot instructional video (Video)
Posted by Lem on January 30th, 2010Imagination+wheelchair+cake_cover=snow blowing robot
Posted by Lem on January 30th, 2010Augmented Reality Architecture App by the NAI
Posted by miles on January 29th, 2010Augmented (hyper)Reality: Domestic Robocop
Posted by miles on January 28th, 2010Replacing URLs with links… halp?
Posted by rajbot on January 26th, 2010I found this crazy regex for matching URLs in python. Even though some very smart people went through the trouble of concocting that regex, I can’t seem to use for all text cases… hmm.
I’m trying to turn bare urls into links for our Twitter sidebar widget, and it almost works, except for the last crazy case below (query string + anchor):
#!/usr/bin/python
import re
def convertLinks(str):
#crazy regex from http://flanders.co.nz/2009/11/08/a-good-url-regular-expression-repost/
prog = re.compile(r'(?#Protocol)(?:(?:ht|f)tp(?:s?)\:\/\/|~\/|\/)?(?#Username:Password)(?:\w+:\w+@)?(?#Subdomains)(?:(?:[-\w]+\.)+(?#TopLevel Domains)(?:com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum|travel|[a-z]{2}))(?#Port)(?::[\d]{1,5})?(?#Directories)(?:(?:(?:\/(?:[-\w~!$+|.,=]|%[a-f\d]{2})+)+|\/)+|\?|#)?(?#Query)(?:(?:\?(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)(?:&(?:[-\w~!$+|.,*:]|%[a-f\d{2}])+=?(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)*)*(?#Anchor)(?:#(?:[-\w~!$+|.,*:=]|%[a-f\d]{2})*)?')
return prog.sub(r'<a href="\g<0>">\g<0></a>', str)
#single url
print convertLinks('http://tikirobot.net\n')
#string
print convertLinks('See http://tikirobot.net for more info.\n')
#two urls in a string
print convertLinks('See http://tikirobot.net or http://wikipedia.org for more info.\n')
#some test urls from flanders.co.nz
print convertLinks('This is a google search: http://www.google.com/search?q=good+url+regex&rls=com.microsoft:*&ie=UTF-8&oe=UTF-8&startIndex=&startPage=1\n')
print convertLinks('ftp://joe:password@ftp.filetransferprotocal.com is a ftp url\n')
print convertLinks('There is a bare url google.ru somewhere in this sentence\n')
#This one fails
print convertLinks('This one fails: both a query string and an anchor: https://some-url.com?query=&name=joe?filter=*.*#some_anchor\n')Also note my double-grouping on the regex.. There must be a better way!
Update, figured out that the group zero backreference is \g ( doesn’t work, so I was double-grouping so that I could use \1).
Little help, regex ninjas?
Fever Ray WANTS YOUR BRAIN
Posted by rajbot on January 26th, 2010Karin Dreijer Andersson made it on to Resident Advisor’s Top 100 albums of the ’00s list twice, once for her solo album as Fever Ray and again for her collaboration with her brother as The Knife.
Here is an acceptance speech that Fever Ray gave at an awards show in Sweeden. It is one of the best acceptance speeches ever given:
Recent Comments