<?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>doppnet</title>
	<atom:link href="http://doppnet.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://doppnet.com</link>
	<description></description>
	<lastBuildDate>Sat, 28 Jan 2012 14:38:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Why can&#8217;t all software be like Sublime Text?</title>
		<link>http://doppnet.com/2012/01/why-cant-all-software-be-like-sublime-text/</link>
		<comments>http://doppnet.com/2012/01/why-cant-all-software-be-like-sublime-text/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 15:18:51 +0000</pubDate>
		<dc:creator>Tom Najdek</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://doppnet.com/?p=530</guid>
		<description><![CDATA[Most software sux, but there are exceptions, gems that make me believe that not all is lost. Sublime Text 2 is one great example (and I don&#8217;t get paid to say so). There are great many places online where you can learn about its features, this post isn&#8217;t one. I want to focus on what [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://doppnet.com/2011/12/wtf-happened-to-software/" title="WTF Happened To Software">Most software sux</a>, but there are exceptions, gems that make me believe that not all is lost. <a href="http://www.sublimetext.com/2" title="Sublime Text 2" target="_blank">Sublime Text 2 </a>is one great example (and I don&#8217;t get paid to say so). There are <a href="http://news.ycombinator.com/item?id=3455360" target="_blank">great</a> <a href="http://www.reddit.com/r/programming/comments/o6aeb/sublime_text_2_demo_of_features_pdf/" target="_blank">many</a> <a href="http://net.tutsplus.com/tutorials/tools-and-tips/sublime-text-2-tips-and-tricks/" target="_blank">places</a> online where you can learn about its <a href="http://www.sublimetext.com/docs/2/" title="Sublime Text 2 documentation" target="_blank">features</a>, this post isn&#8217;t one. I want to focus on what makes Sublime Text make me love it when I hate most software:</p>
<p><strong>It&#8217;s sophisticated yet simple</strong>. In its core it&#8217;s just a text editor. Yet it has tabs, colored syntax, auto-complete, excellent regexp support, go-to-definition capability, snippets, multi-line selection and million other features that make you love it. It&#8217;s all there but it doesn&#8217;t manifest itself unless you say so. </p>
<p><strong>It&#8217;s centered around you and your work</strong>. It doesn&#8217;t enforce it&#8217;s own workflow (think &#8216;create project&#8217; from some IDEs). It doesn&#8217;t ask stupid questions (try closing an editor with 10 unsaved documents, you will get 10 stupid dialog boxes, 0 in Sublime Text 2). It remembers where you left your work and just gets there when started again. </p>
<p><strong>It&#8217;s blistering fast</strong>. It pops up immediately &#8211; no splash screen, no questions asked. It opens and parses 150K lines of xml in just below 3 seconds (and that&#8217;s on my non-SSD PC!) and you can edit and navigate it smoothly without waiting for anything. </p>
<p><strong>It&#8217;s extensible</strong>. There are <a href="http://wbond.net/sublime_packages/community" title="Sublime Text 2 Community Packages" target="_blank">hundreds of plugins</a> and you can write your own if you know python. </p>
<p><strong>It&#8217;s truly cross-platform</strong>. I&#8217;m regularly using Sublime Text 2 on Linux and Windows, with exception for some key-bindings it&#8217;s exactly the same piece of software. And a single license covers them all!</p>
<p><strong>It&#8217;s elegant</strong>.</p>
<p>Other software like that: Blender, Firefox, Chrome, XBMC&#8230; Gosh why this list is so short?</p>
]]></content:encoded>
			<wfw:commentRss>http://doppnet.com/2012/01/why-cant-all-software-be-like-sublime-text/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wtf happened to software?!</title>
		<link>http://doppnet.com/2011/12/wtf-happened-to-software/</link>
		<comments>http://doppnet.com/2011/12/wtf-happened-to-software/#comments</comments>
		<pubDate>Fri, 16 Dec 2011 21:57:24 +0000</pubDate>
		<dc:creator>Tom Najdek</dc:creator>
				<category><![CDATA[Rants]]></category>

		<guid isPermaLink="false">http://doppnet.com/?p=518</guid>
		<description><![CDATA[Gosh I hate what happened to software. I really do. When did it all happen? Let&#8217;s take windows for an example: Why all of sudden to use windows you need at least 2 firewalls, an anti-virus and a rookit detector. Why every time you start something else than Internet Explorer you have to confirm that [...]]]></description>
			<content:encoded><![CDATA[<p>Gosh I hate what happened to software. I really do. When did it all happen? Let&#8217;s take windows for an example: Why all of sudden to use windows you need at least 2 firewalls, an anti-virus and a rookit detector. Why every time you start something else than Internet Explorer you have to confirm that you indeed intended to run this application and yes it should be allowed to connect to the internet in both home and office network and yes public network too! Why every single app all of a sudden needs to add something to one of 10 places where windows keeps &#8216;autostart apps&#8217;; or sneak in a shitty toolbar plugin to spy on my every action; or at least change my default search engine.</p>
<p>Similar revolution happened to PC games: You need to download Steam, Origin or other spyware, create an account to play a single game these days. Origin takes 5 minutes to start on a well-spec gaming rig and Steam will fuck-up my game every time an update is release. And once you get through all this crap a small fluctuation on your network connection will stop you from playing thanks to our new friend DRM. This is supposed to stop piracy they say, but hey it has been on the Pirate Bay day before the official release day and Razor 1911 made it EASIER to install the damn thing than the distributor itself. Put the disc in, double click razor_install.exe, select path, click OK, grab a drink, play.</p>
<p>Another thing &#8211; programmer&#8217;s best friend &#8211; the IDE (or a very clever editor). My programming environment is like a temple so I can&#8217;t stand one that takes 20 seconds to start like Eclipse does, or one that crashes every 30 minutes like Komodo does. Since I&#8217;m using different operating systems it can&#8217;t be platform limited like Visual Studio and hey I appreciate the fact that your vim/emacs can do all that Eclipse does but I don&#8217;t have 10 years spare to learn all the magic nor I really want to use a command-line text editor 40 years after Apple stole GUI from Xerox.</p>
<p>Sometimes I find myself thinking that I should have become a monk; find myself an isolated cave in Himalayas and spend rest of my life searching for inner peace. Yet they don&#8217;t have 3G up there so I&#8217;ll stick to my software engineer career.</p>
]]></content:encoded>
			<wfw:commentRss>http://doppnet.com/2011/12/wtf-happened-to-software/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>10 Advanced JavaScript Interview Questions</title>
		<link>http://doppnet.com/2011/10/10-advanced-javascript-interview-questions/</link>
		<comments>http://doppnet.com/2011/10/10-advanced-javascript-interview-questions/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 12:45:48 +0000</pubDate>
		<dc:creator>Tom Najdek</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://doppnet.com/?p=444</guid>
		<description><![CDATA[Whether you&#8217;re looking to prepare for an interview for JavaScript role, you&#8217;re an interviewer looking for inspiration or you just want to evaluate your JavaScript knowledge here are 10 advanced topics that a software engineer working with JavaScript should be able to answer. Bear in mind that answers here are kept minimal, there are lots [...]]]></description>
			<content:encoded><![CDATA[<p>Whether you&#8217;re looking to prepare for an interview for JavaScript role, you&#8217;re an interviewer looking for inspiration or you just want to evaluate your JavaScript knowledge here are 10 advanced topics that a software engineer working with JavaScript should be able to answer. Bear in mind that answers here are kept minimal, there are lots of caveats not mentioned.</p>
<p><span id="more-444"></span></p>
<p><strong>When would you use var in your declaration and when you wouldn&#8217;t?</strong></p>
<p><strong></strong>Always use var. Not using var for variable declaration will traverse scopes all the way up till the global scope. If variable with that name is not found it will declare it in the global scope. Therefore not using var implicitly declares variable in the global scope (which, let me remind you, is a bad practice).</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   baz <span style="color: #339933;">=</span> <span style="color: #CC0000;">5</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> bar <span style="color: #339933;">=</span> <span style="color: #CC0000;">10</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>baz<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// outputs 5</span>
<span style="color: #006600; font-style: italic;">//console.log(bar); // error: bar is not defined</span></pre></div></div>

<p lang="javascript">A common mistake is to not use var in loops which might, in some cases, bear unexpected results or pollute the global scope:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> baz <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Hello World&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> bar<span style="color: #339933;">=</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span> bar</pre></div></div>

<p lang="javascript">Try it: <a title="Not using 'var' can cause problems" href="http://jsfiddle.net/tnajdek/AKxn9/" target="_blank">http://jsfiddle.net/tnajdek/AKxn9/</a></p>
<p><strong>What does the attribute defer/async do when added to the script tag?</strong></p>
<p>The defer attribute will cause browser to execute script after the document has been parsed. This attribute was first implemented in Internet Explorer 4, then <a title="HTML 4.01 script tag, defer attribute" href="http://www.w3.org/TR/html401/interact/scripts.html#adef-defer" target="_blank">added to HTML 4</a> and more recently<a title="HTML 5 spec - script tag, defer attribute" href="http://dev.w3.org/html5/spec/Overview.html#attr-script-defer" target="_blank"> HTML 5 spec</a>. You might not have heard of it as it has not been supported till version 3.5 (Gecko 1.9.2). Async is another attribute that can affect how a script is loaded and executed, here is a quote from HTML 5 spec on how this is expected to work:</p>
<blockquote><p>There are three possible modes that can be selected using these attributes. If the <code title="attr-script-async">async</code> attribute is present, then the script will be executed asynchronously, as soon as it is available. If the <code title="attr-script-async">async</code> attribute is not present but the <code title="attr-script-defer">defer</code> attribute is present, then the script is executed when the page has finished parsing. If neither attribute is present, then the script is fetched and executed immediately, before the user agent continues parsing the page.</p></blockquote>
<p>Note: A somewhat (but not exactly) similar defer behavior can be achieved by placing your script tags at the end of the body tag and that&#8217;s what is considered to be modern &#8216;best practice&#8217;</p>
<p><strong>What is the difference between == and ===? Which one would you use?</strong></p>
<p>The equality (==) operator will compare for equality after doing necessary type casting, the identity operator (===) doesn&#8217;t do any conversions. A good practice suggested by Douglas Crockford is to always use strict equality,  couple of examples from Douglas&#8217; book <a title="Douglas Crockford - JavaScript: The Good Parts" href="http://www.amazon.co.uk/exec/obidos/ASIN/0596517742/doppnetcom-21" target="_blank">JavaScript: The Good Parts</a></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #3366CC;">''</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'0'</span>          <span style="color: #006600; font-style: italic;">// false</span>
<span style="color: #CC0000;">0</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">''</span>            <span style="color: #006600; font-style: italic;">// true</span>
<span style="color: #CC0000;">0</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'0'</span>           <span style="color: #006600; font-style: italic;">// true</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'false'</span>   <span style="color: #006600; font-style: italic;">// false</span>
<span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'0'</span>       <span style="color: #006600; font-style: italic;">// true</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">==</span> undefined <span style="color: #006600; font-style: italic;">// false</span>
<span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span>      <span style="color: #006600; font-style: italic;">// false</span>
<span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">==</span> undefined  <span style="color: #006600; font-style: italic;">// true</span></pre></div></div>

<p><strong>How would you check if a variable is null/undefined?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//check if bar is null</span>
bar <span style="color: #339933;">===</span> <span style="color: #003366; font-weight: bold;">null</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//check if bar is undefined</span>
<span style="color: #000066; font-weight: bold;">typeof</span> bar <span style="color: #339933;">===</span> <span style="color: #3366CC;">&quot;undefined&quot;</span></pre></div></div>

<p><strong>How do you check if a variable is an object</strong><br />
You can use <code>typeof</code> to determine if variable is an object, however bear in mind that null is actually an object! However null object is &#8216;falsy&#8217; thus the following will work:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>bar <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">typeof</span> bar <span style="color: #339933;">===</span> <span style="color: #3366CC;">&quot;object&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'bar is object and is not null'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Discuss  scoping in JavaScript.</strong></p>
<p>JavaScript has lexical scoping based on functions but not blocks. Therefore:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//global scope</span>
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//anonymous function scope</span>
    <span style="color: #003366; font-weight: bold;">var</span> foo <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">function</span> bar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">//bar function scope</span>
        <span style="color: #003366; font-weight: bold;">var</span> foo <span style="color: #339933;">=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    bar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>foo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//outputs 1</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> foo <span style="color: #339933;">=</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//redeclares foo</span>
    <span style="color: #009900;">&#125;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>foo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//outputs 3</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Try it: <a title="Lexical scoping in JavaScript" href="http://jsfiddle.net/tnajdek/8y3XC/" target="_blank">http://jsfiddle.net/tnajdek/8y3XC/</a>. Note: from within function scope everything in above scope(s) is available (see closures below)</p>
<p><strong>Explain hoisting in JavaScript.</strong></p>
<p>As some might not be familiar with the term &#8216;hoisting&#8217; yet have the relevant experience this question could be asked indirectly</p>
<p>In JavaScript function declarations ( <code>function foo() {}</code> ) and variable declarations ( <code>var bar</code>  ) are &#8216;hoisted&#8217; i.e. are silently moved to the very top of the scope. Consider the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>bar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//returns 'undefined'</span>
    <span style="color: #006600; font-style: italic;">//console.log(baz) // error: baz is not defined</span>
    foo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// outputs 'aloha' to the console</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//function declaration AND its body is hoisted</span>
    <span style="color: #003366; font-weight: bold;">function</span> foo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'aloha'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #006600; font-style: italic;">//variable declaration is hoisted but value assignment stays here</span>
    <span style="color: #003366; font-weight: bold;">var</span> bar <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
    baz <span style="color: #339933;">=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//defines baz in global scope</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p lang="javascript"><span class="Apple-style-span" style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; white-space: normal;">See for yourself: <a title="Example of JavaScript hoisting on jsfiddle" href="http://jsfiddle.net/tnajdek/FxDrj/" target="_blank">http://jsfiddle.net/tnajdek/FxDrj/</a></span></p>
<p><strong>What are closures?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">function</span> foo<span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> baz <span style="color: #339933;">=</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>y<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>x <span style="color: #339933;">+</span> y <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">++</span>baz<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #003366; font-weight: bold;">var</span> moo <span style="color: #339933;">=</span> foo<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// moo is now a closure.</span>
moo<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 7</span>
moo<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// 8!</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The inner function inside <code>foo</code> will close-over the variables of <code>foo</code> before leaving creating a closure.</p>
<p>Try it: <a title="Closures in JavaScript" href="http://jsfiddle.net/tnajdek/Rj6mK/" target="_blank">http://jsfiddle.net/tnajdek/Rj6mK/</a></p>
<p><strong>Explain prototypal/differential inheritance</strong></p>
<p>Conceptually this is very simple: A new object can inherit properties of an old object.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> genericObject <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
        bar <span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Hello World&quot;</span><span style="color: #339933;">,</span>
        get_bar <span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">bar</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> customObject <span style="color: #339933;">=</span> Object.<span style="color: #660066;">create</span><span style="color: #009900;">&#40;</span>genericObject<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    customObject.<span style="color: #660066;">bar</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Aloha folks!&quot;</span><span style="color: #339933;">;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>customObject.<span style="color: #660066;">get_bar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//outputs: &quot;Aloha folks&quot;</span>
    <span style="color: #000066; font-weight: bold;">delete</span> customObject.<span style="color: #660066;">bar</span><span style="color: #339933;">;</span>
    console.<span style="color: #660066;">log</span><span style="color: #009900;">&#40;</span>customObject.<span style="color: #660066;">get_bar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//fallbacks to the prototype's value, outputs: &quot;Hello World&quot;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>While JavaScript has always been a prototype-oriented language, tools to work with prototypes were somewhat missing. <code>Object.create</code> used in the code snipped above has been added in ECMAScript 5 and has not been supported prior to Firefox 4, Chrome 5, IE 9</p>
<p><strong>What is Strict Mode in JavaScript</strong><br />
Strict Mode has been introduced as part of ECMAScript 5 and introduces new, restricted variant of JavaScript which has following aims:</p>
<ul>
<li>Throws errors for actions that are rather silly but previously didn&#8217;t throw an error</li>
<li>Throws errors for potentially unsafe actions</li>
<li>Disables functions that are poorly thought out</li>
<li>Potentially code in strict mode could run faster by eliminating mistakes that would make it difficult for JavaScript engines to perform optimizations</li>
</ul>
<p>Strict mode can be enabled for the entire source file or on per function basis by adding a string literal &#8220;use strict&#8221; on top of the file/function i.e.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> foo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #3366CC;">&quot;use strict&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #006600; font-style: italic;">// ... your code ...</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>For more detailed information about the strict mode consult <a title="MDN: Strict Mode" href="https://developer.mozilla.org/en/JavaScript/Strict_mode" target="_blank">relevant article on MDN</a></p>
<p><strong>Extra topics for discussion:</strong></p>
<ul>
<li>What&#8217;s your favorite browser, framework, JavaScript book</li>
<li>How do you approach debugging in JavaScript</li>
<li>What do you think of JSLint?</li>
<li>Browser detection vs. feature sniffing</li>
</ul>
<p>Anything I missed? Had a surprising interview question I haven&#8217;t covered? Let me know in comments below!</p>
]]></content:encoded>
			<wfw:commentRss>http://doppnet.com/2011/10/10-advanced-javascript-interview-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cracking the Google Code</title>
		<link>http://doppnet.com/2011/07/cracking-the-google-code/</link>
		<comments>http://doppnet.com/2011/07/cracking-the-google-code/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 15:36:04 +0000</pubDate>
		<dc:creator>Tom Najdek</dc:creator>
				<category><![CDATA[Challenges]]></category>

		<guid isPermaLink="false">http://doppnet.com/?p=359</guid>
		<description><![CDATA[Spoiler alert: In this article I&#8217;m going to give a step-by-step solution to Google Chromebook logic puzzle describing my exact thought process and hopefully providing few useful pieces of advice regarding cracking puzzles in general. However I encourage you to have a go at the puzzle yourself before reading the solution. The Begining We begin [...]]]></description>
			<content:encoded><![CDATA[<p>Spoiler alert: In this article I&#8217;m going to give a step-by-step solution to <a title="Chromebook puzzle no 5" href="http://www.google.co.uk/chromebook/puzzles/puzzle5.html" target="_blank">Google Chromebook logic puzzle</a> describing my exact thought process and hopefully providing few useful pieces of advice regarding cracking puzzles in general. However I encourage you to have a go at the puzzle yourself before reading the solution.</p>
<h3>The Begining</h3>
<p>We begin with guesstimating the correct order for colourful balls. This is the easy part, it&#8217;s pretty much a <a title="Mastermind (wikipedia article)" href="http://en.wikipedia.org/wiki/Mastermind_(board_game)" target="_blank">Mastermind</a> game, but I didn&#8217;t realize it at that time. There is no limit on the number of attempts and you can pretty much brute force it. Each time you attempt to make a guess, you are being given a &#8216;hint&#8217; or a &#8216;score&#8217; on how close was your attempt to the actual solution. After trying for couple of times you can deduct what&#8217;s the meaning of these little black/white/gray bulbs even if you&#8217;ve never seen a Mastermind game before.</p>
<p><span id="more-359"></span>Here is how I started the game:</p>
<p style="text-align: center;"><a href="http://doppnet.com/wp-content/uploads/2011/07/chromebook1.png"><img class="aligncenter size-full wp-image-360" title="The Chromebook Puzzle - Initial Play" src="http://doppnet.com/wp-content/uploads/2011/07/chromebook1.png" alt="" width="561" height="587" /></a></p>
<p>Terminology:<em> What in Mastermind is called <strong>code pegs</strong> I ignorantly refer to as &#8216;balls&#8217; within this document. What in Mastermind would be <strong>key pegs </strong>I simply call &#8216;bulbs&#8217;. </em></p>
<p>After each guess I&#8217;m getting a feedback consisting of 6 bulbs:</p>
<ul>
<li>each black bulb represents a single ball in correct spot</li>
<li>each white bulb represents a single ball in incorrect spot i.e. a ball of this color should be used somewhere else in the sequence</li>
<li>gray/empty bulb represents ball that has no place in the final answer</li>
</ul>
<div>With no more than 4 attempts you can estimate how many times a ball of each color should appear in the final solution. That simplifies the problem to arranging the balls in correct order. I admit I pretty much brute forced the actual correct order and it took me roughly 20 minutes to go through all 11 levels while having the lunch in the office at the same time.</div>
<h3>The Mysterious Code</h3>
<div>After each level you&#8217;re presented with a little hint, see the arrangements of bulbs below:</div>
<p style="text-align: center;"><a href="http://doppnet.com/wp-content/uploads/2011/07/chromebook2.png"><img class="size-full wp-image-361 aligncenter" title="The Chromebook Puzzle - First Level Completed" src="http://doppnet.com/wp-content/uploads/2011/07/chromebook2.png" alt="" width="538" height="585" /></a></p>
<p>Not much huh? Well that&#8217;s all the help you will get! After each level a screen similar to the one above is displayed. Eventually you will be asked if you&#8217;ve &#8216;cracked the code&#8217; and to submit a solution. After finishing all 11 levels I&#8217;ve stopped for the moment an summarized my knowledge so far:</p>
<ol>
<li>There are 11 levels in total and 22 bulbs in 2 rows, 11 bulbs each</li>
<li>Each level is associated with 2 lightened bulbs</li>
<li>Lightened bulbs are unique for each level</li>
<li>Each level is associated with 6 balls in one out of 4 colors</li>
</ol>
<p>From the points listed above I&#8217;ve deducted the following:</p>
<ol>
<li>Bulbs represent some kind of &#8216;meta data&#8217; &#8211; position, location, placement.</li>
<li>The actual value must be represented by the colorful balls</li>
<li>There are 6 balls and 2 highlighted bulbs per each level thus each 3 balls must represent a single &#8216;unit&#8217; of data</li>
</ol>
<p>Based on these assumptions I&#8217;ve tried to come up with some way (an algorithm) to derive a value from the set of 3 balls, usually by mixing and re-calculating their RGB representations in different ways. That didn&#8217;t work.</p>
<p>So let&#8217;s have another look at the screen above, there is one more hint on that screen which I&#8217;ve managed to completely ignore. On the very top of the screen there are 6 balls that are persistent between levels. It&#8217;s easy to miss them because colors are quite familiar &#8211; it&#8217;s Google logo colors. Let&#8217;s make another assumption:</p>
<ol start="4">
<li>The key to the solution is Google logo or its colors.</li>
</ol>
<p>At this point my imagination went quite wild. I&#8217;ve tried to perform various calculations on RGB representations of Google logo bulbs and each level&#8217;s solution bulbs. I&#8217;ve went as far as counting the number of occurrences of each color (blue and red -&gt; 2, green and yellow -&gt;1), converting that to binary and trying to get the answer that way. I&#8217;ve gave up after about an hour, finished lunch and get back to office work.</p>
<h3>The Revelation</h3>
<p>After a busy day in the office I&#8217;ve been chilling at home with some cold beer when a revelation struck me &#8211; I already had the algorithm I&#8217;ve been looking for so badly! The algorithm has been used to give me feedback after each guess in the initial Mastermind-like game. Let&#8217;s try to recreate it:</p>
<ol>
<li>Iteratively compare a ball from the guessed answer to a bulb in the same spot in the secret solution</li>
<li>If bulbs have the same colour, the result is black dot [•]</li>
<li>If bulbs have different colour, check other bulbs in the secret solution. If there is one with a matching colour in the secret solution (that is not matched correctly in the guessed answer and it has not been used before) the result is white dot [◦], otherwise it&#8217;s null [0].</li>
<li>In case where operation 3 results in [◦], mark that bulb in secret solution as &#8216;used&#8217;.</li>
<li>After comparing all balls Count [•], [◦] and [0] and use sorted counts to give feedback</li>
</ol>
<p>In practice this is how it would look like:</p>
<div style="text-align: center;"><a href="http://doppnet.com/wp-content/uploads/2011/07/chromebook3-1.png"><img class="size-full wp-image-374 aligncenter" title="The Mastermind Algorithm - Reverse Engineering" src="http://doppnet.com/wp-content/uploads/2011/07/chromebook3-1.png" alt="" width="432" height="188" /></a></div>
<p>Let&#8217;s re-use the same algorithm to score the level&#8217;s 1 solution against Google colors:</p>
<div style="text-align: center;"><a href="http://doppnet.com/wp-content/uploads/2011/07/chromebook4.png"><img class="aligncenter size-full wp-image-379" title="The Mastermind Algorithm - Reusing" src="http://doppnet.com/wp-content/uploads/2011/07/chromebook4.png" alt="" width="432" height="137" /></a></div>
<p>Let&#8217;s reassess the assumptions made earlier on:</p>
<ol>
<li>Bulbs represent some kind of &#8216;meta data&#8217; &#8211; position, location, placement.</li>
<li>The actual value must be represented by the bulbs.</li>
<li>There are 6 balls and 2 highlighted bulbs per each level thus each 3 balls must represent a single &#8216;unit&#8217; of data</li>
<li>The key to the solution is Google logo or its colors.</li>
</ol>
<p>Based on assumptions 2 &amp; 4 we&#8217;ve derived a value, marked as score on the chart above. Based on assumption 3 we need to derive 2 &#8216;units&#8217; of data. Earlier on feedback has been given in 2 rows, 3 bulbs each, so let&#8217;s do the same &#8211; but without sorting (effectively skipping step 5 in the algorithm described above). We will have:</p>
<ol>
<li>[◦] [•] [0]</li>
<li>[◦] [•] [0]</li>
</ol>
<p>Same? Funny.</p>
<p>Now follows the tricky part &#8211; so far we&#8217;ve been speaking about balls and bulbs, however the final answer must be a number or sentence. I&#8217;ve asked myself a question &#8211; how can I convert these symbols into values? Well there are 3 possible values for each scoring operation ([•], [◦] or [0]). Let&#8217;s assign these symbols numerical values &#8211; 2 for [•], 1 for [◦] and 0 for [0]. So far we have</p>
<ol>
<li>1,2,0</li>
<li>1,2,0</li>
</ol>
<p>120 in ascii is lowercase &#8216;x&#8217;, however if you think about it, most of the combinations of 0, 1 and 2 don&#8217;t produce meaningful values in ascii (e.g. 012 would be &#8216;vertical tab&#8217;). You can&#8217;t build a sentence with such a limited vocabulary either. It&#8217;s an incorrect approach, let&#8217;s try something different.</p>
<p>With my scoring algorithm I can produce no more than 3 symbols, later converted into numeric values. Since I can have only 3 different values I shouldn&#8217;t assume a decimal system! A <strong>Ternary (base 3) </strong>system would be more suitable, let&#8217;s try it:</p>
<ol>
<li>120<sub>3</sub> = 15<sub>10</sub></li>
<li>120<sub>3</sub> = 15<sub>10</sub></li>
</ol>
<p>Ok&#8230; that still doesn&#8217;t mean much in ascii. Let&#8217;s see what kind of values I can expect with 3 digits ternary system:</p>
<ul>
<li>Minimum: 000<sub>3</sub> = 0<sub>10</sub></li>
<li>Maximum: 222<sub>3</sub> = 26<sub>10</sub></li>
</ul>
<p>26? Hold on, isn&#8217;t that a total number of letters in english alphabet? Wikipedia!</p>
<blockquote><p>The modern <strong>English alphabet</strong> is a Latin-based alphabet consisting of 26 letters</p></blockquote>
<p>Bingo! Lazy as I&#8217;m I&#8217;ve googled for english letters ordering numbers (<a title="Puzzle reference page" href="http://moonatnoon.com/puzzles/reference/a1b2z26.html" target="_blank">got this</a>) and looked up 15th letter of the alphabet (it&#8217;s letter O). So we have:</p>
<ol>
<li>[◦] [•] [0] =&gt; 1,2,0 =&gt; 120<sub>3</sub> = 15<sub>10</sub> =&gt; &#8216;O&#8217;</li>
<li>[◦] [•] [0] =&gt; 1,2,0 =&gt; 120<sub>3</sub> = 15<sub>10</sub> =&gt; &#8216;O&#8217;</li>
</ol>
<p>Assumption no 1 says &#8220;Bulbs represent some kind of &#8216;meta data&#8217; &#8211; position, location, placement&#8221;. Let&#8217;s try that:</p>
<div style="text-align: center;"><a href="http://doppnet.com/wp-content/uploads/2011/07/chromebook5.png"><img class="aligncenter size-full wp-image-382" title="The Solution Revealed (almost!)" src="http://doppnet.com/wp-content/uploads/2011/07/chromebook5.png" alt="" width="360" height="126" /></a></div>
<p>From that point it&#8217;s couple of minutes to work your way through the remaining 10 levels reusing the same approach. Couple of minutes later I had the code cracked and submitted to Google. And hey! <a title="Google Chromebook Puzzle Contents Winners" href="http://www.google.co.uk/chromebook/puzzles/winners.html" target="_blank">I&#8217;ve won a Chromebook</a> :)</p>
<h3>The Summary</h3>
<p>Cracking logic puzzles like this one is not something you can learn. Yet having a correct approach can definitely help. Couple of hints I can share:</p>
<ol>
<li>Whenever you&#8217;re stuck &#8211; stop and assess your knowledge. Write it down as a list, graph or something.</li>
<li>If you&#8217;re still stuck make an assumption and chase it. Gazing at the problem usually doesn&#8217;t help.</li>
<li>It&#8217;s ok to fail. Learn from it, then discard a non-working solution, revert back to a known state and start again.</li>
<li>If you&#8217;re stuck for a long time, leave it. Look for something else to do and come back to a problem later on.</li>
<li>Don&#8217;t give up!</li>
</ol>
<div>Good luck!</div>
]]></content:encoded>
			<wfw:commentRss>http://doppnet.com/2011/07/cracking-the-google-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mining Bitcoins</title>
		<link>http://doppnet.com/2011/05/mining-bitcoins/</link>
		<comments>http://doppnet.com/2011/05/mining-bitcoins/#comments</comments>
		<pubDate>Sat, 28 May 2011 19:23:11 +0000</pubDate>
		<dc:creator>Tom Najdek</dc:creator>
				<category><![CDATA[Experiments]]></category>

		<guid isPermaLink="false">http://doppnet.com/?p=218</guid>
		<description><![CDATA[tl;dr: I&#8217;ve experimented with Bitcoin, the p2p, digital crypto-currency, for over a month, made some profit and eventually decided to build a dedicated mining machine. Recently Bitcoin has gained a lots of attraction and has been both praised and criticized. While there are multiple threats to the technology and community, Bitcoin is something definitely worth [...]]]></description>
			<content:encoded><![CDATA[<p><strong>tl;dr: </strong>I&#8217;ve experimented with Bitcoin, the p2p, digital crypto-currency, for over a month, made some profit and eventually decided to build a dedicated mining machine. Recently Bitcoin has gained a lots of attraction and has been both praised and criticized. While there are multiple threats to the technology and community, Bitcoin is something definitely worth keeping an eye on.</p>
<h2>What is a Bitcoin</h2>
<p>Bitcoin is an anonymous, decentralized, p2p, digital (crypto)currency that comes with a network to maintain it. There is no central authority to maintain the currency, thus the network has a mechanism to track transactions and the ownership of Bitcoins, as well as prevent any fraudulent behavior such as spending Bitcoins you don&#8217;t have, double spending or creating Bitcoins out of a thin air. New Bitcoins are created at predictable rate through a process known as &#8216;mining&#8217; which requires a lot of computational power to do and is also used to verify past transactions. Bitcoin has been created in 2009 by a mysterious Satoshi Nakamoto who wrote the original client and helped the network to take off, then gradually reducing his involvment. To join the Bitcoin community and start using it is an open source client which you can download from <a title="bitcoin.org" href="http://www.bitcoin.org/" target="_blank">bitcoin.org</a>.</p>
<p><span id="more-218"></span></p>
<h2>Mining explained</h2>
<p>Mining is the process of generating new Bitcoins as well as validating transactions that have been made by other members of the network. The process itself is somewhat peculiar and there are some who would say it&#8217;s a pointless waste of resources. In simple terms a miner would continually calculate a sha256 hash of a representation of Bitcoin transactions and a certain nonce (a meaningless number used only to change the hashing result) to generate a block and create a proof of work. Generated hash is then compared to a target (<a title="Current Bitcoin target" href="http://blockexplorer.com/q/hextarget" target="_blank">current value</a>) and if it is less or equal it is accepted and the block is generated (if it is grater than the target then hash is discarded, nonce is modified/increased and process is continued). If a miner is successful he is allowed to append a transaction of 50 BTC credited to his Bitcoin account &#8211; an incentive for miners for doing the hard work. The block generated is then propagated into the Bitcoin network where it exists inside a &#8216;chain&#8217; so that each block is connected to a previous one and the next one. More detailed (and far more technical) description of the process can be found on <a title="Bitcoin wiki" href="https://en.bitcoin.it/wiki/Main_Page" target="_blank">Bitcoin Wiki/Help page</a>.</p>
<p>&nbsp;</p>
<h2>The Bitcoin economy</h2>
<p>Gradually, over time, the amount of Bitcoins awarded for generating a block will decrease at predictable rate (it&#8217;s halved every 210&#8217;000 blocks, recently we&#8217;ve reached block 127&#8217;000 so it is still months if not years till that happens). Bitcoin network controls the amount of blocks generated every week by amending the difficulty of coming up with a valid hash (see &#8216;target&#8217; above) &#8211; the target is to achieve exactly 2016 blocks generated every week (in other words 144 a day or  1 every 10 minutes). At some point in distant future generating a block will yield a neglectable amount of Bitcoins thus making it inefficient for miners to participate. For that reason one can add an additional fee to the transaction which will be awarded to the miner discovering the block. Transactions with fees will have higher priorities thus being processed and confirmed first. Currently and in the near future this is not really needed as the default 50 BTC is lucrative enough but in the future it will ensure a well-being of the Bitcoin network.</p>
<p>&nbsp;</p>
<h2>Bitcoin Markets</h2>
<p>Bitcoins can be used for paying for goods and services in <a title="Places that accept Bitcoins" href="https://en.bitcoin.it/wiki/Trade">many places</a> but it is still far from common to accept Bitcoins as a form of payment. Another thing you can do with your Bitcoins is trade them for fiat currencies and gold on <a title="Bitcoin Markets" href="http://bitcoincharts.com/markets/" target="_blank">various markets</a>. Out of curiosity I&#8217;ve experimented with trading few Bitcoins for GPB and getting money in and out with wire transfers &#8211; it all went well. Usually you can trade Bitcoins without paying any fees &#8211; similarly, as of today, you can send them around without paying any transaction fees. That means that with a little extra effort you could use Bitcoins to send money to different countries without paying outrageous bank fees for such transfers. I can also think of some &#8216;shady&#8217; ways Bitcoins could be possible used but let&#8217;s leave this out of the picture.</p>
<p>&nbsp;</p>
<h2>Reception</h2>
<p>Bitcoin community has gained a lot of attraction during past month. There were couple of interesting articles that have made it to the top of the Hacker News, most notable: <a title="Why Bitcoin will fail" href=" http://apenwarr.ca/log/?m=201105#08" target="_blank">Why Bitcoin will fail aka &#8216;the rant&#8217;</a> and <a title="Bitcoin payment system isnt like the gold standard" href="http://www.bitcoinbulletin.com/2011/05/09/the-bitcoin-payment-system-isnt-like-the-gold-standard/" target="_blank">the answer for that</a>. Bitcoin seems to gain popularity and it is about time that governments start <a title="Gavin will visit the CIA " href="http://forum.bitcoin.org/?topic=6652.0" target="_blank">poking around</a> sniffing potential threat to the controlled economies. While this interest is a potential threat to the Bitcoin currency, the currency itself is doing very well. Over past month the value of a Bitcoin raised multiple times:</p>
<div id="attachment_300" class="wp-caption aligncenter" style="width: 640px"><a href="http://doppnet.com/wp-content/uploads/2011/05/chart.png"><img class="size-full-width-margin wp-image-300 " title="BTC/USD exchange rate value 1 April - 28 May - chart courtesy of bitcoincharts.com" src="http://doppnet.com/wp-content/uploads/2011/05/chart-630x273.png" alt="BTC/USD exchange rate value 1 April - 28 May - chart courtesy of bitcoincharts.com" width="630" height="273" /></a><p class="wp-caption-text">BTC/USD exchange rate value 1 April - 28 May - chart courtesy of bitcoincharts.com</p></div>
<p>&nbsp;</p>
<h2>My findings</h2>
<p>I&#8217;ve begun mining with my desktop machine approximately a month ago. After trying couple of different miners I&#8217;ve chosen a <a title="Phoenix Miner " href="http://forum.bitcoin.org/?topic=6458.0" target="_blank">Phoenix Miner</a> for my Linux box with Ati Radeon 6950 (flashed to 6970) which is capable of doing approximately340Mhash/s without breaking a sweat (usable desktop, fat @50%). At current difficulty mining solo with this kind of computational power might turn out to be very unrewarding &#8211; you could be mining for days, weeks even months without finding a single block and thus earning exactly 0 BTC.  However a group of people working together can easily find a block within minutes thus mining pools have been conceived. Effectively pool is just a group of people working together on the same block in order to boost chance of finding a block. Pool&#8217;s computational power reaches many GHashes per second and finding a block is a matter of hours or even minutes for a crowded pool! Once block is found, the reward is then divided between all participants usually based on amount of shares each has provided. I&#8217;ve tried 2 different pools, <a title="DeepBit Bitcoin Pool" href="http://deepbit.net" target="_blank">deepbit</a> and <a title="BitcoinPool" href="http://bitcoinpool.org" target="_blank">bitcoinpool</a>, first one being the biggest public pool currently in existence and running at speeds above 1 Thash/s (!), second much smaller (currently around 100 Ghash/s). Effective earnings at each pool are comparable &#8211; deepbit gives you a lot of small payments (they usually find a block within minutes), bitcoinpool gives you a slightly bigger payouts but less often &#8211; still it is at most couple of hours between payouts.</p>
<p>With my 340Mhash/s machine I&#8217;ve been initially able to generate approximately 3BTC during each 24hrs period but due to the increase in difficulty over past month I can now roughly do half of that. At the same time I&#8217;ve been using the same machine for day-to-day activities and occasionally I&#8217;ve been forced to switch mining off if I had a need of GPU. After a month I&#8217;ve decided to get a dedicated mining machine and see how it fares.</p>
<p>For my dedicated machine I&#8217;ve chosen Radeon 5870 cards with hope to keep it most cost-effective. I&#8217;ve built the following spec:</p>
<ul>
<li>Motherboard: <a href="http://www.amazon.co.uk/dp/B003F8SNBM/?tag=doppnetcom-21">ASUS Crosshair IV</a></li>
<li>Power Supply: <a href="http://www.amazon.co.uk/dp/B00154QAXQ/?tag=doppnetcom-21">Corsair CMPSU-1000HX 1000W</a></li>
<li>GPU: 3x <a href="http://www.amazon.co.uk/dp/B0037YMWXO/?tag=doppnetcom-21">XFX Radeon HD 5870</a></li>
<li>CPU: <a href="http://www.amazon.co.uk/dp/B002I25RWO/?tag=doppnetcom-21&quot;">AMD Sempron 140 2.7 GHz </a></li>
<li>RAM: <a href="http://www.amazon.co.uk/dp/B002BXA7UC/?tag=doppnetcom-21">Corsair 2GB 1333MHz DDR3</a></li>
</ul>
<p>&nbsp;</p>
<p>Couple of things you don&#8217;t really need but will make things easier:</p>
<ul>
<li><a href="http://www.amazon.co.uk/dp/B001CIREXA/?tag=doppnetcom-21" target="_blank">Cheapest HDD you can put your hands on</a></li>
<li><a title="NZXT H2 MidTower" href="http://www.amazon.co.uk/dp/B004ULYPVK/?tag=doppnetcom-21" target="_blank">Plain tower case with lots of fans</a></li>
<li>Cheap <a title="LG DVDRW" href="http://www.amazon.co.uk/dp/B004ULYPVK/?tag=doppnetcom-21" target="_blank">dvd drive</a> or a usb stick to boot the operating system</li>
</ul>
<p>&nbsp;</p>
<p>Which can produce between 1.1 and 1.3Ghash/s (depending on how good cooling you have) using Phoenix miner executed as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">python2.7 phoenix.py <span style="color: #660033;">-u</span> http:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #c20cb9; font-weight: bold;">login</span>:password<span style="color: #000000; font-weight: bold;">@</span>miningpool:<span style="color: #000000;">8334</span><span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-k</span> phatk <span style="color: #007800;">DEVICE</span>=<span style="color: #000000;">0</span> VECTORS BFI_INT <span style="color: #007800;">AGGRESSION</span>=<span style="color: #000000;">11</span> <span style="color: #007800;">WORKSIZE</span>=<span style="color: #000000;">128</span></pre></div></div>

<p>There are couple of things you can tweak. Theoretically with excellent airflow through your case and A/C in the room it should be possible to overclock all your cards to 900Mhz and reach speeds &gt;400Mhash/s per card (thus total speed of 1.2-1.3Ghash/s is possible). In practice, the cards are sandwiched and the card in the middle will run at slightly higher temperature than other two thus I&#8217;ve been forced to lower it&#8217;s clock:</p>
<div id="attachment_284" class="wp-caption aligncenter" style="width: 640px"><a href="http://doppnet.com/wp-content/uploads/2011/05/DSC_0118.jpg"><img class="size-full-width-margin wp-image-284  " title="My mining rig which I proudly call Arrakis" src="http://doppnet.com/wp-content/uploads/2011/05/DSC_0118-630x420.jpg" alt="My mining rig which I proudly call Arrakis" width="630" height="420" /></a><p class="wp-caption-text">My mining rig which I proudly call Arrakis</p></div>
<p>&nbsp;</p>
<h2>Threats</h2>
<p>Ok, this all sounds exciting so before you jump onto the wagon and spend your savings on numerous top-shelf graphic cards, let me at least outline couple of potential and actual threats that can make mining unprofitable or even trip the entire Bitcoin ecosystem.</p>
<ul>
<li>Raising difficulty. There are more and more miners, the overall speed of a network is rising in a steep curve and Bitcoin network tries to catch-up by increasing the difficulty. Due to the nature of the network, mining will eventually become  unprofitable:</li>
</ul>
<p>&nbsp;</p>
<div id="attachment_291" class="wp-caption aligncenter" style="width: 640px"><a href="http://doppnet.com/wp-content/uploads/2011/05/speed-lin-ever1.png"><img class="size-full-width-margin wp-image-291 " title="Difficulty of Bitcoin network over time - chart by courtesy of bitcoin.sipa.be" src="http://doppnet.com/wp-content/uploads/2011/05/speed-lin-ever1-630x393.png" alt="Difficulty of Bitcoin network over time - chart by courtesy of bitcoin.sipa.be" width="630" height="393" /></a><p class="wp-caption-text">Difficulty of Bitcoin network over time - chart by courtesy of bitcoin.sipa.be</p></div>
<p>&nbsp;</p>
<ul>
<li>Governments will try to kill it, there is no doubt in that. Bitcoin can turn out to be an interesting experiment in fields of p2p, the Internet and social freedoms in general.</li>
<li>Technology fails big time &#8211; a single failure of the technology could cause a huge and violent hyperinflation which in turn renders mining hugely unprofitable discouraging most miners and, in worse case scenario, killing the network.</li>
<li>A new technology comes with computing power so great that it will render GPU mining obsolete, in a similar fashion that GPUs made CPU mining obsolete.</li>
</ul>
<p>&nbsp;</p>
<p>This is by no means complete list of threats but only ones that I&#8217;ve personally found most accurate.</p>
<p>&nbsp;</p>
<h2>Summary</h2>
<p>Recently Bitcoin has definitely gained some traction and more and more people are looking into it. Currently value of a Bitcoin it pretty unstable but the general trend is upwards, or using more economic we&#8217;re in a long-term rally period. At this moment mining using a GPUs should turn out profitable but it might change due to multiple threats and rather unpredictable market. Whether you&#8217;re looking into becoming a miner, trading currencies, thinking about accepting Bitcoins on your e-commerce or just found Bitcoin an interesting curiosity it is definitively something worth keeping an eye on.</p>
<p>&nbsp;</p>
<h2>Resources</h2>
<ul>
<li>Home page: <a href="http://bitcoin.org/">http://bitcoin.org/</a> and wiki: <a href="https://en.bitcoin.it/wiki/Main_Page">https://en.bitcoin.it/wiki/Main_Page</a></li>
<li>Markets overview: <a href="http://bitcoinwatch.com/">http://bitcoinwatch.com/</a> and <a href="http://bitcoincharts.com/">http://bitcoincharts.com</a></li>
<li>Interesting visualization of a Bitcoin network (real-time) <a href="http://www.bitcoinmonitor.com/">http://www.bitcoinmonitor.com/</a></li>
<li>Mining pools: <a href="https://deepbit.net/">https://deepbit.net/</a> (3% charge), <a href="http://mining.bitcoin.cz/">http://mining.bitcoin.cz</a> (2% charge), <a href="http://bitcoinpool.org/">http://bitcoinpool.org/</a> (0% charge), <a href="http://btcguild.com/">http://btcguild.com/</a> (0% charge)</li>
<li>Profitability calculator (I would call it &#8216;guestimator&#8217;): <a href="http://bitcoinx.com/profit/">http://bitcoinx.com/profit/</a></li>
<li>Mining hardware comparision: <a href="https://en.bitcoin.it/wiki/Mining_Hardware_Comparison">https://en.bitcoin.it/wiki/Mining_Hardware_Comparison</a></li>
</ul>
<p>&nbsp;</p>
<p>If you would like to support my world domination plan, please send Bitcoins to: 1DNeuiLoEj6yJ16snHKg3e1DHyTeb6dz5g. I shall share them with Pinky and Brain.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://doppnet.com/2011/05/mining-bitcoins/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Coding while on the plane</title>
		<link>http://doppnet.com/2011/04/coding-while-on-the-plane/</link>
		<comments>http://doppnet.com/2011/04/coding-while-on-the-plane/#comments</comments>
		<pubDate>Thu, 14 Apr 2011 03:45:09 +0000</pubDate>
		<dc:creator>Tom Najdek</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://doppnet.com/?p=199</guid>
		<description><![CDATA[A simple fact that I have figured out while being 12km above the ground: you can do more during a single transatlantic flight than you can do during an entire day in your standard working environment. Flight from London to Washington DC takes roughly 8.5 hours. Minus time for the take off, landing and food [...]]]></description>
			<content:encoded><![CDATA[<p>A simple fact that I have figured out while being 12km above the ground: you can do more during a single transatlantic flight than you can do during an entire day in your standard working environment.</p>
<p>Flight from London to Washington DC takes roughly 8.5 hours. Minus time for the take off, landing and food that gives you approximately 7hrs of interruption-free time. In other words a true blessing! There are no co-workers to distract you, no lengthy meetings, no family or friends, no cell phone, not even the Internet access with things like Skype, Facebook, Twitter and Hacker News lingering for your attention. I&#8217;ve realized that <strong>I can do much more in a single block of uninterrupted time that I can in the same time split between other arrangements</strong>.  It&#8217;s amazing on its own, but there more to it!</p>
<p><span id="more-199"></span></p>
<p>Let&#8217;s analyse the standard approach that most developers take when facing a problem (and I&#8217;m being guilty of it as well!):</p>
<p>&nbsp;</p>
<ol>
<li>Search on Google &#8211; surely someone already did that before</li>
<li>Have a look on Stack Overflow &#8211; there is bunch of  clever developers there</li>
<li>Ask other developers (online or offline) around</li>
<li>Think</li>
</ol>
<p>&nbsp;</p>
<p>While on plane options 1-3 are not there at your disposal, thus you tend to spend more time actually thinking and trying to come up with a viable solution.  I&#8217;ve realized that code produced this way is of much better quality!.</p>
<p>Unfortunately this kind of environment is not easily reproduced. I&#8217;m under strong impression that the following could help to achieve it, at least partially:</p>
<ol>
<li>Work during night or early morning hours &#8211; people are less pesky at that time</li>
<li>Try to manage your time and arrange your time into a block of uninterrupted time (takes some human skills)</li>
<li>Change the environment of work - leave your multi-screen setup behind and take your laptop to the local coffee shop, park or library</li>
<li>Switch off Skype, mobile and email while working</li>
</ol>
<p>&nbsp;</p>
<p><strong>Update</strong>: A day after I&#8217;ve published this article Jacques Mattheij wrote a very interesting piece about &#8216;<a title="Living in the Zone" href="http://jacquesmattheij.com/living+in+the+zone" target="_blank">living in the zone</a>&#8216;, i.e. being in a state of mind where you&#8217;re entirely focused on something (like programming task) without interruption within a block of time. It&#8217;s definitely worth reading.</p>
]]></content:encoded>
			<wfw:commentRss>http://doppnet.com/2011/04/coding-while-on-the-plane/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Era of Opportunity</title>
		<link>http://doppnet.com/2011/03/era-of-opportunity/</link>
		<comments>http://doppnet.com/2011/03/era-of-opportunity/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 23:26:05 +0000</pubDate>
		<dc:creator>Tom Najdek</dc:creator>
				<category><![CDATA[Entrepreneurship]]></category>

		<guid isPermaLink="false">http://doppnet.com/?p=122</guid>
		<description><![CDATA[For last couple of days I&#8217;ve been reading and hearing a lot about now being the beginning of next dot-com bubble. Well we certainly see many more startups showing up these days and I believe that it&#8217;s because it&#8217;s way much easier to run a startup now. We have this wonderful pool of tools available that let [...]]]></description>
			<content:encoded><![CDATA[<p>For last couple of days I&#8217;ve been reading and hearing a lot about now being the beginning of next dot-com bubble. Well we certainly see many more startups showing up these days and I believe that it&#8217;s because it&#8217;s way much easier to run a startup now. We have this wonderful pool of tools available that let you rapidly mock up, test and throw away (or further develop!) concepts.  A quick and by no means complete list of assets that has emerged in recent years to make life of hackers and entrepreneurs alike so much easier (in no particular order):</p>
<ul>
<li>Cloud hosting like <a title="Amazon EC2" href="http://aws.amazon.com/ec2/">Amazon EC2</a> that can be instantly &#8216;thrown away&#8217; when no longer needed&#8217;</li>
<li>Social Media</li>
<li><a title="Launch Rock" href="http://launchrock.com/" target="_blank">LaunchRock</a></li>
<li>Frameworks and rapid development technologies that get you halfway through to ready product instantly</li>
<li>Supporting communities</li>
<li>A real <a title="Spring Startup Fever" href="http://www.avc.com/a_vc/2011/03/spring-startup-fever.html" target="_blank">fever</a> of events like <a title="Startup Weekend" href="http://startupweekend.org/" target="_blank">Startup Weekend</a></li>
</ul>
<p>&nbsp;</p>
<p>But to call it a bubble? I think that&#8217;s too much. Until yesterday I&#8217;ve been convinced that as Naval Ravikant has stated: <a title="Naval Ravikant hack your funding" href="http://hackersandfounders.tv/T7F/naval-ravikant-hack-your-funding/" target="_blank">there is no bubble</a>. Yesterday however <a title="Color" href="http://color.com" target="_blank">Color</a> has lunched and not without lots of hype. And hype is all I expect from something that managed to attract <a title="color on crunch" href="http://www.crunchbase.com/company/color" target="_blank">41 million dollars</a> of funding. Last night I&#8217;ve snatched an Android phone to check what is all this commotion about.  <span id="more-122"></span></p>
<p>So let me quickly describe my experience with Color. The phone I have been testing this on was Desire Z and the installation went fine, then the application started OK as well (I&#8217;ve seen  <a title="color at android" href="https://market.android.com/details?id=com.jckjck.color" target="_blank">some comments</a> about troubles getting that far). There were some significant problems with the interface (i.e. critical buttons hidden underneath the virtual keyboard and ignoring &#8216;enter&#8217; on a single input form) but it&#8217;s a alpha version so I can understand these as long as the app is usable. On first run I have been asked to enter my name and take a photo of myself which seems to me like too much to ask during the initial run. Nevertheless I took &#8216;some&#8217; photo and continued to see what can this app offer. Problem is that there is NOTHING more. Blank screen with a single photo of my wall that I&#8217;ve just taken. OK I&#8217;m guessing that&#8217;s because no one else is or has recently been using this app in my area, but hey! I&#8217;m not living in the middle of nowhere. Based on poor rating of this app on the Android Market I reckon I&#8217;m not the only person not being able to make any use of this app. I believe that there are some uses that I didn&#8217;t discover. Perhaps it&#8217;s really cool when used while attending a conference or a concert. Perhaps we have not yet discovered its full potential. It&#8217;s possible that Color will be &#8216;the next big thing&#8217; but if you ask me I say it&#8217;s highly unlikely.</p>
<p>Let me summarize: valuation of 80 something million dollars, no track record, lots of hype and product that is, so far, less than average. Sounds irrational, doesn&#8217;t it? It all seems to me like characteristics of many ventures that we&#8217;ve seen during the previous bubble era. And there is more to it! Jacques Mattheij has <a title="Jacques Mattheij" href="http://jacquesmattheij.com/41000006+reasons+why+I+think+we+are+in+a+bubble" target="_blank">posted an entire list</a> of indicators that we&#8217;re indeed in the next bubble.</p>
<p>Bubble or not I think it might be an era of opportunity for some. We live in interesting times and with all these assets at hand I tend to agree with Cristina Cordova &#8211; <a title="Aim Higher Stop Building Photo Sharing Apps" href="http://www.cristinajcordova.com/2011/03/aim-higher-stop-building-photo-sharing-apps/" target="_blank">let&#8217;s stop building photo sharing</a> applications and aim a bit higher&#8230;</p>
<p><strong>Edit</strong>: Apparently we have all misunderstood Color. It&#8217;s not a yet another photo sharing app, it&#8217;s a <a title="Color Keeps Digging" href="http://daringfireball.net/linked/2011/03/25/color-digging" target="_blank">data mining trojan horse</a> that runs on your mobile. Does it change anything? No.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://doppnet.com/2011/03/era-of-opportunity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A decent federated login implementation</title>
		<link>http://doppnet.com/2011/03/a-decent-federated-login-implementation/</link>
		<comments>http://doppnet.com/2011/03/a-decent-federated-login-implementation/#comments</comments>
		<pubDate>Wed, 23 Mar 2011 00:15:30 +0000</pubDate>
		<dc:creator>Tom Najdek</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[User Experience]]></category>
		<category><![CDATA[OAuth]]></category>
		<category><![CDATA[OpenID]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://doppnet.com/?p=116</guid>
		<description><![CDATA[It seems that folks at Quora don&#8217;t like the OpenID even going as far as claiming that: OpenID is the worst possible &#8220;solution&#8221; I have ever seen in my entire life to a problem that most people don&#8217;t really have Sounds pretty harsh, doesn&#8217;t it? Personally I think it&#8217;s all bunch of bollocks! I think problem [...]]]></description>
			<content:encoded><![CDATA[<div>
<p>It seems that <a href=" http://www.quora.com/What-s-wrong-with-OpenID" target="_blank">folks at Quora don&#8217;t like the OpenID</a> even going as far as claiming that:</p>
<blockquote><p>OpenID is the worst possible &#8220;solution&#8221; I have ever seen in my entire life to a problem that most people don&#8217;t really have</p></blockquote>
<p>Sounds pretty harsh, doesn&#8217;t it? Personally I think it&#8217;s all bunch of bollocks! I think problem does exist and OpenID is part of a solution. Fortunately <a title="Is OpenID really that bad" href="http://programmers.stackexchange.com/questions/50138/is-openid-really-that-bad">Stack Overflow community</a>, which opinion I highly value, has not yet  ruled out the OpenID. In this post I intend to revisit the &#8216;problem that most people don&#8217;t really have&#8217; and take a fresh look at  OpenID-based implementation.</p>
<h3><span id="more-116"></span></h3>
<h3>A common problem</h3>
<p>I believe that nowadays average, day-to-day Internet user has to find a method to store tens, sometimes hundreds of authentication details. Most resolve to re-using the same password(s), using a password manager or using a &#8220;method&#8221;  for password generation. Either way <strong>when presented with a registration form for a new service, users are reluctant</strong>. They start to ask questions: &#8220;Do I really need to post that opinion online?&#8221;, &#8220;Are they going to send me spam?&#8221;, &#8220;Can I be bothered to remember another login/password combination&#8221;, &#8220;Do I have time to wait for the confirmation email?&#8221; etc. This is unpleasant for a first-time visitor who wants to quickly see what is your service about. It also lowers your conversion rate. Various implementations of a federated login mechanism have been devised or adapted as a solution to this problem and OpenID is one of them. While it might not be perfect it is a viable alternative to standard login/password combination, especially if used as <strong>part of solution and not as a solution on its own</strong>. And only if  implemented right.</p>
<h3>Doing it Right</h3>
<p>To define what I consider right implementation I will first explain what&#8217;s definitely should be avoided &#8211; a plain  &#8217;enter your OpenID&#8217; box is simply wrong. It&#8217;s wrong because it&#8217;s very confusing for users who are not familiar with OpenID. <strong>Average user probably already has an account with an OpenID provider</strong> and is not even aware of that! Major online service providers such as <strong> Google, Yahoo and AOL all can act as OpenID Identity Providers</strong> &#8211; if your visitor has an account with any of these guys, it means he already has an OpenID account. So let them know! Rather than asking for OpenID identifier, ask your visitor to log in with any of these providers.</p>
<p>I&#8217;ve already seen couple of examples of a good implementation of a federated authorization in the web and, despite of what people at Quora say, most of these make use of OpenID among other methods.  I believe that <a title="springpad" href="http://springpadit.com/home/" target="_blank">SpringPad</a> has got it almost right, the only thing I don&#8217;t really like is the fact that they put so much emphasis on a classic login/registration and so little on the actual federated login capability. Personally I would make it more obvious that you don&#8217;t really need to register. Also Stack Overflow implementation is not bad for more &#8216;geeky&#8217; audience but forces users to register with some arbitrary third party provider if they don&#8217;t have an OpenID or Facebook account which might discourage some potential visitors. Also there is no single sign-on between all <a title="Stack Exchange" href="http://stackexchange.com/" target="_blank">Stack Exchange</a> Q&amp;A sites (you need to login to each of these separately), which is pretty disappointing.</p>
<h3>My approach</h3>
<p>I think that a decent implementation would:</p>
<ol>
<li>Offer access with multiple <strong>popular</strong>, <strong>respectable</strong> (also trustworthy) and <strong>recognizable</strong> providers such as Google, Yahoo, Facebook, Twitter</li>
<li>Offer a <strong>fallback mechanism</strong> &#8211; alternative for those who can&#8217;t or don&#8217;t want to use federated login</li>
<li><strong>Don&#8217;t ask ANY questions</strong> or confirmation if user logs in with a third party provider. In particular don&#8217;t ask to create an account.</li>
<li>Be able to<strong> spot user that has previously logged in with another provider</strong>. Allow manual associations of additional third party accounts (i.e. user has logged in with Google, but wants to associate their Facebook with their profile)</li>
<li>Explain <strong>why do your users need to use a third-party provider</strong> to login and what are the benefits</li>
<li>Make a promise <strong>not to spam</strong></li>
</ol>
<p>&nbsp;</p>
<p>I&#8217;ve been working on implementation that would meet the requirements listed above and as of today my code covers items 1 through 3 from the list above.  I&#8217;ve setup a <a title="A decent single sign-on implementation" href="http://openid.doppnet.com" target="_blank">working demo</a> and shared code <a title="Code for a decent single sing-on implementation on GitHub" href="https://github.com/tnajdek/single-sign-on-implementation" target="_blank">on github</a> so feel free to grab yourself a copy or even better fork me! &#8211; I would love to see this code brought to completion.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://doppnet.com/2011/03/a-decent-federated-login-implementation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Playing with web sockets</title>
		<link>http://doppnet.com/2011/03/playing-with-web-sockets/</link>
		<comments>http://doppnet.com/2011/03/playing-with-web-sockets/#comments</comments>
		<pubDate>Mon, 14 Mar 2011 01:13:22 +0000</pubDate>
		<dc:creator>Tom Najdek</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://doppnet.com/?p=82</guid>
		<description><![CDATA[The WebSocket is quite a cool concept that might gradually affect web as we know it. Currently to implement a real-time chat (Facebook and Gmail have one) you need to employ one of the xhr-based hacks aka COMET (i.e. long polling, xhr multipart etc.) and while these techniques will work, there are couple of problems. [...]]]></description>
			<content:encoded><![CDATA[<p>The WebSocket is quite a cool concept that might gradually affect web as we know it. Currently to implement a real-time chat (Facebook and Gmail have one) you need to employ one of the xhr-based hacks aka COMET (i.e. long polling,  xhr multipart etc.) and while these techniques will work, there are couple of problems. First of all HTTP protocol has not been designed for sustained client-server connection &#8211; keeping the connection open creates a performance penalty on each side. Secondly this is not a true two-way communication protocol, a lag of couple of hundreds of milliseconds in one direction is pretty much unavoidable. I could name couple of more issues related to the use of COMET but that&#8217;s not the point. Point is Websockets are coming for a rescue! Well more like slowly crawling than coming, but still on the horizon.</p>
<p><span id="more-82"></span></p>
<p>With my WebSocket experiment I&#8217;ve decided to go a little bit beyond a &#8216;chat application&#8217; and develop a game using only WebSockets and HTML. I (incorrectly) assumed that a simple <a title="Tic Tac Toe" href="http://en.wikipedia.org/wiki/Tic-tac-toe" target="_blank">tic-tac-toe</a> game (aka noughts and crosses) would be cool to begin my journey with Websockets. I don&#8217;t like reinventing the wheel so I&#8217;ve picked up a first <a title="php websockets" href="http://code.google.com/p/phpwebsocket/" target="_blank">php websocket library I could find</a> and begin implementing the tic-tac-toe game. While I&#8217;ve failed to come up with a truly playable game I&#8217;ve learned couple of important lessons:</p>
<ul>
<li>A tic-tac-toe game is effectively a <strong>turn based</strong> game thus it doesn&#8217;t really benefit from WebSockets. Halfway through I&#8217;ve made a decision to convert my game into a red-and-blue squares game.</li>
<li>PHP might not be best suited for socket-based programming.</li>
<li>At this moment effectively ONLY Chrome supports web sockets!
<ul>
<li>Firefox 4 and Opera comes with the<a href="http://hacks.mozilla.org/2010/12/websockets-disabled-in-firefox-4/" target="_blank"> support for WebSockets disabled</a> due to a potential security issue</li>
<li>IE9 <a href="http://www.quora.com/Does-IE9-Support-WebSockets" target="_blank">doesn&#8217;t support WebSockets</a>. I mean <a href="http://blogs.msdn.com/b/interoperability/archive/2010/12/21/introducing-the-websockets-prototype.aspx" target="_blank">it does</a> but only through a Silverlight object so you need extra JavaScript-Silverlight bridge. So it doesn&#8217;t.</li>
</ul>
</li>
<li>For browsers that do not support WebSockets yet, there is a <a href="https://github.com/gimite/web-socket-js" target="_blank">nifty flash compatibility wrapper</a> (it will use native WebSockets if available, fall back to use WebSockets through flash)</li>
</ul>
<p>&nbsp;</p>
<p>Eventually I got my red-and-blue-square prototype game into kind of playable state but it&#8217;s far from complete. After each &#8216;game&#8217; you need to truncate a table in the database and also there is no logic to understand the win/lost condition thus you can play forever. Not a particularly useful piece of code but I decided to share it nevertheless, you can <a title="Red and Blue squares game" href="https://github.com/tnajdek/red-and-blue-squares-game" target="_blank">grab it on github</a>.</p>
<p>I&#8217;m now working on a <a href="http://en.wikipedia.org/wiki/Tron_(video_game)" target="_blank">TRON</a> game, expect update soon!</p>
]]></content:encoded>
			<wfw:commentRss>http://doppnet.com/2011/03/playing-with-web-sockets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>24861% performance boost in Perl</title>
		<link>http://doppnet.com/2011/03/how-to-gain-24861-performance-boost-in-perl/</link>
		<comments>http://doppnet.com/2011/03/how-to-gain-24861-performance-boost-in-perl/#comments</comments>
		<pubDate>Tue, 01 Mar 2011 20:15:53 +0000</pubDate>
		<dc:creator>Tom Najdek</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://doppnet.com/?p=17</guid>
		<description><![CDATA[Ok, I admit the title might sound a little bold. Recently as a part of a bigger project we&#8217;ve been working on a piece of software that would need to generate an extensive, complex and nested hash structure, then compare it with another, previously cached version of the same structure and decide whether it&#8217;s the [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, I admit the title might sound a little bold.</p>
<p>Recently as a part of a bigger project we&#8217;ve been working on a piece of software that would need to generate an extensive, complex and nested hash structure, then compare it with another, previously cached version of the same structure and decide whether it&#8217;s the same or different. The rest of the system has been written in perl thus logically we&#8217;ve selected perl for the implementation. Our hash comparison tool would be executed every 30 seconds and it  had to perform well on a rather busy system. We knew that a brute-force approach of comparing each key and value recursively would definitely cause performance issues. It was time to do some cheating!</p>
<p><span id="more-17"></span></p>
<h3>Cheating in Perl</h3>
<p>Fast forward to my findings, here is a table comparing various solutions for hash comparison:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">               Rate  testdeep comparedata    dumper freezthaw storable    jsonxs
testdeep    0.152/s        --        -90%      -93%      -94%     -99%     -100%
comparedata  1.45/s      855%          --      -29%      -42%     -87%      -96%
dumper       2.04/s     1245%         41%        --      -18%     -82%      -95%
freezthaw    2.50/s     1547%         73%       22%        --     -78%      -93%
storable     11.3/s     7329%        678%      452%      351%       --      -70%
jsonxs       37.9/s    24861%       2514%     1755%     1415%     236%        --</pre></div></div>


<div id="easyChartDivadb8001" style='width:100%;'  style='text-align:center;' align='center'>
<!-- Easy Chart Builder by dyerware -->
<img id="easyChartDivadb8001_img" style='text-align:center;float:center;' alt='dyerware.com' title=''  align='center' border='0' />

</div>
<script type="text/javascript">
//<![CDATA[
wpEasyChart.wpNewChart("easyChartDivadb8001", {"type":"horizbar","width":200,"height":"100","title":"Hash Comparision in Perl","minaxis":"","groupnames":"Iterations\/s","groupcolors":"0070C0,FFFF00,FF0000,00CC00,A3A3A3,007070,00FFFF,CC7000,00CC70,CC0070,7000CC,A370CC","valuenames":"testdeep,comparedata,dumper,freezethaw,storable,jsonxs","group1values":"0.152, 1.45, 2.04, 2.50, 11.3, 37.9","group2values":"0,0,0","group3values":"0,0,0","group4values":"0,0,0","group5values":"0,0,0","group6values":"0,0,0","group7values":"0,0,0","group8values":"0,0,0","group9values":"0,0,0","group10values":"0,0,0","group11values":"0,0,0","group12values":"0,0,0","group1markers":"","group2markers":"","group3markers":"","group4markers":"","group5markers":"","group6markers":"","group7markers":"","group8markers":"","group9markers":"","group10markers":"","group11markers":"","group12markers":"","markercolor":"FFFF00","imagealtattr":"dyerware.com","imagetitleattr":"","hidechartdata":true,"chartcolor":"FFFFFF","chartfadecolor":"DDDDDD","datatablecss":"hentry easyChartDataTable","imgstyle":"text-align:center;float:center;","watermark":"","watermarkvert":"","watermarkcolor":"A0BAE9","currency":"","precision":"","grid":false,"axis":"both"});
//]]&gt;
</script>
<p><small>Benchmark performed by running 100 iterations of each comparison subroutine using two identical hashes  occupying approximately 4MB of memory each. Tested on a server with 8GB of RAM and powered by a 64bit, 2Ghz AMD Opteron 2212 CPU</small></p>
<ol>
<li>Solution marked as <strong>testdeep </strong>above  is using the eq<em>_deeply</em> method from the <a title="Test::Deep" href="http://search.cpan.org/~rjbs/Test-Deep-0.108/lib/Test/Deep.pod" target="_blank">Test::Deep</a> package.</li>
<li>Solution marked as <strong>comparedata</strong> above is using the <em>Compare </em>method from the <a title="Data::Compare" href="http://search.cpan.org/~dcantrell/Data-Compare-1.22/lib/Data/Compare.pm" target="_blank">Data::Compare</a> package.</li>
<li>Solution marked as <strong>freezethaw </strong>above is using the <em>freeze </em>method from the <a title="FreezeThaw" href="http://search.cpan.org/~ilyaz/FreezeThaw-0.5001/FreezeThaw.pm" target="_blank">FreezeThaw</a> package on both hashes then compares strings returned by this method.</li>
<li>Solution marked as <strong>storable </strong>above is using the <em>freeze</em> method from the <a title="Storable" href="http://search.cpan.org/~ams/Storable-2.25/Storable.pm" target="_blank">Storable</a> package on both hashes, then compares strings returned by this method. In order to achieve comparable results the  <em>$Storable::canonical</em> property is set to be true.</li>
<li>Solution marked as <strong>jsonxs </strong>is using the <em>encode</em> method from the <a title="JSON::XS" href="http://search.cpan.org/~mlehmann/JSON-XS-2.3/XS.pm" target="_blank">JSON::XS</a> package on both hashes, then compares strings returned by this method. Before the encode method can be applied, module needs to be configured in order to make sure that it always produces identical output. I&#8217;ve have used the following method in my benchmark:</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$json</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSON<span style="color: #339933;">::</span><span style="color: #006600;">XS</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$json</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">indent</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$json</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">space_after</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$json</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">space_before</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$json</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">canonical</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">return</span> <span style="color: #0000ff;">$json</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">encode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$hash</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">eq</span> <span style="color: #0000ff;">$json</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">encode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$hash2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>So why did JSON::XS perform  so much better than any other comparison/serialization method? First of all JSON format is quite good for serialization/deserialization performance (not so much for the size). But why it&#8217;s really so much faster is the fact that all the actual heavy lifting is done in a nicely-optimized code written in C.  Perl is just a wrapper using an <a title="XS" href="http://en.wikipedia.org/wiki/XS_(Perl)" target="_blank">XS Interface</a>.</p>
<h3>More cheats?</h3>
<p>There are many more Perl XS libraries available on <a title="CPAN" href="http://www.cpan.org/" target="_blank">CPAN </a>that can give a decent performance boost to your applications.  Aside from <em>JSON::XS </em>we&#8217;ve been using two other XS packages:  <a title="CVS_XS" href="http://search.cpan.org/~hmbrand/Text-CSV_XS-0.80/CSV_XS.pm" target="_blank">CSV_XS</a> for parsing/generation of comma-separated values and <a title="YAML::XS" href="http://search.cpan.org/~ingy/YAML-LibYAML-0.34/lib/YAML/XS.pm" target="_blank">YAML::XS</a> for YAMLS serialization. Furthermore if you can think of any piece of functionality that would benefit from a C-based implementation, you can <a title="Perl XS" href="http://perldoc.perl.org/perlxs.html" target="_blank">create your own Perl XS</a> implementation thought it is not very straight forward and there is certain amount of hacking required.</p>
]]></content:encoded>
			<wfw:commentRss>http://doppnet.com/2011/03/how-to-gain-24861-performance-boost-in-perl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

