Posts Tagged ‘javascript’

get registered domain in Python and Javascript

April 5, 2011

reg-dom-libs are a set of libraries for C, PHP and Perl to convert an arbitrary domain name to the registered domain name.

  • for simple domains, like http://www.amazon.com or news.ycombinator.com, the task is trivial.
  • for more complicated ones, like http://www.ebay.co.uk or http://www.japantimes.co.jp, handling the second level subdomain is a little painful.
  • for exoteric ones, like nic.com.ai or http://www.nic.net.ge or 公司.cn, the problem becomes virtually impossible.
  • after seeing stupid ones, like http://www.comune.caserta.it (believe it or not, the registered domain is comune.caserta.it!), I gave up finding an elegant algorithm for the problem.
  • a full list of valid registered domain is necessary. luckily, it is available (and nightly updated) here.

inspired by reg-dom-libs, I’ve ported the algorithm to Python and Javascript.
see the tests at the end of each file for an example of the usage.

a demo is availble here.

Advertisements

handling an iframe from the inside

March 30, 2011

if you’ve ever worked with iframes you’ve certainly run into the same origin policy.

from here:

The same origin policy basically limits how scripts and frames on different domains can talk to each other.

this is particularly bad if you want to resize an iframe to accomodate its content, as this is not doable with simple CSS (to the best of my knowledge!). it can be done using window.postMessage, though.

see a demo here.

basically, the content of the iframe fires postMessages to its parent window and the window itself, i.e. the iframe container, handles them. cool…