<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>mFabrik - mobile sites, apps, HTML5 and CMS software development &#187; hostname</title>
	<atom:link href="http://blog.mfabrik.com/tag/hostname/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mfabrik.com</link>
	<description>Freedom delivered.</description>
	<lastBuildDate>Wed, 03 Aug 2011 09:47:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Testing if hostname is numeric IPv4</title>
		<link>http://blog.mfabrik.com/2010/08/31/testing-if-hostname-is-numeric-ipv4/</link>
		<comments>http://blog.mfabrik.com/2010/08/31/testing-if-hostname-is-numeric-ipv4/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 14:51:44 +0000</pubDate>
		<dc:creator>Mikko Ohtamaa</dc:creator>
				<category><![CDATA[iphone]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[hostname]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[ipv4]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://blog.mfabrik.com/?p=716</guid>
		<description><![CDATA[I had to resort this hack when testing a hybrid web/mobile site which uses site hostname based device discrimination. In production mode we can have m.yoursite.com and www.yoursite.com hostnames. However, when running the site locally, on your development computer and in LAN this does not work very well: one cannot spoof hostnames for web browsers [...]]]></description>
			<content:encoded><![CDATA[<p>I had to resort this hack when testing a hybrid web/mobile site which uses site hostname based device discrimination. In production mode we can have <em>m.yoursite.com</em> and<em> www.yoursite.com</em> hostnames. However, when running the site locally, on your development computer and in LAN this does not work very well: one cannot spoof hostnames for web browsers in devices like iPhone/iPod/other mobile phone unless you install a DNS server. And installing a DNS server for LAN is something you don&#8217;t want to do&#8230;</p>
<p>So, I figured out that I can use  hostname spoofing on desktop computers (/etc/hosts file) and I always access the site via numeric IP (IPv4 over ethernet) when testing over WLAN on mobile devices.</p>
<ul>
<li>The site is rendered in web mode when it is being accessed via textual hostname (localhost, yourpcname)</li>
<li>The site is rendered in mobile mode when it is being accessed via IPv4 numeric hostname (127.0.0.1, 196.168.200.1)</li>
</ul>
<p>And,&#8230; dadaa,&#8230; here is my magical code to test whether hostname is numeric IPv4. I couldn&#8217;t find a ready function from Python standard library</p>
<pre>import re

ipv4_regex_source = "^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
ipv4_regex = re.compile(ipv4_regex_source)

def is_numeric_ipv4(str):
    """

http://answers.oreilly.com/topic/318-how-to-match-ipv4-addresses-with-regular-expressions/

    @param str: Hostname as a string.

    @return: True if the given string is numeric IPv4 address
    """
    # ^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
    return ipv4_regex.match(str)</pre>
<p class="signature">
<a href="http://mfabrik.com/@@zoho-contact-form"><img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/mfabrik-24.png"></a> <a href="http://mfabrik.com/@@zoho-contact-form">Get developers</a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml"><img valign="middle" src="http://www.feedburner.com/fb/images/pub/feed-icon16x16.png" alt="" style="vertical-align:middle;border:0"/></a> <a href="http://feeds.feedburner.com/mFabrikWebAndMobileDevelopment" rel="alternate" type="application/rss+xml">Subscribe mFabrik blog in a reader</a> <a href="http://twitter.com/mfabrik"> <img valign="middle"  src="http://blog.mfabrik.com/wp-content/uploads/twitter-24.png"></a> <a href="http://twitter.com/moo9000">Follow me on Twitter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2010/08/31/testing-if-hostname-is-numeric-ipv4/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Python-like urlparser module for Javascript</title>
		<link>http://blog.mfabrik.com/2008/11/29/python-like-urlparser-module-for-javascript/</link>
		<comments>http://blog.mfabrik.com/2008/11/29/python-like-urlparser-module-for-javascript/#comments</comments>
		<pubDate>Sat, 29 Nov 2008 01:56:42 +0000</pubDate>
		<dc:creator>Mikko Ohtamaa</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fragment]]></category>
		<category><![CDATA[hostname]]></category>
		<category><![CDATA[href]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[location]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[urlparse]]></category>
		<category><![CDATA[urlparser]]></category>

		<guid isPermaLink="false">http://blog.redinnovation.com/?p=152</guid>
		<description><![CDATA[I had to deconstruct and reconstruct URLs from pieces when doing advanced Javascripting for Plone. I found this nice library from Denis Laprise. However, it had a bug with fragment extractor and lacked reconstruction possibilies. So I decided to make a new version. Download urlparse.js version 0.2. thank you Couple of examples: var p = [...]]]></description>
			<content:encoded><![CDATA[<p>I had to deconstruct and reconstruct URLs from pieces when doing advanced Javascripting for Plone.</p>
<p>I found this <a href="https://code.poly9.com/trac/browser/urlparser/urlparser.js">nice library</a> from <span class="c">Denis Laprise. However, it had a bug with fragment extractor and lacked reconstruction possibilies. So I decided to make a new version.</span></p>
<p><a href="http://snipplr.com/view/10139/urlparse--pythonlike-url-parser-and-manipulator/">Download urlparse.js version 0.2</a>. thank you <img src='http://blog.mfabrik.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Couple of examples:</p>
<pre>var p = new Poly9.URLParser('http://user:password@poly9.com/pathname?arguments=1#fragment');
p.getHost() == 'poly9.com';
p.getProtocol() == 'http';
p.getPathname() == '/pathname';
p.getQuerystring() == 'arguments=1';
p.getFragment() == 'fragment';
p.getUsername() == 'user';
p.getPassword() == 'password';

var p = new Poly9.URLParser("http://localhost:8080/path);

p.setQuerystring("foo=bar");
p.setFragment("anchor");
p.setPort(7070);

var url = p.getURL() // http://localhost:7070/path?foo=bar#anchor</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.mfabrik.com/2008/11/29/python-like-urlparser-module-for-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

