<?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>web development &#8211; stoimen&#039;s web log</title>
	<atom:link href="/category/web-development/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>Javascript Array Unique</title>
		<link>/2015/05/04/javascript-array-unique/</link>
		<comments>/2015/05/04/javascript-array-unique/#comments</comments>
		<pubDate>Mon, 04 May 2015 13:15:39 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Method]]></category>

		<guid isPermaLink="false">/?p=3600</guid>
		<description><![CDATA[<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/01/21/array-merge-in-javascript/" rel="bookmark" title="Array merge in JavaScript">Array merge in JavaScript </a></li>
<li><a href="/2009/03/07/flex-javascript-communication/" rel="bookmark" title="Flex Javascript communication">Flex Javascript communication </a></li>
<li><a href="/2009/03/12/javascript-rounded-corners/" rel="bookmark" title="JavaScript rounded corners">JavaScript rounded corners </a></li>
<li><a href="/2010/07/01/replace-the-broken-images-with-a-default-image-with-javascript/" rel="bookmark" title="Replace the Broken Images with a Default Image with JavaScript">Replace the Broken Images with a Default Image with JavaScript </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p><script src="https://gist.github.com/stoimen/c42dcc2d57f6f68c3941.js"></script></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/01/21/array-merge-in-javascript/" rel="bookmark" title="Array merge in JavaScript">Array merge in JavaScript </a></li>
<li><a href="/2009/03/07/flex-javascript-communication/" rel="bookmark" title="Flex Javascript communication">Flex Javascript communication </a></li>
<li><a href="/2009/03/12/javascript-rounded-corners/" rel="bookmark" title="JavaScript rounded corners">JavaScript rounded corners </a></li>
<li><a href="/2010/07/01/replace-the-broken-images-with-a-default-image-with-javascript/" rel="bookmark" title="Replace the Broken Images with a Default Image with JavaScript">Replace the Broken Images with a Default Image with JavaScript </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2015/05/04/javascript-array-unique/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>5 Tips on How to Spot a Bad Developer and Team Member</title>
		<link>/2012/03/02/5-tips-on-how-to-spot-a-bad-developer-and-team-member/</link>
		<comments>/2012/03/02/5-tips-on-how-to-spot-a-bad-developer-and-team-member/#comments</comments>
		<pubDate>Fri, 02 Mar 2012 11:41:22 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programmer]]></category>
		<category><![CDATA[team member]]></category>
		<category><![CDATA[Technology/Internet]]></category>

		<guid isPermaLink="false">/?p=2811</guid>
		<description><![CDATA[1. He hates libraries, framworks and cutting edge technologies He always hates newest technologies and considers that pure programming with no libraries and frameworks is the masterpiece of coding and only way to show his greatness. Any mention of a library name results in something like &#8220;blah, this sucks&#8221; with no explanation why. However most &#8230; <a href="/2012/03/02/5-tips-on-how-to-spot-a-bad-developer-and-team-member/" class="more-link">Continue reading <span class="screen-reader-text">5 Tips on How to Spot a Bad Developer and Team Member</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/06/12/joomla-old-code-or-bad-code/" rel="bookmark" title="Joomla! &#8211; Old Code or Bad Code?">Joomla! &#8211; Old Code or Bad Code? </a></li>
<li><a href="/2010/02/19/jquery-tips-storing-data/" rel="bookmark" title="jQuery tips &#8211; storing data">jQuery tips &#8211; storing data </a></li>
<li><a href="/2009/05/25/ie-developer-tools/" rel="bookmark" title="IE developer tools">IE developer tools </a></li>
<li><a href="/2010/10/04/some-php-tips-basename/" rel="bookmark" title="Some PHP Tips: basename()">Some PHP Tips: basename() </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>1. He hates libraries, framworks and cutting edge technologies</h2>
<p>He always hates newest technologies and considers that pure programming with no libraries and frameworks is the masterpiece of coding and only way to show his greatness. Any mention of a library name results in something like &#8220;blah, this sucks&#8221; with no explanation why. However most often the reason is &#8220;because it’s slow&#8221; with no examples of how slow actually this library is &#8211; he does not make any performance tests at all. Always prefers to write his own pure “javascript” or “php” based code/library because he thinks this is the cutting edge of modern technology. </p>
<h2>2. He hates helping and talking to clients</h2>
<p>Always after a phone call with a client he’s angry, because “the sutpid client” doesn’t understand his way of brilliant thinking. He thinks that a project must exists just to show what a “good” developer he is and how much he knows, not because the product will be someday, somehow used by poor clients.</p>
<h2>3. He loves to see how others make mistakes</h2>
<p>Bugs by other developers are always accepted with a smile with some words like “I told you”. He doesn’t think bugs will be comited if he were the developer. However bugs in his code are always accepted and explained as misconseption of the client!</p>
<h2>4. Always negative at meetings</h2>
<p>Whatever solution is proposed on a meeting he’s negative. But he doesn’t propose his own solution. Typically a bad team member is always trying to say &#8220;whatever solution you get I’m telling you that there are some pitfalls&#8221;.</p>
<h2>5. He hates interviews</h2>
<p>Because he thinks he’s the best programmer in the world, he hates going to interviews. His behaviour on interviews is always like “you know less than me and I don’t know why I’m here”. However once he gets the job he behaves with his boss like “I’m making you a favor to receive a salary from you!”</p>
<p>Advice: To avoid working with such jerks try to spot them on the interview. If he tells you that your choice of library and technology sucks you should better get another candidate.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/06/12/joomla-old-code-or-bad-code/" rel="bookmark" title="Joomla! &#8211; Old Code or Bad Code?">Joomla! &#8211; Old Code or Bad Code? </a></li>
<li><a href="/2010/02/19/jquery-tips-storing-data/" rel="bookmark" title="jQuery tips &#8211; storing data">jQuery tips &#8211; storing data </a></li>
<li><a href="/2009/05/25/ie-developer-tools/" rel="bookmark" title="IE developer tools">IE developer tools </a></li>
<li><a href="/2010/10/04/some-php-tips-basename/" rel="bookmark" title="Some PHP Tips: basename()">Some PHP Tips: basename() </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2012/03/02/5-tips-on-how-to-spot-a-bad-developer-and-team-member/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>PHP Performance: Bitwise Division</title>
		<link>/2012/01/05/php-performance-bitwise-division/</link>
		<comments>/2012/01/05/php-performance-bitwise-division/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 15:38:13 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[bitwise operation]]></category>
		<category><![CDATA[bitwise operators]]></category>
		<category><![CDATA[division]]></category>
		<category><![CDATA[performance tests]]></category>
		<category><![CDATA[php performance]]></category>
		<category><![CDATA[research]]></category>

		<guid isPermaLink="false">/?p=2577</guid>
		<description><![CDATA[Recently I wrote about binary search and then I said that in some languages, like PHP, bitwise division by two is not faster than the typical “/” operator. However I decided to make some experiments and here are the results. Important Note It’s very important to say that the following results are dependant from the &#8230; <a href="/2012/01/05/php-performance-bitwise-division/" class="more-link">Continue reading <span class="screen-reader-text">PHP Performance: Bitwise Division</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2012/01/24/javascript-performance-for-vs-while/" rel="bookmark" title="JavaScript Performance: for vs. while">JavaScript Performance: for vs. while </a></li>
<li><a href="/2010/02/02/firebugs-console-time-accuracy/" rel="bookmark" title="Firebug&#8217;s console.time() accuracy">Firebug&#8217;s console.time() accuracy </a></li>
<li><a href="/2009/12/30/jquery-live-vs-bind-performance/" rel="bookmark" title="jQuery live() vs bind() performance">jQuery live() vs bind() performance </a></li>
<li><a href="/2012/07/24/php-arrays-or-linked-lists/" rel="bookmark" title="PHP: Arrays or Linked Lists?">PHP: Arrays or Linked Lists? </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Recently I wrote about <a href="/2011/12/26/computer-algorithms-binary-search/" title="Computer Algorithms: Binary Search">binary search</a> and then I said that in some languages, like PHP, bitwise division by two is not faster than the typical “/” operator. However I decided to make some experiments and here are the results.</p>
<h2>Important Note</h2>
<p>It’s very important to say that the following results are dependant from the machine and the environment!</p>
<h2>Source Code</h2>
<p>Here&#8217;s the PHP source code.</p>
<pre lang="PHP">
function divide($n = 1) 
{
	$a = microtime(true);
	for ($i = 0; $i < $n; $i++) {
		300/2;
	}
	echo microtime(true) - $a;
}

divide(100);
//divide(1000);
//divide(10000);
//divide(100000);
//divide(1000000);
//divide(10000000);
</pre>
<p><span id="more-2577"></span><br />
and bitwise ...</p>
<pre lang="PHP">
function bitwise($n = 1)
{
	$a = microtime(true);
	for ($i = 0; $i < $n; $i++) {
		300 >> 1;
	}
	echo microtime(true) - $a;
}

bitwise(100);
//bitwise(1000);
//bitwise(10000);
//bitwise(100000);
//bitwise(1000000);
//bitwise(10000000);
</pre>
<p>Note that each method was called 6 times with the same parameter. This means that divide(100) was called 6 times and then I used the average value of these six times.</p>
<h2>Results</h2>
<p>I said back then in my binary search post, that in PHP the bitwise operator ">> 1" is not faster than the typical division with the "/" operator. However the results tells us that using bitwise division is slightly faster, as you can see at the diagram bellow.</p>
<pre lang="PHP">
n		">>"			"/"
100		0.0002334912618		0.000311803817749
1000		0.001911004384359	0.007335503896078
10000		0.013423800468445	0.039460102717081
100000		0.14417803287506	0.21413381894429
1000000		1.15839115778605	1.17152162392935
10000000	10.556711634		11.0911625623705
</pre>
<figure id="attachment_2596" style="width: 600px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/01/bitwise-divide-by-two.png"><img src="/wp-content/uploads/2012/01/bitwise-divide-by-two.png" alt="PHP Performance: Bitwise division is slightly faster!" title="bitwise-divide-by-two" width="600" height="371" class="size-full wp-image-2596" srcset="/wp-content/uploads/2012/01/bitwise-divide-by-two.png 600w, /wp-content/uploads/2012/01/bitwise-divide-by-two-300x185.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a><figcaption class="wp-caption-text">Bitwise division is slightly faster!</figcaption></figure>
<h2>Conclusion</h2>
<p>Although bitwise division is a bit faster the difference is so small that you should work with very large data in order to gain some performance.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2012/01/24/javascript-performance-for-vs-while/" rel="bookmark" title="JavaScript Performance: for vs. while">JavaScript Performance: for vs. while </a></li>
<li><a href="/2010/02/02/firebugs-console-time-accuracy/" rel="bookmark" title="Firebug&#8217;s console.time() accuracy">Firebug&#8217;s console.time() accuracy </a></li>
<li><a href="/2009/12/30/jquery-live-vs-bind-performance/" rel="bookmark" title="jQuery live() vs bind() performance">jQuery live() vs bind() performance </a></li>
<li><a href="/2012/07/24/php-arrays-or-linked-lists/" rel="bookmark" title="PHP: Arrays or Linked Lists?">PHP: Arrays or Linked Lists? </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2012/01/05/php-performance-bitwise-division/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>OOP JavaScript: Accessing Public Methods in Private Methods</title>
		<link>/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/</link>
		<comments>/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 12:05:42 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[Accessing Private]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[Object-oriented programming]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[private]]></category>
		<category><![CDATA[public]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[Subroutine]]></category>

		<guid isPermaLink="false">/?p=2339</guid>
		<description><![CDATA[As you know in JavaScript when you define a variable with the special word &#8220;var&#8221; the scope of this variable is within the function. So when you simply wite &#8220;var a = 5&#8221; the variable named &#8220;a&#8221; has a global scope and can be accessed in any function in the global scope. var a = &#8230; <a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" class="more-link">Continue reading <span class="screen-reader-text">OOP JavaScript: Accessing Public Methods in Private Methods</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
<li><a href="/2011/10/20/some-notes-on-the-object-oriented-model-of-php/" rel="bookmark" title="Some Notes on the Object-oriented Model of PHP">Some Notes on the Object-oriented Model of PHP </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/03/09/what-make-javascript-closures-work/" rel="bookmark" title="What make JavaScript closures work?">What make JavaScript closures work? </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>As you know in JavaScript when you define a variable with the special word &#8220;var&#8221; the scope of this variable is within the function. So when you simply wite &#8220;var a = 5&#8221; the variable named &#8220;a&#8221; has a global scope and can be accessed in any function in the global scope. </p>
<pre lang="javascript">
var a = 5;

function f() { return a; } // returns 5
</pre>
<p>Thus f will return the value of &#8220;a&#8221; which equals to 5. You can also change the value of the global variable in the function body.</p>
<pre lang="javascript">
var a = 5;
function f() { a = 10; return a; }
console.log(a); // equals to 10
</pre>
<p>Now after we call the function f the value of &#8220;a&#8221; will equal to 10. This is because we reference the global variable &#8220;a&#8221; into the function body without using the keyword &#8220;var&#8221;. This means that if you put the &#8220;var&#8221; keyword the variable &#8220;a&#8221; inside the function body is no longer the same variable as the variable defined outside the body. It becames &#8220;local&#8221; and it&#8217;s visible only inside the function.<br />
<span id="more-2339"></span></p>
<h2>Objects &#038; JavaScript</h2>
<p>Actually in JavaScript functions can be also objects. Any variable defined with the &#8220;var&#8221; keyword becomes private, because it&#8217;s only visible inside the function body, while by using the &#8220;this&#8221; keyword we can define global variables visible outside the function body. Let&#8217;s see na example.</p>
<pre lang="javascript">
var f = function() 
{
	var a = 10;
	this.b = 5;
}

var myfunc = new f();
myfunc.a; // is undefined because a is private
myfunc.b; // equals to 5 because b is public
</pre>
<h2>Public and Private Methods in JavaScript</h2>
<p>As you may know in JS you can define functions inside other functions. Actually this is how you can define classes in JavaScript.</p>
<pre lang="javascript">
var myClass = function() 
{
	var f = function() {
		return 10;
	}
}
</pre>
<p>But this in fact defines a local (private) function into myClass and we cannot access it from the outside world. Here&#8217;s a fully functional class with one public and one private method.</p>
<pre lang="javascript">
var myClass = function()
{
	// public method
	this.a = function() {
		return 10;
	}
	
	// private method
	var b = function() {
		return 5;
	}
}

var c = new myClass();
c.a(); // will return 10
c.b(); // is undefined, because is private
</pre>
<h2>Accessing Private Methods from Public Methods</h2>
<p>Easily we can access private methods from public ones.</p>
<pre lang="javascript">
var myClass = function()
{
	// public method
	this.a = function() {
		return b();
	}
	
	// private method
	var b = function() {
		return 5;
	}
}
</pre>
<p>However accessing public mtehods in private ones is more difficult. That&#8217;s because we cannot use &#8220;this&#8221; into the private methods, just because &#8220;this&#8221; refers to the private method<br />
itself and not to the global method, which is &#8220;myClass&#8221; in our case.</p>
<pre lang="javascript">
var myClass = function()
{
	// public method
	this.a = function() {
		return 10;
	}
	
	// private method
	var b = function() {
		return this.a(); // this will result in an error
	}
}
</pre>
<h2>Accessing Public Methods from Private Methods</h2>
<p>To access public methods in private methods you need to define a variable that points to the global &#8220;this&#8221; object.</p>
<pre lang="javascript">
var myClass = function()
{
	var self = this; 
	
	// public method
	this.a = function() {
		return 10;
	}
	
	// private method
	var b = function() {
		return self.a(); // this will return 10
	}
}
</pre>
<p>This variable gives you the bridge between private methods and global &#8220;this&#8221; pointer.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
<li><a href="/2011/10/20/some-notes-on-the-object-oriented-model-of-php/" rel="bookmark" title="Some Notes on the Object-oriented Model of PHP">Some Notes on the Object-oriented Model of PHP </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/03/09/what-make-javascript-closures-work/" rel="bookmark" title="What make JavaScript closures work?">What make JavaScript closures work? </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Object Oriented JavaScript: Inheritance</title>
		<link>/2011/05/30/object-oriented-javascript-inheritance/</link>
		<comments>/2011/05/30/object-oriented-javascript-inheritance/#comments</comments>
		<pubDate>Mon, 30 May 2011 09:43:53 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[code sample]]></category>
		<category><![CDATA[code snippet]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[Inheritance]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Literal]]></category>
		<category><![CDATA[object oriented]]></category>
		<category><![CDATA[Object-oriented programming]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[oop javascript]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Software engineering]]></category>

		<guid isPermaLink="false">/?p=2314</guid>
		<description><![CDATA[Objects and JavaScript JavaScript, being a functional language, differs from most of the procedural/object oriented languages we know. The object oriented approach in JavaScript is rather strange. However there is much power in making objects! The syntax is really odd and there are several approaches. Literal Notation As many of you may know the most &#8230; <a href="/2011/05/30/object-oriented-javascript-inheritance/" class="more-link">Continue reading <span class="screen-reader-text">Object Oriented JavaScript: Inheritance</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2011/10/20/some-notes-on-the-object-oriented-model-of-php/" rel="bookmark" title="Some Notes on the Object-oriented Model of PHP">Some Notes on the Object-oriented Model of PHP </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/03/02/javascript-inheritance-example/" rel="bookmark" title="JavaScript inheritance example">JavaScript inheritance example </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Objects and JavaScript</h2>
<p><a href="/tag/javascript/" title="JavaScript on Stoimen.com">JavaScript</a>, being a functional language, differs from most of the procedural/object oriented languages we know. The object oriented approach in JavaScript is rather strange. However there is much power in making objects! The syntax is really odd and there are several approaches.</p>
<h2>Literal Notation</h2>
<p>As many of you may know the most used notation is the JSON (JavaScript Object Notation).</p>
<pre lang="javascript">
{ 'key1' : 'val1'
, 'key2' : 'val2'
, 'key3' : 'val3'
}
</pre>
<p>Of course this is the very basic example. You can use as value any JavaScript object &#8211; another similar object or a function.</p>
<pre lang="javascript">
{ 'key1' : 'val1'
, 'key2' : { 'inner_key1' : 'inner_val1' }
, 'key3' : function() {
			return 10 + 5;
		 }
}
</pre>
<p>The two examples above are showing an anonymous object in JavaScript, but you can assign this code to some variable.</p>
<pre lang="javascript">
var myObject = 
	{ 'key1' : 'val1'
	, 'key2' : 'val2'
	, 'key3' : 'val3'
	}
</pre>
<p>or </p>
<pre lang="javascript">
var myObject =
	{ 'key1' : 'val1'
	, 'key2' : { 'inner_key1' : 'inner_val1' }
	, 'key3' : function() {
				return 10 + 5;
			 }
	}
</pre>
<p>and then you can call the properties of these objects with the &#8216;.&#8217; operator:</p>
<pre lang="javascript">
myObject.key1;
myObject.key2.inner_key1;
myObject.key3();
</pre>
<p>So far so good &#8211; this is the literal object notation in JavaScript. However there is another &#8220;objects&#8221; in JavaScript.<br />
<span id="more-2314"></span></p>
<h2>Objects and Functions in JavaScript</h2>
<p>Actually in JS the functions are also objects (classes). So you can define a function and then define another function inside or use the &#8220;this&#8221; operator.</p>
<pre lang="javascript">
var a = function(name)
{
	this.name = name;
	
	this.print = function() {
		alert(this.name);	
	}
}
</pre>
<p>Then you can make a new instance of this &#8220;class&#8221;.</p>
<pre lang="javascript">
var myObject = new a('hello world');
var anotherObject = new a('some test');

myObject.print(); // will print the string "hello world"
anotherObject.print(); // will print the string "some test"
</pre>
<p>Thus the function <strong>&#8220;a&#8221;</strong> defined within the code <strong>&#8220;var a = function(name) &#8230;&#8221;</strong> is a class in JavaScript. You can make instances (objects) of this class with the &#8220;new&#8221; operator.</p>
<p>You can use another notation for defining the function &#8220;a&#8221;, so both can be used and it&#8217;s up to you to decide which one is more convenient.</p>
<pre lang="javascript">
function a(name) 
{
	this.name = name;
	
	this.print = function() {
		alert(this.name);	
	}	
}
</pre>
<h2>Prototypes</h2>
<p>JS gives you more power. In most of the languages you&#8217;ve to define the class first and then make objects. In JS you can define a &#8220;class&#8221; then make some objects and then add some properties to the class by using the prototype.</p>
<pre lang="javascript">
var a = function(name) 
{
	this.name = name;
}

var myObj = new a('hello world');

a.prototype.print = function() {
	alert(this.name);	
}

myObj.print();
</pre>
<p>So you can see how you can add functions and properties to an already defined class using the prototype. Thus you can call the &#8220;print&#8221; function on the myObj object.</p>
<h2>Inheritance</h2>
<p>The prototype built-in property can be used to make use of one of the main OOP features &#8211; inheritance. </p>
<pre lang="javascript">
var SuperClass = function()
{
	this.superFunction = function() {
		return 'function in Super Class';	
	}
}

var sup = new SuperClass();
sup.superFunction(); // will return the string "function in Super Class"
</pre>
<p>Now you can add one more class and set its prototype to the SuperClass</p>
<pre lang="javascript">
var SubClass = function()
{
	this.subFunction = function() {
		return 'function in Sub Class';	
	}	
}

SubClass.prototype = new SuperClass();
</pre>
<p>Thus you make SubClass inherit from SuperClass. Now you can call the SuperClass properties from any SubClass object.</p>
<pre lang="javascript">
var sub = new SubClass();
sub.superFunction(); // will return the string "function in Super Class"
sub.subFunction(); // will return the string "function in Sub Class"
</pre>
<p>Even more! You can add properties to the super class with prototype.</p>
<pre lang="javascript">
SuperClass.prototype.myFunc = function() {
	return 'my new function';	
}
</pre>
<p>And then call it from the sub class:</p>
<pre lang="javascript">
sub.myFunc(); // will return the string "my new function"
</pre>
<h2>Override a Function</h2>
<p>What happens if you have the same function name in both classes. Actually this overrides the method in the sub class.</p>
<pre lang="javascript">
var SuperClass = function()
{
	this.myFunc = function() {
		return 'function in Super Class';	
	}
}

var SubClass = function()
{
	this.myFunc = function() {
		return 'function in Sub Class';	
	}	
}

SubClass.prototype = new SuperClass();

var sub = new SubClass();
sub.myFunc(); // will return the string "function in Sub Class"
</pre>
<p>while </p>
<pre lang="javascript">
var sup = new SuperClass();
sup.myFunc(); // will return the string "function in Super Class"
</pre>
<h2>Conclusion</h2>
<p>Now you know there are classes, inheritance and overrides in JavaScript &#8211; thus you can improve your object oriented JavaScript!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2011/10/20/some-notes-on-the-object-oriented-model-of-php/" rel="bookmark" title="Some Notes on the Object-oriented Model of PHP">Some Notes on the Object-oriented Model of PHP </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/03/02/javascript-inheritance-example/" rel="bookmark" title="JavaScript inheritance example">JavaScript inheritance example </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/05/30/object-oriented-javascript-inheritance/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Scroll an IFRAME Content to a Predefined Position</title>
		<link>/2011/03/29/scroll-an-iframe-content-to-a-predefined-position/</link>
		<comments>/2011/03/29/scroll-an-iframe-content-to-a-predefined-position/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 11:43:36 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[absolute iframe content]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">/?p=2238</guid>
		<description><![CDATA[IFRAME Source Usually when you use an IFRAME tag to link an external source the page that&#8217;s referenced by the SRC attributes is loaded at the top left corner. This is the default behavior, but sometimes you&#8217;d like to show to your users not the entire page from the top left corner, but to show &#8230; <a href="/2011/03/29/scroll-an-iframe-content-to-a-predefined-position/" class="more-link">Continue reading <span class="screen-reader-text">Scroll an IFRAME Content to a Predefined Position</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/04/24/scroll-the-page-with-javascript/" rel="bookmark" title="Scroll the page with JavaScript">Scroll the page with JavaScript </a></li>
<li><a href="/2010/01/24/css-default-position-value/" rel="bookmark" title="CSS default position value">CSS default position value </a></li>
<li><a href="/2009/06/11/remove-iframe-border-on-ie/" rel="bookmark" title="remove iframe border on IE">remove iframe border on IE </a></li>
<li><a href="/2009/11/10/jquery-css-functions-part-1-offset/" rel="bookmark" title="jQuery CSS functions. Part 1 &#8211; offset()">jQuery CSS functions. Part 1 &#8211; offset() </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>IFRAME Source</h2>
<p>Usually when you use an <a href="/tag/iframe/">IFRAME</a> tag to link an external source the page that&#8217;s referenced by the SRC attributes is loaded at the top left corner. This is the default behavior, but sometimes you&#8217;d like to show to your users not the entire page from the top left corner, but to show only part of the external page instead.</p>
<p>In most of the cases the reference is external and you don&#8217;t have control over the external page. Thus you&#8217;ve to scroll the IFRAME content to the desired position. This of course is impossible. Yeah, there are some JavaScript hacks, but they&#8217;re all a bad solution, because the scrolling occurs only after the page is loaded.</p>
<h2>The Solution</h2>
<p>You can wrap the <a href="/tag/iframe/">IFRAME</a> into a div and scroll the DIV content using absolute TOP and LEFT <a href="/tag/css/">CSS</a> properties.</p>
<p>Here&#8217;s an example:</p>
<pre lang="css">
#my-div
{
    width    : 400px;
    height   : 200px;
    overflow : hidden;
    position : relative;
}

#my-iframe
{
    position : absolute;
    top      : -100px;
    left     : -100px;
    width    : 1280px;
    height   : 1200px;
}
</pre>
<p>Here you have one DIV with dimensions 400x200px. Now by moving the IFRAME within it you can position it on the right place.</p>
<pre lang="html4strict">
<div id="my-div">
<iframe src="http://www.example.com/" id="my-iframe" scrolling="no"></iframe>
</div>
</pre>
<p><span id="more-2238"></span><br />
Example with the awesome <a href="http://www.yahoo.com/" target="_blank" title="Yahoo! Homepage">Yahoo! Homepage</a>:<br />
<iframe src="http://stoimen.com/projects/iframe.scrolled.content/" scrolling="no" frameborder="0" style="width:400px;height:390px"></iframe></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/04/24/scroll-the-page-with-javascript/" rel="bookmark" title="Scroll the page with JavaScript">Scroll the page with JavaScript </a></li>
<li><a href="/2010/01/24/css-default-position-value/" rel="bookmark" title="CSS default position value">CSS default position value </a></li>
<li><a href="/2009/06/11/remove-iframe-border-on-ie/" rel="bookmark" title="remove iframe border on IE">remove iframe border on IE </a></li>
<li><a href="/2009/11/10/jquery-css-functions-part-1-offset/" rel="bookmark" title="jQuery CSS functions. Part 1 &#8211; offset()">jQuery CSS functions. Part 1 &#8211; offset() </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/03/29/scroll-an-iframe-content-to-a-predefined-position/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>How to Collect the Images and Meta Tags from a Webpage with PHP</title>
		<link>/2011/02/25/how-to-collect-the-images-and-meta-tags-from-a-webpage-with-php/</link>
		<comments>/2011/02/25/how-to-collect-the-images-and-meta-tags-from-a-webpage-with-php/#comments</comments>
		<pubDate>Fri, 25 Feb 2011 09:23:50 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Facebook Inc]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[HTML element]]></category>
		<category><![CDATA[LinkedIn Corporation]]></category>
		<category><![CDATA[Meta element]]></category>
		<category><![CDATA[Meta Tags]]></category>
		<category><![CDATA[Online social networking]]></category>
		<category><![CDATA[Search engine optimization]]></category>
		<category><![CDATA[search engines]]></category>
		<category><![CDATA[social services]]></category>
		<category><![CDATA[tag]]></category>
		<category><![CDATA[Technical communication]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[Web page]]></category>
		<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">/?p=2216</guid>
		<description><![CDATA[Meta Tags and the Facebook Example You&#8217;ve definitely seen the &#8220;share a link&#8221; screen in Facebook. When you paste a link into the box (fig. 1) and press the &#8220;Attach&#8221; button you&#8217;ll get the prompted cite parsed with a title, description and possibly thumb (fig. 2). This functionality is well known in Facebook, but it &#8230; <a href="/2011/02/25/how-to-collect-the-images-and-meta-tags-from-a-webpage-with-php/" class="more-link">Continue reading <span class="screen-reader-text">How to Collect the Images and Meta Tags from a Webpage with PHP</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/04/20/how-to-sanitize-user-input-in-php/" rel="bookmark" title="How to Sanitize User Input in PHP?">How to Sanitize User Input in PHP? </a></li>
<li><a href="/2010/08/03/html-tags/" rel="bookmark" title="HTML Tags: &lt;base&gt;">HTML Tags: &lt;base&gt; </a></li>
<li><a href="/2010/09/10/automatically-upload-images-with-php-directly-from-the-uri/" rel="bookmark" title="Automatically Upload Images with PHP Directly from the URI">Automatically Upload Images with PHP Directly from the URI </a></li>
<li><a href="/2011/01/18/download-images-with-php/" rel="bookmark" title="Download Images with PHP">Download Images with PHP </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Meta Tags and the Facebook Example</h2>
<p>You&#8217;ve definitely seen the &#8220;share a link&#8221; screen in <a title="Facebook Homepage" href="http://www.facebook.com/" target="_blank">Facebook</a>. When you paste a link into the box (fig. 1) and press the &#8220;Attach&#8221; button you&#8217;ll get the prompted cite parsed with a title, description and possibly thumb (fig. 2). This functionality is well known in Facebook, but it appears to be well known also in various social services. In fact <a title="LinkedIn Homepage" href="http://www.linkedin.com/" target="_blank">Linkedin</a>, <a title="Reddit Homepage" href="http://www.reddit.com/" target="_blank">Reddit</a>, <a title="DZone Homepage" href="http://www.dzone.com/" target="_blank">Dzone</a>&#8216;s <a title="DZone Bookmarklet" href="http://www.dzone.com/links/add.html" target="_blank">bookmarklet</a> use it.</p>
<figure id="attachment_2222" style="width: 518px" class="wp-caption aligncenter"><a href="/wp-content/uploads/2011/02/facebook_attach_prompt_screen.png"><img class="size-full wp-image-2222" title="facebook_attach_prompt_screen" src="/wp-content/uploads/2011/02/facebook_attach_prompt_screen.png" alt="Facebook Attach a Link Prompt Screen" width="518" height="155" srcset="/wp-content/uploads/2011/02/facebook_attach_prompt_screen.png 518w, /wp-content/uploads/2011/02/facebook_attach_prompt_screen-300x89.png 300w" sizes="(max-width: 518px) 100vw, 518px" /></a><figcaption class="wp-caption-text">fig. 1 - Facebook Attach a Link Prompt Screen</figcaption></figure>
<p>Fist thing to notice is that this information, prompted by Facebook, is the same as the meta tag information. However there is a slight difference.</p>
<figure id="attachment_2224" style="width: 526px" class="wp-caption aligncenter"><a href="/wp-content/uploads/2011/02/facebook_attached_link_screen.png"><img class="size-full wp-image-2224" title="facebook_attached_link_screen" src="/wp-content/uploads/2011/02/facebook_attached_link_screen.png" alt="Facebook Attached Link Screen" width="526" height="362" srcset="/wp-content/uploads/2011/02/facebook_attached_link_screen.png 526w, /wp-content/uploads/2011/02/facebook_attached_link_screen-300x206.png 300w" sizes="(max-width: 526px) 100vw, 526px" /></a><figcaption class="wp-caption-text">fig. 2 - Facebook Attached Link Screen</figcaption></figure>
<p>Facebook prefers for the thumb the image set into the &lt;meta property=&#8221;og:image&#8221; &#8230; /&gt;. In the case above this tag appears to be:</p>
<pre lang="html4strict" escaped="true">
<meta property="og:image" content="http://b.vimeocdn.com/ts/572/975/57297584_200.jpg" />
</pre>
<p>And the image pointed in the SRC attribute is exactly the same as the one prompted by Facebook (fig. 3).</p>
<figure id="attachment_2229" style="width: 200px" class="wp-caption aligncenter"><a href="/wp-content/uploads/2011/02/vimeo_thumb.jpg"><img class="size-full wp-image-2229" title="vimeo_thumb" src="/wp-content/uploads/2011/02/vimeo_thumb.jpg" alt="Vimeo Thumb" width="200" height="150" /></a><figcaption class="wp-caption-text">fig. 3 - Vimeo Thumb</figcaption></figure>
<p>First thing to note is that the real thumb is bigger than the thumb shown in Facebook, so Facebook resizes it and the second thing to note is that there are more meta tags of the og:&#8230; format.<span id="more-2216"></span></p>
<h2>Meta Tags and The Open Graph Protocol</h2>
<p>By default meta tags contain various information about the web page. They are not visible in the webpage, but contain some info about it. The most common meta tags are the title, description and keywords tags. They of course contain the title of the page, not that this can be different from the &lt;title&gt; tag, a short description of the page and some keywords describing the content of the page. They are well known also because the search engines make use of them when trying to collect information about the page and the process of SEO passes through it.</p>
<p>However the <a title="Default HTML Meta Tags Specification" href="http://www.w3schools.com/tags/tag_meta.asp" target="_blank">default HTML meta tags</a> cannot contain everything. Thus for example you cannot point the preferable thumbnail for a webpage. The solution is the <a title="The Open Graph Protocol Homepage" href="http://ogp.me/" target="_blank">Open Graph Protocol</a>. It comes with meta tags that can contain more and more valuable info. Such a tag is the og:image meta tag. Note that all the Open Graph (og) meta tags are defined by the og: prefix before the entity name. Thus og:image comes for images, while og:longitude for geo positioning.</p>
<p>That&#8217;s really useful, but how you can read them?</p>
<h2>PHP, Meta Tags and Regexps</h2>
<p>When you try to read information from a webpage source the first possible path is by using <a title="Regular Expressions Explained on Wikipedia" href="http://en.wikipedia.org/wiki/Regular_expression" target="_blank">regular expressions</a>. However PHP is smart enough to offer you some useful functions. Such a function is <a title="PHP get_meta_tags Function Documentation" href="http://php.net/manual/en/function.get-meta-tags.php" target="_blank">get_meta_tags()</a>. As you may guess this method reads the meta tags by given URL.</p>
<pre lang="php" escaped="true">
$a = get_meta_tags('http://vimeo.com/10758212');
var_dump($a);
</pre>
<p>However this method can&#8217;t read Open Graph tags. So finally you&#8217;ve to use some regexps.</p>
<pre lang="php" escaped="true">
preg_match('/<meta property="og:image" content="(.*?)" \/>/', $source, $matches);
</pre>
<p>Now you can grab the og:image tag. And even more &#8211; grab every image (&lt;img&gt;) from that page.</p>
<pre lang="php" escaped="true">
preg_match_all('/<img src="(.*?)"/', $source, $m);
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/04/20/how-to-sanitize-user-input-in-php/" rel="bookmark" title="How to Sanitize User Input in PHP?">How to Sanitize User Input in PHP? </a></li>
<li><a href="/2010/08/03/html-tags/" rel="bookmark" title="HTML Tags: &lt;base&gt;">HTML Tags: &lt;base&gt; </a></li>
<li><a href="/2010/09/10/automatically-upload-images-with-php-directly-from-the-uri/" rel="bookmark" title="Automatically Upload Images with PHP Directly from the URI">Automatically Upload Images with PHP Directly from the URI </a></li>
<li><a href="/2011/01/18/download-images-with-php/" rel="bookmark" title="Download Images with PHP">Download Images with PHP </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/02/25/how-to-collect-the-images-and-meta-tags-from-a-webpage-with-php/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>From SVG to Geo Coordinates &#8211; A Complete Guide</title>
		<link>/2011/02/11/from-svg-to-geo-coordinates-a-complete-guide/</link>
		<comments>/2011/02/11/from-svg-to-geo-coordinates-a-complete-guide/#comments</comments>
		<pubDate>Fri, 11 Feb 2011 08:30:11 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[Algebraic curves]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[approaching algorithm]]></category>
		<category><![CDATA[Bézier curve]]></category>
		<category><![CDATA[Coordinates]]></category>
		<category><![CDATA[Cubic plane curve]]></category>
		<category><![CDATA[Curves]]></category>
		<category><![CDATA[Differential geometry of curves]]></category>
		<category><![CDATA[Geometry]]></category>
		<category><![CDATA[Graphic design]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[Interpolation]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[Splines]]></category>
		<category><![CDATA[text editor]]></category>

		<guid isPermaLink="false">/?p=2174</guid>
		<description><![CDATA[Why This Task Is Not Trivial? First of all what do we have? There is a vector shape, which may represent a map, which we&#8217;d like to convert into a GEO map. In other words there is a SVG file containing the source shape, that you&#8217;d like to convert in geoJSON or whatever collection of &#8230; <a href="/2011/02/11/from-svg-to-geo-coordinates-a-complete-guide/" class="more-link">Continue reading <span class="screen-reader-text">From SVG to Geo Coordinates &#8211; A Complete Guide</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/04/14/you-should-not-insert-an-tag-in-another-tag-ie-breaks/" rel="bookmark" title="You should not insert an &#8220;a&#8221; tag in another &#8220;a&#8221; tag! &#8230;">You should not insert an &#8220;a&#8221; tag in another &#8220;a&#8221; tag! &#8230; </a></li>
<li><a href="/2012/01/30/computer-algorithms-data-compression-with-relative-encoding/" rel="bookmark" title="Computer Algorithms: Data Compression with Relative Encoding">Computer Algorithms: Data Compression with Relative Encoding </a></li>
<li><a href="/2011/03/29/scroll-an-iframe-content-to-a-predefined-position/" rel="bookmark" title="Scroll an IFRAME Content to a Predefined Position">Scroll an IFRAME Content to a Predefined Position </a></li>
<li><a href="/2011/02/25/how-to-collect-the-images-and-meta-tags-from-a-webpage-with-php/" rel="bookmark" title="How to Collect the Images and Meta Tags from a Webpage with PHP">How to Collect the Images and Meta Tags from a Webpage with PHP </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Why This Task Is Not Trivial?</h2>
<p>First of all what do we have? There is a vector shape, which may represent a map, which we&#8217;d like to convert into a GEO map. In other words there is a SVG file containing the source shape, that you&#8217;d like to convert in geoJSON or whatever collection of geo points. This is not trivial, of course, first of all because there&#8217;s no an algorithm or automation that can do this, and because everybody knows that the resulting map will be only approached, but will never be so accurate as the vector shape. This is because in a vector shape you may contain <a title="Bézier curve" href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve" target="_blank">Bézier Curves</a>, which I&#8217;ll show a little bit later in this post, that are difficult to represent in geo coordinates.</p>
<p>So the first task will be to find an approaching algorithm. However there are two things that are optimistic:</p>
<ol>
<li>You can&#8217;t effectively represent Bézier curves in geo coordinates, but even if you could do it there&#8217;s no practical need, because the collection of geo coordinates will be huge and this will slow down you&#8217;re application. Remember that geoJSON is yet again possibly used by your browser and the amount of geo points will be proportionally slowing down the app.</li>
<li>As you may know Google&#8217;s visualization map is representing the World&#8217;s countries again with quite approached maps. Take a look at the following image &#8211; the country borders are quite sharpened:</li>
</ol>
<p style="text-align: center;"><a href="/wp-content/uploads/2011/02/Google_visualization_map.png"><img class="size-full wp-image-2183 aligncenter" title="Google_visualization_map" src="/wp-content/uploads/2011/02/Google_visualization_map.png" alt="Google Visualization Map" width="562" height="351" srcset="/wp-content/uploads/2011/02/Google_visualization_map.png 562w, /wp-content/uploads/2011/02/Google_visualization_map-300x187.png 300w" sizes="(max-width: 562px) 100vw, 562px" /></a></p>
<p>So far we know that we need an approaching algorithm that will convert vector lines and possibly curves in geo coordinates, but before we proceed we&#8217;ve to understand the SVG format.<span id="more-2174"></span></p>
<h2>SVG Format and Possible Approaches</h2>
<p>Let me give you an example of a SVG file. By opening such file with a text editor you can see the file format:</p>
<pre lang="svg">
M76.484,153.703c-0.86-0.27-3.816,0.199-4.002-1.055
	c-0.049-0.328-1.109-1.799-1.512-1.824c-0.647-0.04-5.182,1.896-5.219,2.013c-0.051,0.161,0.928,0.627,0.319,0.832
	c-0.028-0.003-0.716-0.36-0.816-0.334c-0.13,0.034-0.262,0.834-0.363,0.771c-0.176-0.24-0.179-0.48-0.007-0.719
	c-0.986-0.764-0.345,0.764-0.526,0.764c-0.771,0,0.184-0.849-0.675,0.037c-2.13-0.433-2.267-0.756-4.129-2.754
	c-1.329-1.42,0.383-8.158-1.571-8.535c-2.223-3.153-6.413-3.037-8.806-5.037c0.107-0.278,0.201-0.563,0.282-0.853
	c0.369,0.372-4.136-0.768-4.373-0.862c-1.498-0.604-3.574-0.133-4.656,0.355c-0.028-1.22,0.171-2.329-0.593-3.027
	c0.588-2.548-0.652-4.752-2.98-4.199c-0.443-1.354,0.142-0.868-1.171-1.483c-0.154-2.069,2.703-7.729-2.239-8.185
	c2.009-3.137-6.201-0.985-6.627-3.125c-0.14-0.703-5.574,1.563-5.752,0.192c-0.39-2.987-4.411-2.185-5.371-3.372
	c0.518,0.641-6.067,1.078-5.645,0.85c-0.118,0.063-1.38,5.328-1.307,4.994c-0.457,2.076,3.774,9.01,2.893,9.625
	c-0.495,0.347-3.159,6.972-1.295,8.588c-0.59-0.512,2.894-0.209,3.163-0.129c1.333,0.396,3.091,1.66,3.469,3.176
	c0.52,2.486-0.793,2.359-2.357,3.013c-0.658,0.274-2.289,6.779-2.368,7.461c-0.319,2.747-1.413,4.468-1.264,7.483
	c0.098,1.984-0.368,2.326,0.891,4.287c1.933,3.004,2.018,2.57,2.178,5.813c-0.127,1.556-1.742,3.565-1.568,5.388
	c0.074,0.77,0.485,2.028,0.235,2.795c-0.286,0.875-1.936,1.557-1.573,2.627c3.253-2.051,4.522,3.092,8.168,2.83
	c0.958-0.069,3.996,1.508,4.536,1.938c1.437,1.12,2.39-1.618,3.232-1.618c-1.037,0,3.461,2.315,2.95,1.774
	c0.828,0.873,3.852-0.123,5.026,0.304c2.416,0.881,6.011-1.386,7.227-2.174c1.616-1.048,3.15-1.38,4.396-2.816
	c0.639-0.737,2.375-4.448,3.254-4.366c0.354,0.032,0.59,1.01,1.06,0.652c0.163-0.126-1.075-2.664,0.689-2.664
	c0.935,0,4.283-2.113,3.799-3.344c-1.384-3.521,4.799-1.365,6.683-1.926c0.335-0.1,7.816-8.23,7.865-8.641
	C70.216,157.721,77.5,154.025,76.484,153.703C76.247,153.629,76.721,153.777,76.484,153.703z
</pre>
<p>This text represent this shape:</p>
<p><a href="/wp-content/uploads/2011/02/svg_map.png"><img class="aligncenter size-full wp-image-2190" title="svg_map" src="/wp-content/uploads/2011/02/svg_map.png" alt="SVG Map" width="84" height="92" /></a></p>
<p>First thing to notice is there are things quite different from the HTML markup. Of course this things are noticeable. There is a M, c and z where the first two are followed by some numbers. What are these characters? Well lets see at <a title="W3.org SVG" href="http://www.w3.org/TR/SVG/" target="_blank">W3.org</a>. There are lots of SVG specific commands, but we need to understand only few of them.</p>
<p>1.<strong> M</strong> (absolute) <strong>m</strong> (relative) &#8211; moveto</p>
<blockquote><p>Start a new sub-path at the given (x,y) coordinate.           <strong>M</strong> (uppercase) indicates that absolute           coordinates will follow; <strong>m</strong> (lowercase)           indicates that relative coordinates will follow. If a moveto  is           followed by multiple pairs of coordinates, the subsequent  pairs           are treated as implicit lineto commands. Hence, implicit  lineto           commands will be relative if the moveto is relative, and           absolute if the moveto is absolute. If a relative moveto           (<strong>m</strong>) appears as the first element of the path,           then it is treated as a pair of absolute coordinates. In this           case, subsequent pairs of coordinates are treated as relative           even though the initial moveto is interpreted as an absolute  moveto.</p></blockquote>
<p>2. <strong>Z</strong> or <strong>z</strong> &#8211; closepath</p>
<blockquote><p>Close the current subpath by drawing a straight line from the         current point to current subpath&#8217;s initial point. Since the Z  and z         commands take no parameters, they have an identical effect.</p></blockquote>
<p>3. <strong>C</strong> (absolute) <strong>c</strong> (relative) &#8211; curveto (x1 y1 x2 y2 x y)+</p>
<blockquote><p>Draws a cubic Bézier curve from the current         point to (x,y) using (x1,y1) as the control point at the         beginning of the curve and (x2,y2) as the control point at         the end of the curve. <strong>C</strong> (uppercase)         indicates that absolute coordinates will follow;         <strong>c</strong> (lowercase) indicates that relative         coordinates will follow. Multiple sets of coordinates may         be specified to draw a polybézier. At the end of the         command, the new current point becomes the final (x,y)         coordinate pair used in the polybézier.</p></blockquote>
<p>4. <strong>L</strong> (absolute) <strong>l</strong> (relative) &#8211; lineto (x y)+</p>
<blockquote><p>Draw a line from the current point to the given (x,y)         coordinate which becomes the new current point.         <strong>L</strong> (uppercase) indicates that absolute         coordinates will follow; <strong>l</strong> (lowercase)         indicates that relative coordinates will follow. A number         of coordinates pairs may be specified to draw a polyline.         At the end of the command, the new current point is set to         the final set of coordinates provided.</p></blockquote>
<h3>1. Bézier Curves</h3>
<p>So far we know that the especially the c command draws a curve &#8211; a Bézier curve. But what is a Bézier curve anyway? Here&#8217;s a little explanation you can find at <a title="Bézier curve" href="http://en.wikipedia.org/wiki/B%C3%A9zier_curve" target="_blank">Wikipedia</a>. Here&#8217;s an example of a cubic Bézier curve:</p>
<p><a href="/wp-content/uploads/2011/02/Cubic_Bezier_Curve.png"><img class="aligncenter size-full wp-image-2192" title="Cubic_Bezier_Curve" src="/wp-content/uploads/2011/02/Cubic_Bezier_Curve.png" alt="Cubic Bezier Curve" width="300" height="192" /></a>First thing we see is that here there are four points &#8211; p0, p1, p2, p3. The curve between p0 and p3 is defined by them and the two control points &#8211; p1 and p2. To be more precise let me show you an animation of how this curve is constructed:</p>
<p><a href="/wp-content/uploads/2011/02/Bezier_3_big.gif"><img class="aligncenter size-full wp-image-2193" title="Bezier_3_big" src="/wp-content/uploads/2011/02/Bezier_3_big.gif" alt="Cubic Bezier Curve" width="360" height="150" srcset="/wp-content/uploads/2011/02/Bezier_3_big.gif 360w, /wp-content/uploads/2011/02/Bezier_3_big-300x125.gif 300w" sizes="(max-width: 360px) 100vw, 360px" /></a></p>
<p>This is the way the red line is constructed with the help of the green and blue lines, and of course the points p1 and p2. The result is a smooth line that&#8217;s often used in animation and shapes. This is our case. As you&#8217;ve seen the example above is constructed only with curves.</p>
<p>Before we proceed let me say that there are lots of types of Bézier curves not only cubic. Here they are:</p>
<h4>1.1. Linear Bézier curve</h4>
<p><a href="/wp-content/uploads/2011/02/Bezier_1_big.gif"><img class="aligncenter size-full wp-image-2194" title="Bezier_1_big" src="/wp-content/uploads/2011/02/Bezier_1_big.gif" alt="Linear Bezier Curve" width="360" height="150" srcset="/wp-content/uploads/2011/02/Bezier_1_big.gif 360w, /wp-content/uploads/2011/02/Bezier_1_big-300x125.gif 300w" sizes="(max-width: 360px) 100vw, 360px" /></a></p>
<h4>1.2. Quadratic Bézier curve</h4>
<h4><a href="/wp-content/uploads/2011/02/Bezier_2_big.gif"><img class="aligncenter size-full wp-image-2195" title="Bezier_2_big" src="/wp-content/uploads/2011/02/Bezier_2_big.gif" alt="Quadratic Bezier Curve" width="360" height="150" srcset="/wp-content/uploads/2011/02/Bezier_2_big.gif 360w, /wp-content/uploads/2011/02/Bezier_2_big-300x125.gif 300w" sizes="(max-width: 360px) 100vw, 360px" /></a>1.3. And event Higher-order  curves:</h4>
<p><a href="/wp-content/uploads/2011/02/Bezier_4_big.gif"><img class="aligncenter size-full wp-image-2196" title="Bezier_4_big" src="/wp-content/uploads/2011/02/Bezier_4_big.gif" alt="Bezier Curves" width="360" height="150" srcset="/wp-content/uploads/2011/02/Bezier_4_big.gif 360w, /wp-content/uploads/2011/02/Bezier_4_big-300x125.gif 300w" sizes="(max-width: 360px) 100vw, 360px" /></a></p>
<h3>2. What You Need To Know About The SVG Format</h3>
<p>However the most important thing to know is the heart of SVG curve format. First you MOVE to a point with the <strong>M</strong> command. Lets see how does it look in our case:</p>
<p><strong>M76.484,153.703</strong> &#8211; This simply means: move to the point with coordinates (76.484, 153.703)</p>
<p>The next step is to draw a curve. We&#8217;ve seen that a cubic curve is defined by four points &#8211; p0, p1, p2 and p3, but what we have in the SVG format:</p>
<p><strong>c-0.86-0.27-3.816,0.199-4.002-1.055</strong></p>
<p>Here there are only three points (-0.86, -0.27), (-3.816, 0.199), (-4.002, -1.055) &#8211; not four. Well these are only the last three points, the first one is the one defined by the <strong>M</strong> command. Next thing to know is that the <strong>M</strong> command defines an absolute point in the canvas of the SVG file, while the <strong>c</strong> (shouldn&#8217;t be mistaken with <strong>C</strong>) is a relative curve. This means that if the p0 is the point (76.484, 153.703), the p1 point is relative to it with small difference in coordinates &#8211; (-0.86, -0.27).</p>
<p>However the most <em><strong>important</strong></em> thing to know is that after drawing the curve:</p>
<p><em>At the end of the         command, the new current point becomes the final (x,y)         coordinate pair used in the polybézier.</em></p>
<p>This is extremely important! This means that the last point of this curve becomes the p0 of the next curve, and the three points of the second curve, in our case:</p>
<p><strong>c-0.049-0.328-1.109-1.799-1.512-1.824</strong></p>
<p>are relative to the last (x, y) of the previous curve &#8211; (-4.002, -1.055). Without this you cannot convert any SVG shape into geo coordinates.</p>
<h3>3. Lines Instead of Curves</h3>
<p>OK, I said about an approaching algorithm, that is only approaching the curved vector shape. This means that I can simply replace the curves with lines. Thus I&#8217;ve to change to SVG file format from using the <strong>c</strong> command to the <strong>l</strong> command, as<strong> l</strong> is also relative. The curve:</p>
<p><strong>M76.484,153.703 c-0.86-0.27-3.816,0.199-4.002-1.055</strong></p>
<p>will become</p>
<p><strong>M76.484,153.703 l-4.002-1.055</strong></p>
<p>and so forth. This will result into the more sharpened shape:<a href="/wp-content/uploads/2011/02/SVG_Line_Map.png"><img class="aligncenter size-full wp-image-2199" title="SVG_Line_Map" src="/wp-content/uploads/2011/02/SVG_Line_Map.png" alt="SVG Line Map" width="86" height="90" /></a></p>
<p>However this is again a SVG file and no Geo coordinates are present. To end up with this there&#8217;s a tiny PHP script that collects all the last pairs from the c commands and converts them to Geo Coordinates relative to the World&#8217;s center &#8211; (Lat, Lon) = (0, 0).</p>
<pre lang="php">
<?php

$str = '-0.86-0.27-3.816,0.199-4.002-1.055
c-0.049-0.328-1.109-1.799-1.512-1.824c-0.647-0.04-5.182,1.896-5.219,2.013
c-0.051,0.161,0.928,0.627,0.319,0.832c-0.028-0.003-0.716-0.36-0.816-0.334
c-0.13,0.034-0.262,0.834-0.363,0.771c-0.176-0.24-0.179-0.48-0.007-0.719
c-0.986-0.764-0.345,0.764-0.526,0.764c-0.771,0,0.184-0.849-0.675,0.037
c-2.13-0.433-2.267-0.756-4.129-2.754c-1.329-1.42,0.383-8.158-1.571-8.535
c-2.223-3.153-6.413-3.037-8.806-5.037c0.107-0.278,0.201-0.563,0.282-0.853
c0.369,0.372-4.136-0.768-4.373-0.862c-1.498-0.604-3.574-0.133-4.656,0.355
c-0.028-1.22,0.171-2.329-0.593-3.027c0.588-2.548-0.652-4.752-2.98-4.199
c-0.443-1.354,0.142-0.868-1.171-1.483c-0.154-2.069,2.703-7.729-2.239-8.185
c2.009-3.137-6.201-0.985-6.627-3.125c-0.14-0.703-5.574,1.563-5.752,0.192
c-0.39-2.987-4.411-2.185-5.371-3.372c0.518,0.641-6.067,1.078-5.645,0.85
c-0.118,0.063-1.38,5.328-1.307,4.994c-0.457,2.076,3.774,9.01,2.893,9.625
c-0.495,0.347-3.159,6.972-1.295,8.588c-0.59-0.512,2.894-0.209,3.163-0.129
c1.333,0.396,3.091,1.66,3.469,3.176c0.52,2.486-0.793,2.359-2.357,3.013
c-0.658,0.274-2.289,6.779-2.368,7.461c-0.319,2.747-1.413,4.468-1.264,7.483
c0.098,1.984-0.368,2.326,0.891,4.287c1.933,3.004,2.018,2.57,2.178,5.813
c-0.127,1.556-1.742,3.565-1.568,5.388c0.074,0.77,0.485,2.028,0.235,2.795
c-0.286,0.875-1.936,1.557-1.573,2.627c3.253-2.051,4.522,3.092,8.168,2.83
c0.958-0.069,3.996,1.508,4.536,1.938c1.437,1.12,2.39-1.618,3.232-1.618
c-1.037,0,3.461,2.315,2.95,1.774c0.828,0.873,3.852-0.123,5.026,0.304
c2.416,0.881,6.011-1.386,7.227-2.174c1.616-1.048,3.15-1.38,4.396-2.816
c0.639-0.737,2.375-4.448,3.254-4.366c0.354,0.032,0.59,1.01,1.06,0.652
c0.163-0.126-1.075-2.664,0.689-2.664c0.935,0,4.283-2.113,3.799-3.344
c-1.384-3.521,4.799-1.365,6.683-1.926c0.335-0.1,7.816-8.23,7.865-8.641';


$matches = explode('c', $str);

$temp = array();
foreach ($matches as $k => $v) {
    // get the new relative point
    $s = $v;

    // a really dummy regex to find the last pair
    preg_match('/(-?\d{1,2}\.?\d{0,3}),?(-?\d{1,2}\.?\d{0,3}),?(-?\d{1,2}\.?\d{0,3}),?(-?\d{1,2}\.?\d{0,3}),?(-?\d{1,2}\.?\d{0,3}),?(-?\d{1,2}\.?\d{0,3}),?/', $s, $m);


    // if the array is not empty
    if (!empty($temp)) {
        $m[5] = $temp[0]+$m[5];
        $m[6] = $temp[1]+$m[6];
    }

    echo '[', ($m[5]), ', ', ($m[6]), '],<br />';

    // save the last point
    $temp = array($m[5], $m[6]);
}
</pre>
<h2>Final Adjustments</h2>
<p>I guess you don&#8217;t need any shape in the World&#8217;s center as you may not need it in the same scale. There are two things to do. First you can scale the map by multiplying by a factor every point:</p>
<pre lang="php">
// a really dummy regex to find the last pair
    preg_match('/(-?\d{1,2}\.?\d{0,3}),?(-?\d{1,2}\.?\d{0,3}),?(-?\d{1,2}\.?\d{0,3}),?(-?\d{1,2}\.?\d{0,3}),?(-?\d{1,2}\.?\d{0,3}),?(-?\d{1,2}\.?\d{0,3}),?/', $s, $m);

    // multiply by some factor
    $m[5] *= 0.05;
    $m[6] *= -0.05;

    // if the array is not empty
    if (!empty($temp)) {
        $m[5] = $temp[0]+$m[5];
        $m[6] = $temp[1]+$m[6];
    }
</pre>
<p>and than you can move the shape all over the world by adding some offset to the resulting point:</p>
<pre lang="php">
echo '[', ($m[5]-38.9), ', ', ($m[6]+10.7), '],<br />';
</pre>
<h2>Further Researches</h2>
<p>Here we just substitute the curves with lines, which is the most primitive approach. What about substituting each curve with corresponding two lines, or three lines. The resulting shape will be far more accurate in compare with the source &#8220;curved&#8221; shape. So there are still lots of things to be done. However this may help you do the job.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/04/14/you-should-not-insert-an-tag-in-another-tag-ie-breaks/" rel="bookmark" title="You should not insert an &#8220;a&#8221; tag in another &#8220;a&#8221; tag! &#8230;">You should not insert an &#8220;a&#8221; tag in another &#8220;a&#8221; tag! &#8230; </a></li>
<li><a href="/2012/01/30/computer-algorithms-data-compression-with-relative-encoding/" rel="bookmark" title="Computer Algorithms: Data Compression with Relative Encoding">Computer Algorithms: Data Compression with Relative Encoding </a></li>
<li><a href="/2011/03/29/scroll-an-iframe-content-to-a-predefined-position/" rel="bookmark" title="Scroll an IFRAME Content to a Predefined Position">Scroll an IFRAME Content to a Predefined Position </a></li>
<li><a href="/2011/02/25/how-to-collect-the-images-and-meta-tags-from-a-webpage-with-php/" rel="bookmark" title="How to Collect the Images and Meta Tags from a Webpage with PHP">How to Collect the Images and Meta Tags from a Webpage with PHP </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/02/11/from-svg-to-geo-coordinates-a-complete-guide/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Wanted &#8211; onfocus/onblur. Why They Don&#8217;t Work Always!</title>
		<link>/2011/02/09/wanted-onfocusonblur-why-they-dont-work-always/</link>
		<comments>/2011/02/09/wanted-onfocusonblur-why-they-dont-work-always/#respond</comments>
		<pubDate>Wed, 09 Feb 2011 14:11:48 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[DOM events]]></category>
		<category><![CDATA[Focus]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[Markup languages]]></category>
		<category><![CDATA[Tag soup]]></category>
		<category><![CDATA[Technical communication]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[World Wide Web]]></category>

		<guid isPermaLink="false">/?p=2160</guid>
		<description><![CDATA[On Focus Perhaps you think of onfocus and onblur events as a default behavior existing in any web page. This is not quite true! Onfocurs and onblur are well known in web developing (js) and are fired, of course, when the user tries to point something or leaves some element. Onfocurs is fired when the &#8230; <a href="/2011/02/09/wanted-onfocusonblur-why-they-dont-work-always/" class="more-link">Continue reading <span class="screen-reader-text">Wanted &#8211; onfocus/onblur. Why They Don&#8217;t Work Always!</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/04/20/how-to-sanitize-user-input-in-php/" rel="bookmark" title="How to Sanitize User Input in PHP?">How to Sanitize User Input in PHP? </a></li>
<li><a href="/2009/12/30/jquery-live-vs-bind-performance/" rel="bookmark" title="jQuery live() vs bind() performance">jQuery live() vs bind() performance </a></li>
<li><a href="/2010/09/24/2xjquery-select-a-selector/" rel="bookmark" title="2xjQuery: Select a Selector">2xjQuery: Select a Selector </a></li>
<li><a href="/2010/01/20/google-closure-compiler-doesnt-work/" rel="bookmark" title="Google Closure Compiler doesn&#8217;t work?!">Google Closure Compiler doesn&#8217;t work?! </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>On Focus</h2>
<p><a href="/wp-content/uploads/2011/02/onfocus.jpg"><img class="alignleft size-full wp-image-2177" title="onfocus" src="/wp-content/uploads/2011/02/onfocus.jpg" alt="onfocus" width="450" height="253" srcset="/wp-content/uploads/2011/02/onfocus.jpg 450w, /wp-content/uploads/2011/02/onfocus-300x168.jpg 300w" sizes="(max-width: 450px) 100vw, 450px" /></a></p>
<p>Perhaps you think of onfocus and onblur events as a default behavior existing in any web page. This is not quite true! Onfocurs and onblur are well known in web developing (js) and are fired, of course, when the user tries to point something or leaves some element. Onfocurs is fired when the user either goes to an element with the Tab button on with the mouse. When the element is on focus, evidently, the onfocus event is fired. Actually you can see which element is on focus, like an anchor or input, when the element is outlined by the browser by default. In the same scenario, when some element has been on focus and than the user switches to another element, the onblur event is fired. Thus you may guess that this element is no longer on focus.<span id="more-2160"></span></p>
<p>This in general are the onfocus/onblur events. The interesting part is that by default are known as built-in events in every page, but that is wrong.</p>
<h2>Where Are My Events?</h2>
<p>A typical use case is to take the code from some web page, where you&#8217;re sure this works perfectly, you can focus and blur element with no obstacle, but once you paste it inside your markup everything&#8217;s going wrong. Imagine you&#8217;ve the following markup (a typical search box text):</p>
<pre lang="html4strict">
<input type="text" onblur="if(this.value=='') this.value = 'Search in This Site';" onfocus="if(this.value=='Search in This Site') this.value = '';" />
</pre>
<p>This works perfectly until you paste it to your site. And than nothing works correctly. Why? Where&#8217;s the problem?</p>
<h2>Make Them Work</h2>
<p>Actually the problem isn&#8217;t hiding somewhere in the markup above. It&#8217;s in the HTML definition. There are lots of web pages using strict HTML definition, that looks like this:</p>
<pre lang="html4strict">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	...
</head>
<body>
	...
</pre>
<p>while you&#8217;ve to use the pure HTML definition to make onfocus/onblur work.</p>
<p>You&#8217;ve to switch to:</p>
<pre lang="html4strict">
<html>
<head>
	...
</head>
<body>
	...
</pre>
<p>Than you can continue using these useful events!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/04/20/how-to-sanitize-user-input-in-php/" rel="bookmark" title="How to Sanitize User Input in PHP?">How to Sanitize User Input in PHP? </a></li>
<li><a href="/2009/12/30/jquery-live-vs-bind-performance/" rel="bookmark" title="jQuery live() vs bind() performance">jQuery live() vs bind() performance </a></li>
<li><a href="/2010/09/24/2xjquery-select-a-selector/" rel="bookmark" title="2xjQuery: Select a Selector">2xjQuery: Select a Selector </a></li>
<li><a href="/2010/01/20/google-closure-compiler-doesnt-work/" rel="bookmark" title="Google Closure Compiler doesn&#8217;t work?!">Google Closure Compiler doesn&#8217;t work?! </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/02/09/wanted-onfocusonblur-why-they-dont-work-always/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reading GPS Latitude and Longitude from Image and Video Files</title>
		<link>/2011/02/04/reading-gps-latitude-and-longitude-from-image-and-video-files/</link>
		<comments>/2011/02/04/reading-gps-latitude-and-longitude-from-image-and-video-files/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 10:16:14 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Apple Inc.]]></category>
		<category><![CDATA[Application software]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Container formats]]></category>
		<category><![CDATA[Digital photography]]></category>
		<category><![CDATA[Exchangeable image file format]]></category>
		<category><![CDATA[ExifTool]]></category>
		<category><![CDATA[Geotagging]]></category>
		<category><![CDATA[GPS]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[jpeg]]></category>
		<category><![CDATA[Metadata]]></category>
		<category><![CDATA[mobile device]]></category>
		<category><![CDATA[Mobile Devices]]></category>
		<category><![CDATA[MPEG-4]]></category>
		<category><![CDATA[navigation software]]></category>
		<category><![CDATA[Nokia E71 Smartphone]]></category>
		<category><![CDATA[QuickTime]]></category>
		<category><![CDATA[Resolution Unit]]></category>
		<category><![CDATA[Smartphones]]></category>
		<category><![CDATA[Symbian]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[web platform]]></category>

		<guid isPermaLink="false">/?p=2153</guid>
		<description><![CDATA[The State of GPS Data from Mobile Devices Most of the mobile devices today support GPS geo tagging. In fact most of them come bundled with navigation software that uses GPS and therefore all the pictures and (maybe) videos can be geo tagged. But as expected different vendors come with different support and formats. iPhone &#8230; <a href="/2011/02/04/reading-gps-latitude-and-longitude-from-image-and-video-files/" class="more-link">Continue reading <span class="screen-reader-text">Reading GPS Latitude and Longitude from Image and Video Files</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/01/27/few-thoughts-on-web-video/" rel="bookmark" title="Few Thoughts on Web Video">Few Thoughts on Web Video </a></li>
<li><a href="/2010/03/05/video-sites-must-use-mp4-and-only-mp4/" rel="bookmark" title="Video sites must use &#8230; mp4 and only mp4!">Video sites must use &#8230; mp4 and only mp4! </a></li>
<li><a href="/2010/05/25/download-files-with-zend-framework/" rel="bookmark" title="Download Files with Zend Framework">Download Files with Zend Framework </a></li>
<li><a href="/2010/05/21/check-youtube-video-existence-with-zend_gdata_youtube/" rel="bookmark" title="Check YouTube Video Existence with Zend_Gdata_YouTube">Check YouTube Video Existence with Zend_Gdata_YouTube </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>The State of GPS Data from Mobile Devices</h2>
<p>Most of the mobile devices today support GPS geo tagging. In fact most of them come bundled with navigation software that uses GPS and therefore all the pictures and (maybe) videos can be geo tagged. But as expected different vendors come with different support and formats.<br />
<br clear="all" /><a href="/wp-content/uploads/2011/02/iphone.png"><img class="alignleft size-full wp-image-2162" title="iphone" src="/wp-content/uploads/2011/02/iphone.png" alt="" width="120" height="78" /></a><br />
<br clear="all" /></p>
<p><a title="iPhone OS" href="http://en.wikipedia.org/wiki/IOS_%28Apple%29" target="_blank">iPhone OS</a> comes with geotagging both on video and image files, while the latest <a title="Android" href="http://www.android.com/" target="_blank">Android</a> and <a title="Symbian" href="http://blog.symbian.org/" target="_blank">Symbian</a> (the Nokia main OS for smartphones) can geo tag only images.</p>
<p>Even more &#8211; until recently Symbian didn&#8217;t support any geotagging before the installation of an additional software &#8211; such as <a title="Location Tagger" href="http://betalabs.nokia.com/apps/location-tagger" target="_blank">Location Tagger</a> . So generally the things are quite simple:</p>
<ol>
<li>iPhone OS geotags both video and image files;</li>
<li>Android geotags only images;</li>
<li>Symbian geotags only images &#8211; and on some devices this is possible only after installing a software;</li>
</ol>
<p>This is in breve the state of mobile device geotagging!<span id="more-2153"></span></p>
<h2>Why Use GPS Data?</h2>
<p>Perhaps one of the main reasons why not support geotagging especially on video files can be the usage of those geo tags. First of all what a geotag means?<br />
<br clear="all" /><br />
<a href="/wp-content/uploads/2011/02/android.png"><img class="alignleft size-full wp-image-2165" title="android" src="/wp-content/uploads/2011/02/android.png" alt="Android Logo" width="150" height="150" /></a><br />
<br clear="all" /><br />
You may know that even Android doesn&#8217;t &#8220;geotag&#8221; videos this is not quite true. Because after using you gallery you can see where those videos are shot. This is fantastic, but actually the real information about where the video has been taken is not into the video file, but it&#8217;s in an additional log file that keeps it. Thus actually the video files doesn&#8217;t know the geo coordinates.</p>
<p>Here comes the problem with video format, because you cannot be sure that every format supports tags that can keep geo coordinates. Actually quicktime&#8217;s MOV can store them, while Symbian&#8217;s 3GP cannot. In fact Symbian cannot store any geo information about video files!</p>
<p>So now we&#8217;ve at least three different formats for each of those three vendors.</p>
<ol>
<li>quicktime for iPhone</li>
<li>mpeg-4 with Android</li>
<li>3gp with Symbian</li>
</ol>
<p>For now I can only say that iPhone can keep the geotag into his video files.<br />
<br clear="all" /><br />
<a href="/wp-content/uploads/2011/02/symbian.png"><img class="alignleft size-full wp-image-2164" title="symbian" src="/wp-content/uploads/2011/02/symbian.png" alt="Symbian Logo" width="200" height="55" /></a><br />
<br clear="all" /><br />
But let me return to the question &#8211; why we need this geo tags? Until the video file is on the mobile device &#8211; there&#8217;s no problem. But once you try to download it &#8211; whether on <a title="Flickr" href="http://www.flickr.com/" target="_blank">Flickr</a>, <a title="YouTube" href="http://youtube.com/" target="_blank">YouTube</a>, <a title="Picasa Web Albums" href="https://picasaweb.google.com/" target="_blank">Picasa</a>, etc. you&#8217;ll lose any geo information if it&#8217;s not into the file tags. And of course if the above sites can&#8217;t read it!</p>
<p>The general reason to store this data into the file is to move it along with the file. Once you move this file from your mobile device to a web platform you&#8217;ll see where the file has been created.</p>
<h2>EXIF, Exiftool and PHP&#8217;s exif_read_data</h2>
<p>There are several tools to read geotags. For images, and here we talk only for JPEGs, this is the <a title="EXIF" href="http://www.exif.org/" target="_blank">EXIF</a> information. You can download the exif command line program and try to reed data with it:</p>
<pre lang="bash">
exif filename.jpg
</pre>
<p>Which can result in something like that:</p>
<pre lang="bash">
Manufacturer        |Nokia                                                     
Model               |E71                                                       
Orientation         |top - left                                                
x-Resolution        |300.00                                                    
y-Resolution        |300.00                                                    
Resolution Unit     |Inch                                                      
YCbCr Positioning   |centered                                                  
Compression         |JPEG compression                                          
x-Resolution        |72.00                                                     
y-Resolution        |72.00                                                     
Resolution Unit     |Inch                                                      
FNumber             |f/3.2                                                     
Exif Version        |Exif Version 2.2                                          
Date and Time (origi|2011:01:24 12:15:01                                       
Date and Time (digit|2011:01:24 12:15:01                                       
ComponentsConfigurat|Y Cb Cr -                                                 
Aperture            |3.20 EV (f/3.0)                                           
Light Source        |0                                                         
Flash               |Flash did not fire, auto mode.                            
Focal Length        |4.9 mm                                                    
FlashPixVersion     |FlashPix Version 1.0                                      
Color Space         |sRGB                                                      
PixelXDimension     |2048                                                      
PixelYDimension     |1536                                                      
Custom Rendered     |Normal process                                            
Exposure Mode       |Auto exposure                                             
White Balance       |Auto white balance                                        
Digital Zoom Ratio  |1.00                                                      
Scene Capture Type  |Standard                                                  
GPS tag version     |0x02, 0x02, 0x00, 0x00                                    
North or South Latit|N                                                         
Latitude            |42.00, 39.00, 24.67                                       
East or West Longitu|E                                                         
Longitude           |23.00, 21.00, 28.45                                       
Altitude reference  |0x00                                                      
Altitude            |625.50 
</pre>
<p>While for video files (iPhone) exif cannot help you, this is possible through <a title="Exiftool" href="http://www.sno.phy.queensu.ca/~phil/exiftool/" target="_blank">Exiftool</a>. With it you can read even iPhone video geotags:</p>
<pre lang="bash">
./exiftool filname.mov
</pre>
<p>In addition this information can be read with PHP via <a title="read_exif_data" href="http://php.net/manual/en/function.read-exif-data.php" target="_blank">exif_read_data</a>:</p>
<pre lang="php">
$info = exif_read_data('filename.jpg');
var_dump($info);
</pre>
<p>And this will give you not only standard tags, but geo tags too.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/01/27/few-thoughts-on-web-video/" rel="bookmark" title="Few Thoughts on Web Video">Few Thoughts on Web Video </a></li>
<li><a href="/2010/03/05/video-sites-must-use-mp4-and-only-mp4/" rel="bookmark" title="Video sites must use &#8230; mp4 and only mp4!">Video sites must use &#8230; mp4 and only mp4! </a></li>
<li><a href="/2010/05/25/download-files-with-zend-framework/" rel="bookmark" title="Download Files with Zend Framework">Download Files with Zend Framework </a></li>
<li><a href="/2010/05/21/check-youtube-video-existence-with-zend_gdata_youtube/" rel="bookmark" title="Check YouTube Video Existence with Zend_Gdata_YouTube">Check YouTube Video Existence with Zend_Gdata_YouTube </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/02/04/reading-gps-latitude-and-longitude-from-image-and-video-files/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
