<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>code journal</title>
	<atom:link href="http://codejournal.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://codejournal.wordpress.com</link>
	<description></description>
	<lastBuildDate>Sat, 04 May 2013 07:04:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='codejournal.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>code journal</title>
		<link>http://codejournal.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://codejournal.wordpress.com/osd.xml" title="code journal" />
	<atom:link rel='hub' href='http://codejournal.wordpress.com/?pushpress=hub'/>
		<item>
		<title>2012 in review</title>
		<link>http://codejournal.wordpress.com/2012/12/31/2012-in-review/</link>
		<comments>http://codejournal.wordpress.com/2012/12/31/2012-in-review/#comments</comments>
		<pubDate>Mon, 31 Dec 2012 15:01:40 +0000</pubDate>
		<dc:creator>unknowncoder</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://codejournal.wordpress.com/?p=177</guid>
		<description><![CDATA[The WordPress.com stats helper monkeys prepared a 2012 annual report for this blog. Here&#8217;s an excerpt: 600 people reached the top of Mt. Everest in 2012. This blog got about [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codejournal.wordpress.com&#038;blog=30783452&#038;post=177&#038;subd=codejournal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>The WordPress.com stats helper monkeys prepared a 2012 annual report for this blog.</p>
<p><a href="http://codejournal.wordpress.com/2012/annual-report/"><img alt="" src="http://www.wordpress.com/wp-content/mu-plugins/annual-reports/img/2012-emailteaser.png" width="100%" /></a></p>
<p>Here&#8217;s an excerpt:</p>
<blockquote><p>600 people reached the top of Mt. Everest in 2012. This blog got about <strong>6,000</strong> views in 2012. If every person who reached the top of Mt. Everest viewed this blog, it would have taken 10 years to get that many views.</p></blockquote>
<p><a href="http://codejournal.wordpress.com/2012/annual-report/">Click here to see the complete report.</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codejournal.wordpress.com/177/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codejournal.wordpress.com/177/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codejournal.wordpress.com&#038;blog=30783452&#038;post=177&#038;subd=codejournal&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codejournal.wordpress.com/2012/12/31/2012-in-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/56b533eab201715740dca59e3ddbf4b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">praneetloke</media:title>
		</media:content>

		<media:content url="http://www.wordpress.com/wp-content/mu-plugins/annual-reports/img/2012-emailteaser.png" medium="image" />
	</item>
		<item>
		<title>left-right</title>
		<link>http://codejournal.wordpress.com/2012/10/12/left-right/</link>
		<comments>http://codejournal.wordpress.com/2012/10/12/left-right/#comments</comments>
		<pubDate>Fri, 12 Oct 2012 17:26:38 +0000</pubDate>
		<dc:creator>unknowncoder</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Zepto]]></category>
		<category><![CDATA[horizontal scrolling]]></category>
		<category><![CDATA[jquery horizontal scroll]]></category>
		<category><![CDATA[zepto horizontal scroll]]></category>
		<category><![CDATA[horizontal scroller]]></category>
		<category><![CDATA[side scroll]]></category>
		<category><![CDATA[side scroller]]></category>
		<category><![CDATA[pure js side scroller]]></category>
		<category><![CDATA[pure js horizontal scroller]]></category>

		<guid isPermaLink="false">http://codejournal.wordpress.com/?p=173</guid>
		<description><![CDATA[I created a new public repo on my GitHub page. Check it out.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codejournal.wordpress.com&#038;blog=30783452&#038;post=173&#038;subd=codejournal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I created a new public repo on my GitHub page. <a title="left-righ on GitHub" href="http://praneetloke.github.com/left-right/" target="_blank">Check it out</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codejournal.wordpress.com/173/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codejournal.wordpress.com/173/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codejournal.wordpress.com&#038;blog=30783452&#038;post=173&#038;subd=codejournal&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codejournal.wordpress.com/2012/10/12/left-right/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/56b533eab201715740dca59e3ddbf4b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">praneetloke</media:title>
		</media:content>
	</item>
		<item>
		<title>UTC Offset regex validation</title>
		<link>http://codejournal.wordpress.com/2012/08/29/utc-offset-regex-validation/</link>
		<comments>http://codejournal.wordpress.com/2012/08/29/utc-offset-regex-validation/#comments</comments>
		<pubDate>Wed, 29 Aug 2012 23:27:21 +0000</pubDate>
		<dc:creator>unknowncoder</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[date regex]]></category>
		<category><![CDATA[javascript date validation for utc]]></category>
		<category><![CDATA[javascript regex]]></category>
		<category><![CDATA[javascript utc offset negative]]></category>
		<category><![CDATA[javascript utc offset negative validate]]></category>
		<category><![CDATA[javascript utc offset negative validation]]></category>
		<category><![CDATA[javascript utc offset positive]]></category>
		<category><![CDATA[javascript utc offset positive validate]]></category>
		<category><![CDATA[javascript utc offset positive validation]]></category>
		<category><![CDATA[offset]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regex utc offset]]></category>
		<category><![CDATA[using javascript to validate utc offset]]></category>
		<category><![CDATA[utc]]></category>
		<category><![CDATA[utc date validation]]></category>
		<category><![CDATA[utc offset regex]]></category>
		<category><![CDATA[utc offset validation]]></category>
		<category><![CDATA[utc time validation]]></category>

		<guid isPermaLink="false">http://codejournal.wordpress.com/?p=151</guid>
		<description><![CDATA[I was working on validating UTC Offset values in a javascript application and came up with this regex to do the job. What do you think? //see http://en.wikipedia.org/wiki/List_of_UTC_time_offsets for list [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codejournal.wordpress.com&#038;blog=30783452&#038;post=151&#038;subd=codejournal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I was working on validating <a class="zem_slink" title="UTC offset" href="http://en.wikipedia.org/wiki/UTC_offset" rel="wikipedia" target="_blank">UTC Offset</a> values in a javascript application and came up with this <a class="zem_slink" title="Regular expression" href="http://en.wikipedia.org/wiki/Regular_expression" rel="wikipedia" target="_blank">regex</a> to do the job. What do you think?</p>
<blockquote><p>//see <a href="http://en.wikipedia.org/wiki/List_of_UTC_time_offsets" rel="nofollow">http://en.wikipedia.org/wiki/List_of_UTC_time_offsets</a> for list of valid positive and negative offsets<br />
var positiveOffset = /^[+]?([0-9]\.?[0]?[0]?|1[0-4]\.?[0]?[0]?|[3,4,5,6,9,10,11]\.30|[5,8]\.45|12\.45)$/g;<br />
var negativeOffset = /^[-]([0-9]\.?[0]?[0]?|1[0-2]\.?[0]?[0]?|[3,4,9]\.30)$/g;<br />
var <a class="zem_slink" title="Greenwich Mean Time" href="http://en.wikipedia.org/wiki/Greenwich_Mean_Time" rel="wikipedia" target="_blank">GMT</a> = /^0\.?[0]?[0]?$/g;<br />
if(!positiveOffset.test(value) &amp;&amp; !negativeOffset.test(data.value) &amp;&amp; !GMT.test(value)) {<br />
//show error<br />
}</p></blockquote>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codejournal.wordpress.com/151/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codejournal.wordpress.com/151/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codejournal.wordpress.com&#038;blog=30783452&#038;post=151&#038;subd=codejournal&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codejournal.wordpress.com/2012/08/29/utc-offset-regex-validation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/56b533eab201715740dca59e3ddbf4b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">praneetloke</media:title>
		</media:content>
	</item>
		<item>
		<title>Closure function vs defined (named) function</title>
		<link>http://codejournal.wordpress.com/2012/08/21/closure-function-vs-defined-named-function/</link>
		<comments>http://codejournal.wordpress.com/2012/08/21/closure-function-vs-defined-named-function/#comments</comments>
		<pubDate>Tue, 21 Aug 2012 23:01:46 +0000</pubDate>
		<dc:creator>unknowncoder</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[closure function in loop]]></category>
		<category><![CDATA[closure function performance]]></category>
		<category><![CDATA[closure function poor performance]]></category>
		<category><![CDATA[closure function vs named function]]></category>
		<category><![CDATA[for loop optimization]]></category>
		<category><![CDATA[functions in for loop]]></category>
		<category><![CDATA[functions in for loop performance]]></category>
		<category><![CDATA[functions performance in loop]]></category>
		<category><![CDATA[js function performance]]></category>
		<category><![CDATA[named function in loop]]></category>
		<category><![CDATA[named function performance]]></category>

		<guid isPermaLink="false">http://codejournal.wordpress.com/?p=149</guid>
		<description><![CDATA[I wrote a performance test on jsperf.com to measure the difference between calling a closure function from within a loop and calling a defined function within another loop for the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codejournal.wordpress.com&#038;blog=30783452&#038;post=149&#038;subd=codejournal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I wrote a performance test on jsperf.com to measure the difference between calling a closure function from within a loop and calling a defined function within another loop for the same number of iterations. <a title="jsPerf" href="http://jsperf.com/closure-vs-name-function-in-a-loop" target="_blank">See the difference</a> and run the test yourself.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codejournal.wordpress.com/149/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codejournal.wordpress.com/149/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codejournal.wordpress.com&#038;blog=30783452&#038;post=149&#038;subd=codejournal&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codejournal.wordpress.com/2012/08/21/closure-function-vs-defined-named-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/56b533eab201715740dca59e3ddbf4b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">praneetloke</media:title>
		</media:content>
	</item>
		<item>
		<title>PHP file download</title>
		<link>http://codejournal.wordpress.com/2012/08/19/php-file-download/</link>
		<comments>http://codejournal.wordpress.com/2012/08/19/php-file-download/#comments</comments>
		<pubDate>Sun, 19 Aug 2012 14:27:14 +0000</pubDate>
		<dc:creator>unknowncoder</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[database file download]]></category>
		<category><![CDATA[download file using php]]></category>
		<category><![CDATA[download pdf using php]]></category>
		<category><![CDATA[download using php]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php corrupt file]]></category>
		<category><![CDATA[php corrupted file]]></category>
		<category><![CDATA[php corrupted file download]]></category>
		<category><![CDATA[php database file upload]]></category>
		<category><![CDATA[php download]]></category>
		<category><![CDATA[php download corrupt]]></category>
		<category><![CDATA[php download script]]></category>
		<category><![CDATA[php file download]]></category>
		<category><![CDATA[php uploaded file corrupt]]></category>
		<category><![CDATA[php5]]></category>

		<guid isPermaLink="false">http://codejournal.wordpress.com/?p=136</guid>
		<description><![CDATA[So I have been working on a PHP website for a freelance job and had to write few lines of code to download a file from the database. Very simple [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codejournal.wordpress.com&#038;blog=30783452&#038;post=136&#038;subd=codejournal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>So I have been working on a PHP website for a freelance job and had to write few lines of code to download a file from the database. Very simple right? Yeah that&#8217;s what I thought too. I mean it was &lt; than 20 lines of code. Why wouldn&#8217;t it work? What could go wrong? That&#8217;s where I was wrong. This is what I had at first:</p>
<blockquote><p>if(isset($_GET['id']))<br />
{<br />
// if id is set then get the file with the id from database<br />
$id = $_GET['id'];<br />
$application = new Applications();<br />
$application-&gt;get($id);<br />
header(&#8220;Content-length: $application-&gt;size&#8221;);<br />
header(&#8220;Content-type: $application-&gt;type&#8221;);<br />
header(&#8220;Content-Disposition: attachment; filename=$application-&gt;name&#8221;);<br />
$content = $application-&gt;data;<br />
echo $content;<br />
}<br />
exit;</p></blockquote>
<p>The problem I experienced was that a file would upload (different piece of code) fine. I knew that because the size attributes match when the file is written to the db. When I actually try to download the file back from the db using the script above, the file gets corrupted. I had no idea why! The weird (but made sense later) part was that plaintext files were fine no matter how large they were. It was binary files like images, DOCs, PDFs etc. So, I scoured the internet searching for answers and finally came across one thread somewhere where there was a similar discussion from over a year ago and someone said that the file stream would get random whitespace characters when downloading the file. Then it hit me, I remember seeing whitespace at the beginning of the stream when I had opened the corrupt file using notepad. The solution was to ob_clean() before you begin writing the headers and the content stream itself. <strong>You see one of the important points about writing header information to the client is that there shouldn&#8217;t be any whitespace before writing headers.</strong></p>
<p>I modified the above code then to this:</p>
<blockquote><p>if(isset($_GET['id']))<br />
{<br />
// if id is set then get the file with the id from database<br />
$id = $_GET['id'];<br />
$application = new Applications();<br />
$application-&gt;get($id);<br />
ob_clean(); //clears output buffer in php..see php manual<br />
header(&#8220;Content-length: $application-&gt;size&#8221;);<br />
header(&#8220;Content-type: $application-&gt;type&#8221;);<br />
header(&#8220;Content-Disposition: attachment; filename=$application-&gt;name&#8221;);<br />
$content = $application-&gt;data;<br />
echo $content;<br />
}<br />
exit;</p></blockquote>
<p>It would then download without any problems. At this time I should also caution you about dangling newline/whitespace in the php file itself which handles the download. The reason why plaintext files were ok is because plaintext files are not written in binary so whitespace or not it doesn&#8217;t matter for those file types and they will upload/download fine, at least in my case they did. Do you have a better way to handle this? If so, please leave a comment. Let me know about it.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codejournal.wordpress.com/136/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codejournal.wordpress.com/136/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codejournal.wordpress.com&#038;blog=30783452&#038;post=136&#038;subd=codejournal&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codejournal.wordpress.com/2012/08/19/php-file-download/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/56b533eab201715740dca59e3ddbf4b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">praneetloke</media:title>
		</media:content>
	</item>
		<item>
		<title>canvas-charts</title>
		<link>http://codejournal.wordpress.com/2012/07/30/canvas-charts/</link>
		<comments>http://codejournal.wordpress.com/2012/07/30/canvas-charts/#comments</comments>
		<pubDate>Mon, 30 Jul 2012 21:10:19 +0000</pubDate>
		<dc:creator>unknowncoder</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[canvas based graphs]]></category>
		<category><![CDATA[canvas graphs]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[graph using canvas]]></category>
		<category><![CDATA[graph using html5]]></category>
		<category><![CDATA[graph using html5 canvas]]></category>
		<category><![CDATA[graphs]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[html5 canvas]]></category>
		<category><![CDATA[html5 canvas graph]]></category>
		<category><![CDATA[html5 graphs]]></category>

		<guid isPermaLink="false">http://codejournal.wordpress.com/?p=131</guid>
		<description><![CDATA[I just committed my first open source project on GitHub. You check it out here. Here&#8217;s the example client with graphs: &#160;<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codejournal.wordpress.com&#038;blog=30783452&#038;post=131&#038;subd=codejournal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I just committed my first open source project on GitHub. You check it out <a title="canvas-charts" href="https://github.com/praneetloke/canvas-charts" target="_blank">here</a>.</p>
<p>Here&#8217;s the example client with graphs:</p>
<p><a href="http://codejournal.files.wordpress.com/2012/07/screen-shot-2012-07-30-at-5-07-56-pm.png"><img class="aligncenter size-medium wp-image-132" title="Horizontal Bar Graph" src="http://codejournal.files.wordpress.com/2012/07/screen-shot-2012-07-30-at-5-07-56-pm.png?w=272&#038;h=300" alt="Horizontal Bar Graph" width="272" height="300" /></a></p>
<p>&nbsp;</p>
<p><a href="http://codejournal.files.wordpress.com/2012/07/screen-shot-2012-07-30-at-5-08-08-pm.png"><img class="aligncenter size-medium wp-image-133" title="Line graph" src="http://codejournal.files.wordpress.com/2012/07/screen-shot-2012-07-30-at-5-08-08-pm.png?w=209&#038;h=300" alt="Line graph" width="209" height="300" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codejournal.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codejournal.wordpress.com/131/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codejournal.wordpress.com&#038;blog=30783452&#038;post=131&#038;subd=codejournal&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codejournal.wordpress.com/2012/07/30/canvas-charts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/56b533eab201715740dca59e3ddbf4b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">praneetloke</media:title>
		</media:content>

		<media:content url="http://codejournal.files.wordpress.com/2012/07/screen-shot-2012-07-30-at-5-07-56-pm.png?w=272" medium="image">
			<media:title type="html">Horizontal Bar Graph</media:title>
		</media:content>

		<media:content url="http://codejournal.files.wordpress.com/2012/07/screen-shot-2012-07-30-at-5-08-08-pm.png?w=209" medium="image">
			<media:title type="html">Line graph</media:title>
		</media:content>
	</item>
		<item>
		<title>iOS 5 Style Switch Control</title>
		<link>http://codejournal.wordpress.com/2012/07/24/127/</link>
		<comments>http://codejournal.wordpress.com/2012/07/24/127/#comments</comments>
		<pubDate>Tue, 24 Jul 2012 15:02:15 +0000</pubDate>
		<dc:creator>unknowncoder</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://codejournal.wordpress.com/2012/07/24/127/</guid>
		<description><![CDATA[Reblogged from CSS3 Wizardry: Recreating the iOS 5 Switch Control with HTML5, CSS3 and a Bit of ECMAScript 5 The final result of this post will run in iOS 5, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codejournal.wordpress.com&#038;blog=30783452&#038;post=127&#038;subd=codejournal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<div class="reblog-post"><p class="reblog-from"><img alt='' src='http://0.gravatar.com/avatar/ffb83ba02d9d0309796a19bb0b3bbe54?s=25&amp;d=identicon&amp;r=G' class='avatar avatar-25' height='25' width='25' /> <a href="http://css3wizardry.com/2011/12/18/ios-5-style-switch-control/">Reblogged from CSS3 Wizardry:</a></p><div class="wpcom-enhanced-excerpt"><div class="wpcom-enhanced-excerpt-content"><a href="http://css3wizardry.com/2011/12/18/ios-5-style-switch-control/" target="_self"><img src="http://rmbiggs.files.wordpress.com/2011/12/switch_control-1.png?w=470&h=300" alt="Click to visit the original post" class="size-full" /></a><ul class="thumb-list"><li><a href="http://css3wizardry.com/2011/12/18/ios-5-style-switch-control/" target="_self"><img src="http://rmbiggs.files.wordpress.com/2011/12/switch_control-2.png?w=72&h=72&crop=1" alt="Click to visit the original post" class="size-thumb" width="72" height="72" /></a></li><li><a href="http://css3wizardry.com/2011/12/18/ios-5-style-switch-control/" target="_self"><img src="http://rmbiggs.files.wordpress.com/2011/12/switch_control-3.png?w=72&crop=1&h=72" alt="Click to visit the original post" class="size-thumb" width="72" height="72" /></a></li><li><a href="http://css3wizardry.com/2011/12/18/ios-5-style-switch-control/" target="_self"><img src="http://rmbiggs.files.wordpress.com/2011/12/switch_control-4.png?w=72&crop=1&h=72" alt="Click to visit the original post" class="size-thumb" width="72" height="72" /></a></li><li><a href="http://css3wizardry.com/2011/12/18/ios-5-style-switch-control/" target="_self"><img src="http://rmbiggs.files.wordpress.com/2011/12/switch_control-5.png?w=72&crop=1&h=72" alt="Click to visit the original post" class="size-thumb" width="72" height="72" /></a></li><li><a href="http://css3wizardry.com/2011/12/18/ios-5-style-switch-control/" target="_self"><img src="http://rmbiggs.files.wordpress.com/2011/12/switch_control-6.png?w=72&crop=1&h=72" alt="Click to visit the original post" class="size-thumb" width="72" height="72" /></a></li><li><a href="http://css3wizardry.com/2011/12/18/ios-5-style-switch-control/" target="_self"><img src="http://rmbiggs.files.wordpress.com/2011/12/switch_control-7.png?w=72&crop=1&h=72" alt="Click to visit the original post" class="size-thumb" width="72" height="72" /></a></li><li><a href="http://css3wizardry.com/2011/12/18/ios-5-style-switch-control/" target="_self"><img src="http://rmbiggs.files.wordpress.com/2011/12/switch_control-8.png?w=72&crop=1&h=72" alt="Click to visit the original post" class="size-thumb" width="72" height="72" /></a></li><li><a href="http://css3wizardry.com/2011/12/18/ios-5-style-switch-control/" target="_self"><img src="http://rmbiggs.files.wordpress.com/2011/12/switch_control-9.png?w=72&crop=1&h=72" alt="Click to visit the original post" class="size-thumb" width="72" height="72" /></a></li><li><a href="http://css3wizardry.com/2011/12/18/ios-5-style-switch-control/" target="_self"><img src="http://rmbiggs.files.wordpress.com/2011/12/switch_control-10.png?w=72&crop=1&h=72" alt="Click to visit the original post" class="size-thumb" width="72" height="72" /></a></li></ul>
<h3>Recreating the iOS 5 Switch Control with HTML5, CSS3 and a Bit of ECMAScript 5</h3>
<p>The final result of this post will run in iOS 5, Safari 5.1, as well as the latest versions of Chrome, Firefox and Opera.</p>
<p>Previously I had created a version of the switch control in iOS. With the launch of iOS5 Apple complete updated the look of the switch control.</p>
</div> <p class="read-more"><a href="http://css3wizardry.com/2011/12/18/ios-5-style-switch-control/" target="_self"><span>Read more&hellip;</span> 1,862 more words</a></p></div></div><div class="reblogger-note"><div class='reblogger-note-content'>
Very neat!
</div></div>]]></content:encoded>
			<wfw:commentRss>http://codejournal.wordpress.com/2012/07/24/127/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/56b533eab201715740dca59e3ddbf4b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">praneetloke</media:title>
		</media:content>
	</item>
		<item>
		<title>Android NetworkOnMainThreadException</title>
		<link>http://codejournal.wordpress.com/2012/07/03/android-networkonmainthreadexception/</link>
		<comments>http://codejournal.wordpress.com/2012/07/03/android-networkonmainthreadexception/#comments</comments>
		<pubDate>Tue, 03 Jul 2012 04:17:48 +0000</pubDate>
		<dc:creator>unknowncoder</dc:creator>
				<category><![CDATA[App Development]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[android 4.0 network on main thread exception]]></category>
		<category><![CDATA[android ics network on main thread exception]]></category>
		<category><![CDATA[network on main thread exception]]></category>
		<category><![CDATA[network on main thread exception ics]]></category>
		<category><![CDATA[networkonmainthreadexception android]]></category>
		<category><![CDATA[why network on main thread exception in android 4.0]]></category>

		<guid isPermaLink="false">http://codejournal.wordpress.com/?p=121</guid>
		<description><![CDATA[Android has been lenient about network access on the main thread in prior versions and now with ICS, they are cracking down on us. It is bad practice however to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codejournal.wordpress.com&#038;blog=30783452&#038;post=121&#038;subd=codejournal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Android has been lenient about network access on the main thread in prior versions and now with ICS, they are cracking down on us.</p>
<p>It is bad practice however to have operations that are intensive and for a network operation it is even more sensitive since the network speed is a varying factor that can block the UI for an unknown amount of time. Although it is annoying to have your app crash all of a sudden in new Android versions because you (and by that I mean, I) made a bad programming mistake, it is for your own good to consider porting your network access code to an AsyncTask. Writing an AsyncTask is shit easy.</p>
<blockquote><p>private class SomeTask extends AsyncTask&lt;Void, Void, Void&gt;{</p>
<p>@Override</p>
<p>protected Void doInBackground(Void&#8230;params){</p>
<p>//your network access code goes here</p>
<p>}</p>
<p>}</p></blockquote>
<p>and then in your UI thread or main thread, just instantiate this task and execute it and you&#8217;re done. Obviously, I have simplified the AsyncTask by not going into much details about the arguments and result codes etc..You can read all about that <a title="AsyncTask" href="http://developer.android.com/reference/android/os/AsyncTask.html" target="_blank">here</a>. I can&#8217;t tell you how much I love the Android documentation. Say what you want about their fragmentation problem; I just love their documentation. Just amazing. There&#8217;s nothing you can&#8217;t find in there unlike Apple&#8217;s. I spent a whole day trying to figure out how to create those provisioning and distribution certificates and there&#8217;s not an article on the internet that ties it all together!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codejournal.wordpress.com/121/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codejournal.wordpress.com/121/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codejournal.wordpress.com&#038;blog=30783452&#038;post=121&#038;subd=codejournal&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codejournal.wordpress.com/2012/07/03/android-networkonmainthreadexception/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/56b533eab201715740dca59e3ddbf4b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">praneetloke</media:title>
		</media:content>
	</item>
		<item>
		<title>Squiggly &#8211; Android app</title>
		<link>http://codejournal.wordpress.com/2012/07/01/coming-soon/</link>
		<comments>http://codejournal.wordpress.com/2012/07/01/coming-soon/#comments</comments>
		<pubDate>Sun, 01 Jul 2012 00:35:17 +0000</pubDate>
		<dc:creator>unknowncoder</dc:creator>
				<category><![CDATA[App Development]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[android app]]></category>
		<category><![CDATA[app silences phone based on location]]></category>
		<category><![CDATA[app to silence phone based on location]]></category>
		<category><![CDATA[auto silence android phone]]></category>
		<category><![CDATA[automatically silence android phone]]></category>
		<category><![CDATA[location aware android app]]></category>
		<category><![CDATA[location sentry android]]></category>
		<category><![CDATA[silence android phone based on location type]]></category>
		<category><![CDATA[silence based on location android phone]]></category>
		<category><![CDATA[squiggly]]></category>
		<category><![CDATA[squiggly android]]></category>
		<category><![CDATA[Squiggly Android app]]></category>
		<category><![CDATA[use google calendar to silence android phone]]></category>

		<guid isPermaLink="false">http://codejournal.wordpress.com/?p=109</guid>
		<description><![CDATA[Squiggly is a calendar and location based app that can silence your phone. You know what the best part is? It knows where to silence your phone even without you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codejournal.wordpress.com&#038;blog=30783452&#038;post=109&#038;subd=codejournal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p style="text-align:center;"><a href="http://codejournal.files.wordpress.com/2012/07/device-2012-06-06-1852191.png"><img class="size-full wp-image-118 aligncenter" title="Squiggly" src="http://codejournal.files.wordpress.com/2012/07/device-2012-06-06-1852191.png?w=470" alt="Squiggly"   /></a></p>
<dl class="wp-caption aligncenter">
<dt class="wp-caption-dt"></dt>
<dd class="wp-caption-dd"></dd>
</dl>
<p>Squiggly is a calendar and <a class="zem_slink" title="Location-based service" href="http://en.wikipedia.org/wiki/Location-based_service" rel="wikipedia" target="_blank">location based</a> app that can silence your phone. You know what the best part is? It knows where to silence your phone even without you telling it. Developed by <a title="my.app.factory" href="http://myappfactory.com" target="_blank">my.app.factory</a>.</p>
<p><strong>Update: </strong>Squiggly just went live. Get it now for your <a class="zem_slink" title="android phones,best android phones,top android phones" href="http://www.t-mobile.com/shop/phones/?capcode=AGE" rel="tmobile" target="_blank">Android</a> <a title="Squiggly on Google Play" href="https://play.google.com/store/apps/details?id=com.squiggly" target="_blank">here</a>.</p>
<p><strong>Update: </strong>An updated version (1.4) with much better <a class="zem_slink" title="Location awareness" href="http://en.wikipedia.org/wiki/Location_awareness" rel="wikipedia" target="_blank">location awareness</a> and calendars functionality has been released to the Play store. Get it now! Don&#8217;t forget to look at the location types available for you to choose in Location Sentry.</p>
<p><strong>Update: </strong>v1.4.2 coming soon with local calendar access for ICS and above devices. Watch out for the update on the Play store in the next few days.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codejournal.wordpress.com/109/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codejournal.wordpress.com/109/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codejournal.wordpress.com&#038;blog=30783452&#038;post=109&#038;subd=codejournal&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codejournal.wordpress.com/2012/07/01/coming-soon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/56b533eab201715740dca59e3ddbf4b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">praneetloke</media:title>
		</media:content>

		<media:content url="http://codejournal.files.wordpress.com/2012/07/device-2012-06-06-1852191.png" medium="image">
			<media:title type="html">Squiggly</media:title>
		</media:content>
	</item>
		<item>
		<title>Simple validation of required fields in html5 mobile apps</title>
		<link>http://codejournal.wordpress.com/2012/07/01/simple-validation-of-required-fields-in-html5-mobile-apps/</link>
		<comments>http://codejournal.wordpress.com/2012/07/01/simple-validation-of-required-fields-in-html5-mobile-apps/#comments</comments>
		<pubDate>Sun, 01 Jul 2012 00:12:17 +0000</pubDate>
		<dc:creator>unknowncoder</dc:creator>
				<category><![CDATA[App Development]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[html5 required]]></category>
		<category><![CDATA[html5 required attribute]]></category>
		<category><![CDATA[html5 required validation]]></category>
		<category><![CDATA[html5 validation]]></category>
		<category><![CDATA[micro required field validation html5]]></category>
		<category><![CDATA[micro required field validation javascript]]></category>
		<category><![CDATA[micro validation script html5]]></category>

		<guid isPermaLink="false">http://codejournal.wordpress.com/?p=101</guid>
		<description><![CDATA[I am working on an html5 mobile app and wanted a simple validation of required fields. Nothing fancy. Just a simple validation that would let the user know they left [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codejournal.wordpress.com&#038;blog=30783452&#038;post=101&#038;subd=codejournal&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I am working on an html5 mobile app and wanted a simple validation of required fields. Nothing fancy. Just a simple validation that would let the user know they left something blank. Since I was not interested in checking the format of the values entered in these fields, I felt that I should create something very generic that can be reused across platforms especially by using html5 features. A micro validation script, if I may.</p>
<p>So the setup is pretty easy. You need to mark your required input tags with the <strong>required</strong> attribute. Now, remember that this is an html5 attribute, so while older browsers won&#8217;t understand this it shouldn&#8217;t break anything. The next, optional, attribute to set is the data-tab-id, which when set tells validating function that it needs to mark that tab with an indication that it contains errors. This will be useful when you have data entry in multiple tabs.</p>
<blockquote><p>&lt;input id=&#8221;name&#8221; type=&#8221;text&#8221; placeholder=&#8221;name&#8221; maxlength=&#8221;25&#8243; required=&#8221;required&#8221; data-tab-id=&#8221;#tab1&#8243;/&gt;</p></blockquote>
<p>Next is the CSS, simple, nothing extreme:</p>
<blockquote><p>input.inputrequired{<br />
border: 1px solid #ff0000;<br />
}</p>
<p>a.haserrors{<br />
color: #ff0000;<br />
font-weight: bold;<br />
}</p></blockquote>
<p>The haserrors class is for the tab. You can change the selector for this class to match whatever tag you would have used with your tabs. Again, this is optional, you do not need to set the data-tab-id in the first place, if don&#8217;t need this and you will, in a moment, see why.</p>
<p>Finally, the script:</p>
<blockquote><p>var _validateInput = function(e){<br />
var currentTarget = e.currentTarget;<br />
var tabId = currentTarget.dataset["tabId"];<br />
var tab = $(tabId);<br />
var result = false;<br />
if(currentTarget.required &amp;&amp; currentTarget.value == &#8220;&#8221; &amp;&amp; tab != null &amp;&amp; typeof tab !== &#8220;undefined&#8221;){<br />
$(&#8220;#&#8221; + currentTarget.id).css(&#8220;class&#8221;, &#8220;inputrequired&#8221;);<br />
tab.addClass(&#8220;haserrors&#8221;);<br />
}<br />
else {<br />
currentTarget.setAttribute(&#8220;class&#8221;, &#8220;&#8221;);<br />
//before removing the haserrors from the tab class check if any other siblings are in error<br />
if($(&#8220;#&#8221; + currentTarget.id).siblings(&#8220;.inputrequired&#8221;).length &lt;= 0 &amp;&amp; tab != null &amp;&amp; typeof tab !== &#8220;undefined&#8221;){<br />
tab.removeClass(&#8220;haserrors&#8221;);<br />
}<br />
//set result to true since this input is fine<br />
result = true;<br />
}<br />
tab = null;<br />
currentTarget = null;<br />
return result;<br />
};</p></blockquote>
<p>The actual event trigger:</p>
<blockquote><p>//validates onblur the inputs that have required attribute<br />
$(&#8220;input&#8221;).on(&#8220;blur&#8221;, function(e){<br />
validateInput(e);<br />
}, false);</p></blockquote>
<p>Although the required attribute is backward compatible, meaning no existing functionality would break, there is no need to worry about old browsers for mobile anyway. The <strong>data-</strong> attributes are an html5 addition as well. They won&#8217;t be recognized by older browsers and you cannot access the DOM string map dataset from an element in older browsers. And again, there is no need to worry about these things unless you are planning to use this for the desktop in which case you will need to replace the use of dataset with a JS framework&#8217;s data() method which provides cross-browser support.</p>
<p>One nice thing about the &#8220;required&#8221; attribute is that when you place fields with required attributes inside a &lt;form&gt; element, when the form is submitted, the browser automatically validates them and shows a nice tooltip that the a value is required for the element. I wrote this script because I wasn&#8217;t using a &lt;form&gt; element and don&#8217;t think the required attribute validation is supported in mobile webview at least <a title="Required attribute html5 feature availability" href="http://caniuse.com/#feat=form-validation" target="_blank">it is not widely supported</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codejournal.wordpress.com/101/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codejournal.wordpress.com/101/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codejournal.wordpress.com&#038;blog=30783452&#038;post=101&#038;subd=codejournal&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://codejournal.wordpress.com/2012/07/01/simple-validation-of-required-fields-in-html5-mobile-apps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://2.gravatar.com/avatar/56b533eab201715740dca59e3ddbf4b1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">praneetloke</media:title>
		</media:content>
	</item>
	</channel>
</rss>
