<?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>bjelic.net</title> <atom:link href="http://www.bjelic.net/feed/" rel="self" type="application/rss+xml" /><link>http://www.bjelic.net</link> <description>Serendipity running machine progressing toward accomplishments.</description> <lastBuildDate>Thu, 17 May 2012 19:14:29 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>Signal reception filter</title><link>http://www.bjelic.net/2012/04/17/digital-life-2/signal-reception-filter/</link> <comments>http://www.bjelic.net/2012/04/17/digital-life-2/signal-reception-filter/#comments</comments> <pubDate>Tue, 17 Apr 2012 14:19:33 +0000</pubDate> <dc:creator>Bojan Bjelić</dc:creator> <category><![CDATA[Digital Life]]></category> <guid
isPermaLink="false">http://www.bjelic.net/?p=1360</guid> <description><![CDATA[Startups, Moebius, Clouds, Digital ecosystems.]]></description> <content:encoded><![CDATA[<ol
class="signal-links"><li>Frighteningly Ambitious Startup Ideas <a
href="http://paulgraham.com/ambitious.html">http://paulgraham.com/ambitious.html</a></li><li>Wow, dawn of a new era.<br
/><div
class="ModernMediaTweetShortcode"><blockquote
class="twitter-tweet" width="400"><p>RT @<a
href="https://twitter.com/jongalloway">jongalloway</a>: Internet Traffic is now 51% Non-Human <a
href="http://t.co/mjFvqhfa" title="http://www.nextnature.net/2012/03/internet-traffic-is-now-51-non-human/">nextnature.net/2012/03/intern…</a> via @<a
href="https://twitter.com/aeoth">aeoth</a></p>&mdash; Bojan Bjelic (@bojanbjelic) <a
href="https://twitter.com/bojanbjelic/status/181686519818498049" data-datetime="2012-03-19T10:20:16+00:00">March 19, 2012</a></blockquote></div></li><li>R.I.P. Jean “Moebius” Giraud (1938-2012). Always have been amazed by his stories and art.<br
/><div
class="ModernMediaTweetShortcode"><blockquote
class="twitter-tweet" width="400"><p>RT @<a
href="https://twitter.com/Glinner">Glinner</a>: Great post by @<a
href="https://twitter.com/timmaughan">timmaughan</a> showing the influence of Moebius on modern science fiction <a
href="http://t.co/jaFYiFkr" title="http://www.tor.com/blogs/2012/03/moebius-the-visionarys-visionary">tor.com/blogs/2012/03/…</a></p>&mdash; Bojan Bjelic (@bojanbjelic) <a
href="https://twitter.com/bojanbjelic/status/180658040238915585" data-datetime="2012-03-16T14:13:27+00:00">March 16, 2012</a></blockquote></div><br
/><div
class="ModernMediaTweetShortcode"><blockquote
class="twitter-tweet" width="400"><p>Moebius at work. <a
href="http://t.co/fIKba0fH" title="http://blog.drawn.ca/post/19070254436/r-i-p-jean-moebius-giraud-1938-2012-heres-a">blog.drawn.ca/post/190702544…</a> via @<a
href="https://twitter.com/drawn">drawn</a></p>&mdash; Bojan Bjelic (@bojanbjelic) <a
href="https://twitter.com/bojanbjelic/status/178601846712172544" data-datetime="2012-03-10T22:02:53+00:00">March 10, 2012</a></blockquote></div></li><li>The Pirate Bay to Fly &#8216;Server Drones&#8217; to Avoid Law Enforcement (redefining “cloud computing”)<br
/> <a
href="http://www.usnews.com/news/articles/2012/03/19/the-pirate-bay-to-fly-server-drones-to-avoid-law-enforcement">http://www.usnews.com/news/articles/2012/03/19/the-pirate-bay-to-fly-server-drones-to-avoid-law-enforcement</a></li><li>Tips to improve your online stealth mode<br
/> <a
href="https://www.eff.org/wp/six-tips-protect-your-search-privacy">Six Tips to Protect Your Search Privacy | Electronic Frontier Foundation</a></li><li>Interesting and innovative approach for a phone manual.<p><iframe
src="http://player.vimeo.com/video/26489936" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></p><li><img
class="alignleft" src="http://s3-ak.buzzfed.com/static/enhanced/terminal05/2012/3/27/13/enhanced-buzz-wide-15793-1332868671-55.jpg" alt="" width="178" height="119" />33 Stunning Photos Of Our Amazing Planet Earth Taken By A Guy In Space<br
/> <a
href="http://www.buzzfeed.com/gavon/33-stunning-photos-of-earth-taken-by-an-astronaut">http://www.buzzfeed.com/gavon/33-stunning-photos-of-earth-taken-by-an-astronaut</a></li><li>The (so so hard) problem of estimation.<br
/><div
class="ModernMediaTweetShortcode"><blockquote
class="twitter-tweet" width="400"><p>I'm Sure It Will Only Take You A Few Days To Code <a
href="http://t.co/Nd6YGqnB" title="http://post.ly/6U8Cs">post.ly/6U8Cs</a> via @<a
href="https://twitter.com/danshipper">danshipper</a></p>&mdash; Bojan Bjelic (@bojanbjelic) <a
href="https://twitter.com/bojanbjelic/status/187915066811756545" data-datetime="2012-04-05T14:50:17+00:00">April 5, 2012</a></blockquote></div></li><li>Amazon (<a
href="http://hackerne.ws/item?id=2971521">a deployment every 11.6 seconds</a>), Etsy (a new developer <a
href="http://codeascraft.etsy.com/2011/02/04/how-does-etsy-manage-development-and-operations/">commits to production on day 1</a>), and Flickr (they deployed <a
href="http://code.flickr.com/">97 times this week</a>) (!!)<br
/><div
class="ModernMediaTweetShortcode"><blockquote
class="twitter-tweet" width="400"><p>RT @<a
href="https://twitter.com/OdeToCode">OdeToCode</a>: The Bar Is Even Higher Now <a
href="http://t.co/53o7Nkos" title="http://bit.ly/I7aBQA">bit.ly/I7aBQA</a></p>&mdash; Bojan Bjelic (@bojanbjelic) <a
href="https://twitter.com/bojanbjelic/status/187896531305775104" data-datetime="2012-04-05T13:36:38+00:00">April 5, 2012</a></blockquote></div></li></ol> ]]></content:encoded> <wfw:commentRss>http://www.bjelic.net/2012/04/17/digital-life-2/signal-reception-filter/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Signal Links</title><link>http://www.bjelic.net/2012/02/26/digital-life-2/signal-links-5/</link> <comments>http://www.bjelic.net/2012/02/26/digital-life-2/signal-links-5/#comments</comments> <pubDate>Sun, 26 Feb 2012 14:16:49 +0000</pubDate> <dc:creator>Bojan Bjelić</dc:creator> <category><![CDATA[Digital Life]]></category> <category><![CDATA[archive]]></category> <category><![CDATA[links]]></category> <category><![CDATA[posts]]></category> <category><![CDATA[signal]]></category> <category><![CDATA[tweets]]></category> <guid
isPermaLink="false">http://www.bjelic.net/?p=1271</guid> <description><![CDATA[Interesting stuff I came across from October 2011 to February 2012.]]></description> <content:encoded><![CDATA[<ol
class="signal-links"><li><div
class="ModernMediaTweetShortcode"><blockquote
class="twitter-tweet" width="400"><p>Satellite images of Earth show roads, air traffic, cities at night and internet cables <a
href="http://t.co/V7fJwraV" title="http://tgr.ph/qSgJDR">tgr.ph/qSgJDR</a></p>&mdash; Dietrich Groundsel (@dgroundsel) <a
href="https://twitter.com/dgroundsel/status/127434702461214720" data-datetime="2011-10-21T17:22:55+00:00">October 21, 2011</a></blockquote></div><br
/> <img
class="alignleft" title="Europe connected satellite image" src="http://i.telegraph.co.uk/multimedia/archive/02032/rail-road-europe_2032284i.jpg" alt="Major road and rail networks in Europe, along with transmission line and underwater cable data, superimposed over satellite images of cities illuminated at night" width="165" height="165" />It&#8217;s awesome when you see how interconnected the world is now. <a
href="http://www.telegraph.co.uk/science/picture-galleries/8838796/Satellite-images-of-Earth-show-roads-air-traffic-cities-at-night-and-internet-cables.html">Permalink</a></li><li><div
class="ModernMediaTweetShortcode"><blockquote
class="twitter-tweet" width="400"><p>Expired patent of the day: Lego <a
href="http://t.co/8Bhjot28" title="http://goo.gl/idhb3">goo.gl/idhb3</a></p>&mdash; Boing Boing (@BoingBoing) <a
href="https://twitter.com/BoingBoing/status/127477584052232192" data-datetime="2011-10-21T20:13:19+00:00">October 21, 2011</a></blockquote></div><br
/> The patent on Lego has expired. <a
href="http://boingboing.net/2011/10/21/expired-patent-of-the-day-lego.html?utm_source=dlvr.it&amp;utm_medium=twitter&amp;dlvrit=36761">Permalink</a></li><li><div
class="ModernMediaTweetShortcode"><blockquote
class="twitter-tweet" width="400"><p>It’s Official: To Protect Baby’s Brain, Turn Off TV | Wired Science | <a
href="http://t.co/g2YdX0Kk" title="http://Wired.com">Wired.com</a> <a
href="http://t.co/5f91ree7" title="http://www.wired.com/wiredscience/2011/10/infant-tv-guidelines/">wired.com/wiredscience/2…</a> via @<a
href="https://twitter.com/9brandon">9brandon</a></p>&mdash; Bojan Bjelic (@bojanbjelic) <a
href="https://twitter.com/bojanbjelic/status/127818231489634305" data-datetime="2011-10-22T18:46:55+00:00">October 22, 2011</a></blockquote></div></li><li>I have noticed the TV mesmerizing kids effect before (I don&#8217;t mean it in a good way). <a
href="http://www.wired.com/wiredscience/2011/10/infant-tv-guidelines/">Permalink</a></li><li>Vertical centering with CSS has always been a pain. <a
href="http://jsfiddle.net/chriscoyier/hJtpF/">Permalink</a> (<a
href="http://twitter.com/#!/chriscoyier/status/127808488985477120">Tweet</a>).</li><li><div
class="ModernMediaTweetShortcode"><blockquote
class="twitter-tweet" width="400"><p>Up and Down the Ladder of Abstraction <a
href="http://t.co/rJokzwx0" title="http://worrydream.com/LadderOfAbstraction">worrydream.com/LadderOfAbstra…</a> via @<a
href="https://twitter.com/worrydream">worrydream</a></p>&mdash; Bojan Bjelic (@bojanbjelic) <a
href="https://twitter.com/bojanbjelic/status/128585386103545856" data-datetime="2011-10-24T21:35:19+00:00">October 24, 2011</a></blockquote></div><br
/> Wonderfully made.</li><li>Very important: &#8220;Computer programs and languages cannot be copyrighted, says European court advisor&#8221; <a
href="http://news.techworld.com/sme/3321685/computer-programs-and-languages-cannot-be-copyrighted-says-european-court-advisor/">Permalink</a> (<a
href="https://twitter.com/#!/DPleskonjic/status/141859556497162240">Tweet</a>)</li><li><div
class="ModernMediaTweetShortcode"><blockquote
class="twitter-tweet" width="400"><p>All the time spent on supporting 10-year old browsers would be better spent on making awesome stuff on new browsers.</p>&mdash; Thomas Fuchs (@thomasfuchs) <a
href="https://twitter.com/thomasfuchs/status/134596038773313536" data-datetime="2011-11-10T11:39:30+00:00">November 10, 2011</a></blockquote></div><br
/> Completely true &#8211; the pain of being an web developer.</li><li>Superhuman Imagination &#8211; Vernor Vinge on science fiction, the Singularity, and the state <a
href="http://reason.com/archives/2007/05/04/superhuman-imagination">Permalink</a> (<a
href="https://twitter.com/#!/bojanbjelic/status/130698136158089216">Tweet</a>)</li><li><div
class="ModernMediaTweetShortcode"><blockquote
class="twitter-tweet" width="400"><p>Coders are special. "We are expected to know how to do things we've never done before and estimate how long they will take." @<a
href="https://twitter.com/ultrasaurus">ultrasaurus</a></p>&mdash; J'aime Ohm (@jaimeohm) <a
href="https://twitter.com/jaimeohm/status/129284508087357440" data-datetime="2011-10-26T19:53:23+00:00">October 26, 2011</a></blockquote></div><br
/> Coders are truly special. :)</li><li>Interesting analysis on how the devices influence us, and our memories &#8211; <a
href="http://www.nytimes.com/2012/01/29/magazine/what-happens-when-data-disappears.html?_r=1&amp;pagewanted=all">The Dilemma of Being a Cyborg</a>.</li><li><div
class="ModernMediaTweetShortcode"><blockquote
class="twitter-tweet" width="400"><p>!!! The end of an era: Internet Explorer drops below 50% of Web usage <a
href="http://t.co/WBjZCFi0" title="http://arstechnica.com/microsoft/news/2011/11/the-end-of-an-era-internet-explorer-drops-below-50-percent-of-web-usage.ars">arstechnica.com/microsoft/news…</a></p>&mdash; Bojan Bjelic (@bojanbjelic) <a
href="https://twitter.com/bojanbjelic/status/131865028872765441" data-datetime="2011-11-02T22:47:27+00:00">November 2, 2011</a></blockquote></div><br
/> The end of an era: Internet Explorer drops below 50% of Web usage <a
href="http://arstechnica.com/microsoft/news/2011/11/the-end-of-an-era-internet-explorer-drops-below-50-percent-of-web-usage.ars">Permalink</a></li></ol> ]]></content:encoded> <wfw:commentRss>http://www.bjelic.net/2012/02/26/digital-life-2/signal-links-5/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Mozilla Firefox extensions</title><link>http://www.bjelic.net/2012/02/15/productivity/mozilla-firefox-extensions/</link> <comments>http://www.bjelic.net/2012/02/15/productivity/mozilla-firefox-extensions/#comments</comments> <pubDate>Tue, 14 Feb 2012 23:21:04 +0000</pubDate> <dc:creator>Bojan Bjelić</dc:creator> <category><![CDATA[Digital Life]]></category> <category><![CDATA[Productivity]]></category> <category><![CDATA[browsing]]></category> <category><![CDATA[digital life]]></category> <category><![CDATA[extensions]]></category> <guid
isPermaLink="false">http://www.bjelic.net/?p=781</guid> <description><![CDATA[Nowadays the browser extensions shape our browsing experience. Here is a (updated) list of extensions I use in Mozilla Firefox.]]></description> <content:encoded><![CDATA[<p><img
class="alignleft size-full wp-image-1306" title="Add-ons for Firefox 2012-02-16 10-39-25 --" src="http://www.bjelic.net/wp-content/uploads/Add-ons-for-Firefox-2012-02-16-10-39-25-.png" alt="Firefox add-ons site image" width="305" height="150" />Nowadays the browser extensions shape our browsing experience. Here is a list of extensions I use in <a
class="outer" href="http://www.mozilla.com/en-US/firefox/central/">Mozilla Firefox</a>.</p><p><strong></strong>I have also made public the list of my favorite addons on the <a
title="My favorite addons on Mozilla website." href="https://addons.mozilla.org/en-US/firefox/collections/bojanbjelic/favorites/">Mozilla website</a>.</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><ul><li><a
class="outer" href="http://getfirebug.com/">Firebug</a> &#8211; The best thing for web development, irreplaceable really.</li><li><a
class="outer" title="Feedly" href="http://www.feedly.com/">Feedly</a> &#8211; My favorite <abbr
title="Really Simple Syndication">RSS</abbr> reader and sharing toolbox. If you don&#8217;t use it, give it a go &#8211; I am still amazed.</li><li><a
href="https://addons.mozilla.org/en-US/firefox/addon/readability/">Readability</a> &#8211; Convert the page to a more readable format and save to read later (on other devices as well). Good stuff.</li><li><a
class="outer" href="http://www.xuldev.org/firegestures/">Firegestures</a> &#8211; Execute browser commands using mouse gestures for faster browsing.</li><li><a
class="outer" href="https://mozillalabs.com/ubiquity/">AdBlock Plus</a> &#8211; No annoying banners and ads, just content.</li><li><a
href="https://addons.mozilla.org/en-US/firefox/addon/awesome-screenshot-capture-/">Awesome Screenshot &#8211; Capture and Annotate</a> &#8211; The name pretty much explains it all.</li><li><a
class="outer" href="http://www.screengrab.org/">HTML Validator</a> &#8211; Run HTML / XHTML validation in the browser.</li><li><a
class="outer" href="http://www.softwareishard.com/blog/firecookie/">Firecookie</a> &#8211; Nice extension to Firebug dealing with cookies.</li><li><a
class="outer" href="http://developer.yahoo.com/yslow/">YSlow</a> &#8211; Firebug extension by Yahoo team with page loading performance analysis.</li><li><a
class="outer" href="http://www.colorzilla.com/firefox/">ColorZilla</a> &#8211; Color picker, palette generator etc.</li><li><a
class="outer" href="http://quickjavaplugin.blogspot.com/">QuickJava</a> &#8211; The name is a bit misleading, it provides status bar buttons to easily enable / disable JavaScript, Java, Flash, SilverLight, Images and CSS Styles.</li><li><a
class="outer" href="http://ieview.mozdev.org/">IE View</a> &#8211; Just one click to view the same URL in IE.</li></ul><h2>Obsolete</h2><p>Some extensions have become obsolete or I have started using another instead, but that doesn&#8217;t mean they are not awesome anymore. :)</p><ul><li><em><a
href="https://mozillalabs.com/ubiquity/">Ubiquity</a></em> &#8211; Task-centric web browsing, awesome stuff, too bad that it&#8217;s not in development anymore.</li><li><em><a
href="http://www.xmarks.com/">XMarks</a></em> &#8211; Bookmarks synchronization &#8211; not required anymore if you use only Firefox, but can synch across browsers.</li><li><em><a
href="http://www.screengrab.org/">Screengrab!</a></em> &#8211; Save the page as image.</li></ul><p>Share your favorite extensions in the comments, and if you like to improve your browsing experience further have a look at my post on <a
href="http://www.bjelic.net/2010/11/13/tutorials/searching-from-browser-firefox-quick-searches-and-chrome-search-engines/" title="Searching from browser &#8211;  Firefox quick searches and Chrome search engines" rel="bookmark">Firefox quick searches</a>.</p> ]]></content:encoded> <wfw:commentRss>http://www.bjelic.net/2012/02/15/productivity/mozilla-firefox-extensions/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Signal Links</title><link>http://www.bjelic.net/2011/12/05/digital-life-2/signal-links-4/</link> <comments>http://www.bjelic.net/2011/12/05/digital-life-2/signal-links-4/#comments</comments> <pubDate>Mon, 05 Dec 2011 13:46:37 +0000</pubDate> <dc:creator>Bojan Bjelić</dc:creator> <category><![CDATA[Digital Life]]></category> <category><![CDATA[archive]]></category> <category><![CDATA[links]]></category> <category><![CDATA[posts]]></category> <category><![CDATA[signal]]></category> <category><![CDATA[tweets]]></category> <guid
isPermaLink="false">http://www.bjelic.net/?p=1252</guid> <description><![CDATA[Interesting stuff I came across from 16. August 2011 to 20. October 2011.]]></description> <content:encoded><![CDATA[<p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/105016763992911872"]</p><p>Interesting thinking, but I would say that the world is embracing and running on software. <a
href="http://online.wsj.com/article/SB10001424053111903480904576512250915629460.html">Permalink</a></p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/105972790166953984"]</p><p>A bit more on the same theme&#8230; <a
href="http://www.bbc.co.uk/news/technology-14306146">Permalink</a></p><p>[blackbirdpie url="http://twitter.com/#!/smashingmag/status/110411824901525504"]</p><p>Beautiful and informative infographic. <a
href="http://evolutionofweb.appspot.com/">Permalink</a></p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/110821540127440896"]</p><p>Don&#8217;t just wait for things to happen. <a
href="http://www.flickr.com/photos/blackbeltjones/3365682994/">Permalink</a></p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/113169640980627456"]</p><p>The term &#8220;infini-surf&#8221; is just awesome. <a
href="http://www.nytimes.com/2011/09/12/technology/youtube-founders-aim-to-revamp-delicious.html?_r=1&amp;pagewanted=all?src=tp">Permalink</a></p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/113213670288400384"]</p><p>Machines are taking over? (Not yet) <a
href="http://www.ritholtz.com/blog/2011/09/attention-human-trader-you-are-no-longer-needed/">Permalink</a></p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/118234567588052992"]</p><p>Generating images from thoughts. <a
href="http://newscenter.berkeley.edu/2011/09/22/brain-movies/">Permalink</a></p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/119374359914758144"]</p><p>JavaScript is increasingly becoming first-class language, used to solve &#8220;real&#8221; problems instead of just web page interaction. <a
href="http://sylvainzimmer.com/2011/09/06/chessathome-building-largest-chess-ai/">Permalink</a></p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/122936327061778432"]</p><p>Since I don&#8217;t think I&#8217;ll become a spaceman &#8211; YouTube it is. <a
href="http://www.youtube.com/watch?v=rvDqoxMUroA&amp;feature=player_detailpage#t=173s">Permalink</a></p><p>[blackbirdpie url="http://twitter.com/#!/zen_habits/status/126052272059842560"]</p><p>I can say that this is the way to changing things around. <a
href="http://zenhabits.net/1/">Permalink</a></p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/127116399876378624"]</p><p>You said it Woz. <a
href="http://oninnovation.com/innovators/detail.aspx?innovator=Wozniak">Permalink</a></p> ]]></content:encoded> <wfw:commentRss>http://www.bjelic.net/2011/12/05/digital-life-2/signal-links-4/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Evolution Of The JavaScript Loop</title><link>http://www.bjelic.net/2011/11/16/coding/evolution-of-javascript-loop/</link> <comments>http://www.bjelic.net/2011/11/16/coding/evolution-of-javascript-loop/#comments</comments> <pubDate>Wed, 16 Nov 2011 15:13:56 +0000</pubDate> <dc:creator>Bojan Bjelić</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[Productivity]]></category> <category><![CDATA[code]]></category> <category><![CDATA[JavaScript]]></category> <guid
isPermaLink="false">http://www.bjelic.net/?p=1221</guid> <description><![CDATA[Sometimes, the way the syntax is changing can lead to huge improvements in coding and readability. One great example is JavaScript's forEach.]]></description> <content:encoded><![CDATA[<p>Doing a bit of testing last week, I have found out that the source code for the <a
href="http://www.bjelic.net/2011/10/23/snippets/game-of-life-javascript-implementation/" title="Game Of Life JavaScript Implementation">Game Of Life JavaScript Implementation</a> is not working with Internet Explorer 7 (IE7).</p><p>It turns out that IE7 doesn&#8217;t support the <code>forEach</code> construct, and in while rewriting it, I noticed how the code becomes so much uglier and less readable, which led me to think about the programming language evolution.</p><p>Here&#8217;s an excerpt for comparison:</p><pre class="brush: jscript; title: ; notranslate">
// in case you're wandering:
// GOOD
_.neighbours.forEach(function (neighbour) {
	sum += +neighbour.alive;
});
</pre><pre class="brush: jscript; title: ; notranslate">
// BAD
for (var i = 0; i &lt; _.neighbours.length; i++) {
	sum += +_.neighbours[i].alive;
}
</pre><blockquote
class="sidenote"><p>Sometimes, the way the syntax is changing can lead to huge improvements in coding and readability. One great example is JavaScript&#8217;s forEach.</p></blockquote><p>Now, while this might not seem like a big difference, I think it&#8217;s <strong>HUGE</strong>.</p><p>Not only we need to introduce a variable to iterate, but we also need to access the array itself. This takes the focus away from the <strong>primary concern</strong>, which is the current element that we want to work with.</p><p>I prefer to just work with the current member of the array instead of focusing on <code>_.neighbours</code> in the loop.</p><p>Now consider the following more complicated example:</p><pre class="brush: jscript; title: ; notranslate">
_.cells.forEach(function (row, i) {
	row.forEach(function (cell, j) {
		neighboursY = neighbourIndexes(j);
		neighbourIndexes(i).forEach(function (x) {
			neighboursY.forEach(function (y) {
				cell.neighbours.push(_.cells[x][y]); // check this
			});
		});
	});
});
</pre><pre class="brush: jscript; title: ; notranslate">
for (i = 0; i &lt; size; i++) {
	for (j = 0; j &lt; size; j++) {
		indexesX = neighbourIndexes(i);
		indexesY = neighbourIndexes(j);
		for (k = 0; k &lt; indexesX.length; k++) {
			for (l = 0; l &lt; indexesY.length; l++) {
				_.cells[i][j].neighbours.push(_.cells[indexesX[k]][indexesY[l]]); // against this
			}
		}
	}
}
</pre><p>Do you see the difference? In the second excerpt, I feel like I can&#8217;t see the tree from the forest. :)</p><p>Another great thing is that the syntax enables the easy refactorization, just take out the function, whereas you would have to rewrite the code.</p><p>All this points to me that the evolution of programming languages is a very good thing in the means of the way we see and work with the code.</p> ]]></content:encoded> <wfw:commentRss>http://www.bjelic.net/2011/11/16/coding/evolution-of-javascript-loop/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Game Of Life JavaScript Implementation</title><link>http://www.bjelic.net/2011/10/23/coding/game-of-life-javascript-implementation/</link> <comments>http://www.bjelic.net/2011/10/23/coding/game-of-life-javascript-implementation/#comments</comments> <pubDate>Sun, 23 Oct 2011 20:24:15 +0000</pubDate> <dc:creator>Bojan Bjelić</dc:creator> <category><![CDATA[Coding]]></category> <category><![CDATA[Tutorials]]></category> <category><![CDATA[code]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[software design]]></category> <guid
isPermaLink="false">http://www.bjelic.net/?p=847</guid> <description><![CDATA[An article about implementing and redesigning the Conway's Game Of Life in JavaScript. ]]></description> <content:encoded><![CDATA[<p>Recently I have come across my old implementation of Conway&#8217;s Game Of Life in JavaScript I have played with a few years ago, had a long look and I didn&#8217;t like it.<br
/> At all.</p><h2>Conway&#8217;s Game Of Life</h2><p>In short, it&#8217;s a cellular automaton, which means that it&#8217;s a matrix of cells where they live or die based on the surroundings to produce the next generation.</p><p>The state of each cell for the next generation is based on simple rules &#8211; three surrounding cells bring life, two cells will maintain the current state, and any other number of surrounding cells will result in death.</p><p
class="clearfix"><p><img
class="alignleft size-full no-border wp-image-1077" title="Example No. 1" src="http://www.bjelic.net/wp-content/uploads/game-of-life-examples-1.png" alt="Example No. 1" width="62" height="62" />Here is an example when there will be one more living cell (green) in the next generation. Since all others have two living neighbors, they will remain alive as well. It will stagnate after that &#8211; no new ones alive, no deaths.</p><p
class="clearfix"><p><img
class="alignleft size-full no-border wp-image-1078" title="game-of-life-examples-2" src="http://www.bjelic.net/wp-content/uploads/game-of-life-examples-2.png" alt="" width="62" height="62" />This one will result in just one living cell in the second generation, and there will be none after that.</p><p
class="clearfix"><p><img
class="alignleft size-full no-border wp-image-1091" title="Example Oscillator" src="http://www.bjelic.net/wp-content/uploads/game-of-life-examples-7.png" alt="Example Oscillator" width="257" height="62" />There are also some specific configurations, such as oscillators, for example this one.</p><p
class="clearfix"><p><img
class="size-full wp-image-1085 no-border alignleft" title="Example Oscillator Marked" src="http://www.bjelic.net/wp-content/uploads/game-of-life-examples-6-marked.png" alt="Example Oscillator Marked" width="62" height="62" />Here&#8217;s an image where each cell is marked with the number of surrounding cells alive, so it might be easier to grok.</p><p>I hope this gives you an idea&#8230; Have a look at <a
title="Conway's Game of Life - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life">Wikipedia</a> for more detailed information. But let&#8217;s move on.</p><h2>The code</h2><p>But the code was the true problem, so I decided to redesign it, just for the fun of it, and I thought it could be interesting to share this &#8211; the demos, a bit about the code and the redesign process.</p><p>The demos basically do the same thing, and the new one is not much to look at (visually), but this article is about the code redesign process and decisions involved. There will be a new article soon on the subject of visual redesign, so keep a lookout.</p><p> <a
href="http://dl.dropbox.com/u/10964419/gameoflife/game0.html" class="rundemo">View the initial demo</a></p><p> <a
href="http://dl.dropbox.com/u/10964419/gameoflife/game2.html" class="rundemo">View the new demo</a></p><h2>The old</h2><p>Here&#8217;s the full source code of the old version if you like to have a look, but I&#8217;ll overview it piece by piece, so you don&#8217;t need to remember anything&#8230;</p><pre class="brush: jscript; collapse: true; light: false; title: ; toolbar: true; notranslate">
function Cell(i, j) {
	this.Alive = false;
	var el;
	var x = j;
	var y = i;
	var id = &quot;cell&quot;+ i.toString() + j.toString();
	this.Live = function() {
		this.Alive = true;
		el.className = el.className.replace(&quot;false&quot;, &quot;true&quot;);
	}
	this.Die = function() {
		this.Alive = false;
		el.className = el.className.replace(&quot;true&quot;, &quot;false&quot;);
	}
	this.ChangeState = function () {
		var tmp = this.Alive.toString()
		this.Alive = ! this.Alive;
		el.className = el.className.replace(tmp, this.Alive.toString());
	}
	this.Red = function(OnOff) {
		el.className = (OnOff) ? el.className+= &quot; red&quot; : el.className.replace(&quot; red&quot;, &quot;&quot;);
	}
	this.Green = function(OnOff) {
		el.className = (OnOff) ? el.className+= &quot; green&quot; : el.className.replace(&quot; green&quot;, &quot;&quot;);
	}
	this.Element = function (parent) {
		el = document.createElement(&quot;div&quot;);
		el.onclick = function()
		{
			parent.ChangeCellState(x, y);
		}
		el.id = id;
		el.className = &quot;cell &quot;+ this.Alive.toString();
		return el;
	}
}
function GameOfLife(Size, HTMLElementId) {
	var Size = Size;
	var Cells = new Array(Size);
	var Next = new Array(Size);
	var id = HTMLElementId;
	var i, j;
	var el = document.getElementById(id);
	el.style.width = (5*Size) + &quot;px&quot;;
	for(i=0; i&lt;Size; i++) {
		Cells[i] = new Array(Size);
		Next[i] = new Array(Size);
		for(j=0; j&lt;Size; j++) {
			Cells[i][j] = new Cell(i, j);
			el.appendChild( Cells[i][j].Element(this) );
		}
	}
	this.ChangeCellState = function(x, y) {
		Cells[y][x].ChangeState();
	}
	this.RandomStart = function() {
		var OneOrZero = 0;
		var i, j;
		for(i=0; i&lt;Size; i++) {
			for(j=0; j&lt;Size; j++) {
				OneOrZero = Math.round(Math.round(Math.random() * 2)/2);
				if (OneOrZero) Cells[i][j].ChangeState();
			}
		}
	}
	this.NextStep = function () {
		var i, j;
		for(i=0; i&lt;Size; i++) {
			for(j=0; j&lt;Size; j++) {
				var neighboursAlive = NeighboursAlive(i, j);
				switch ( neighboursAlive ) {
					case 3 : {
						Next[i][j] = true;
						break;
					}
					case 2 : {
						Next[i][j] = (Cells[i][j].Alive) ? true : false;
						break;
					}
					default : {
						Next[i][j] = false;
					}
				}
			}
		}
		for(i=0; i&lt;Size; i++)
			for(j=0; j&lt;Size; j++)
				(Next[i][j]) ? Cells[i][j].Live() : Cells[i][j].Die();
	}
	function NeighboursAlive(y, x) {
		var horizontal = new Array( (x&lt;=0) ? Size-1 : x-1, x , (x&gt;=Size-1) ? 0 : x+1 );
		var vertical = new Array( (y&lt;=0) ? Size-1 : y-1, y, (y&gt;=Size-1) ? 0 : y+1 );
		var sum = 0;
		var i, j;
		for (i=0; i&lt;3; i++)
			for (j=0; j&lt;3; j++)
				if( vertical[i]!=y || horizontal[j]!=x ) sum += (Cells[ vertical[i] ][ horizontal[j] ].Alive) ? 1 : 0;
		return sum;
	}
	var playerId;
	var playing = false;
	this.Play = function (name) {
		if (!playing) {
			this.NextStep();
			playerId = setInterval( name +&quot;.NextStep()&quot;, 100);
			playing = true;
		}
	}
	this.Stop = function () {
		if (playing) clearInterval(playerId);
		playing = false;
	}
}
</pre><p>It&#8217;s old school, no selectors, direct HTML elements injection and so on. Looks fine. But not the code.</p><h2>Redesign</h2><p>Ok, let&#8217;s start with the first entity, the cell. Here we go&#8230;</p><h3>Cell class</h3><p>Here is the original Cell class source code.</p><pre class="brush: jscript; title: ; notranslate">
function Cell(i, j) {
	this.Alive = false;
	var el;
	var x = j;
	var y = i;
	var id = &quot;cell&quot;+ i.toString() + j.toString();
	this.Live = function() {
		this.Alive = true;
		el.className = el.className.replace(&quot;false&quot;, &quot;true&quot;);
	}
	this.Die = function() {
		this.Alive = false;
		el.className = el.className.replace(&quot;true&quot;, &quot;false&quot;);
	}
	this.ChangeState = function () {
		var tmp = this.Alive.toString()
		this.Alive = ! this.Alive;
		el.className = el.className.replace(tmp, this.Alive.toString());
	}
	this.Red = function(OnOff) {
		el.className = (OnOff) ? el.className+= &quot; red&quot; : el.className.replace(&quot; red&quot;, &quot;&quot;);
	}
	this.Green = function(OnOff) {
		el.className = (OnOff) ? el.className+= &quot; green&quot; : el.className.replace(&quot; green&quot;, &quot;&quot;);
	}
	this.Element = function (parent) {
		el = document.createElement(&quot;div&quot;);
		el.onclick = function()
		{
			parent.ChangeCellState(x, y);
		}
		el.id = id;
		el.className = &quot;cell &quot;+ this.Alive.toString();
		return el;
	}
}
</pre><p>The first thing that bothered me is that the Cell has a constructor with coordinates. The only place where the Cell uses the coordinate is to let the parent know of the state change, but this is closely related to the next eyesore.</p><p>The Cell knows about the Element that displays it and furthermore &#8211; operates on it, creating the representation and collecting events. While this can be regarded as convenient, it breaks the single responsibility principle, since we have a logical Cell model, but also it&#8217;s dealing with HTML. This means that it&#8217;s tightly coupled with representation.</p><p>So here&#8217;s the redesign.</p><pre class="brush: jscript; title: ; notranslate">
gameOfLife.cell = function() {
	return {
		alive : false,
		live : function() { this.alive = true; },
		die : function() { this.alive = false; },
		touch : function () { this.alive = ! this.alive; }
	};
};
</pre><p>Much better, right? :)</p><h3>GameOfLife class</h3><p>How about the GameOfLife class&#8230;</p><pre class="brush: jscript; title: ; notranslate">
function GameOfLife(Size, HTMLElementId) {
	var Size = Size;
	var Cells = new Array(Size);
	var Next = new Array(Size);
	var id = HTMLElementId;
	var i, j;
	var el = document.getElementById(id);
	el.style.width = (5*Size) + &quot;px&quot;;
	for(i=0; i&lt;Size; i++) {
		Cells[i] = new Array(Size);
		Next[i] = new Array(Size);
		for(j=0; j&lt;Size; j++) {
			Cells[i][j] = new Cell(i, j);
			el.appendChild( Cells[i][j].Element(this) );
		}
	}
	this.ChangeCellState = function(x, y) {
		Cells[y][x].ChangeState();
	}
	this.RandomStart = function() {
		var OneOrZero = 0;
		var i, j;
		for(i=0; i&lt;Size; i++) {
			for(j=0; j&lt;Size; j++) {
				OneOrZero = Math.round(Math.round(Math.random() * 2)/2);
				if (OneOrZero) Cells[i][j].ChangeState();
			}
		}
	}
	this.NextStep = function () {
		var i, j;
		for(i=0; i&lt;Size; i++) {
			for(j=0; j&lt;Size; j++) {
				var neighboursAlive = NeighboursAlive(i, j);
				switch ( neighboursAlive ) {
					case 3 : {
						Next[i][j] = true;
						break;
					}
					case 2 : {
						Next[i][j] = (Cells[i][j].Alive) ? true : false;
						break;
					}
					default : {
						Next[i][j] = false;
					}
				}
			}
		}
		for(i=0; i&lt;Size; i++)
			for(j=0; j&lt;Size; j++)
				(Next[i][j]) ? Cells[i][j].Live() : Cells[i][j].Die();
	}
	function NeighboursAlive(y, x) {
		var horizontal = new Array( (x&lt;=0) ? Size-1 : x-1, x , (x&gt;=Size-1) ? 0 : x+1 );
		var vertical = new Array( (y&lt;=0) ? Size-1 : y-1, y, (y&gt;=Size-1) ? 0 : y+1 );
		var sum = 0;
		var i, j;
		for (i=0; i&lt;3; i++)
			for (j=0; j&lt;3; j++)
				if( vertical[i]!=y || horizontal[j]!=x ) sum += (Cells[ vertical[i] ][ horizontal[j] ].Alive) ? 1 : 0;
		return sum;
	}
	var playerId;
	var playing = false;
	this.Play = function (name) {
		if (!playing) {
			this.NextStep();
			playerId = setInterval( name +&quot;.NextStep()&quot;, 100);
			playing = true;
		}
	}
	this.Stop = function () {
		if (playing) clearInterval(playerId);
		playing = false;
	}
}
</pre><p>So the GameOfLife class has really a lot of things going on, let&#8217;s have a look at all the things it does.</p><ol><li>Has the Cells (the current generation) and Next matrix (the next generation of cells),</li><li>sets up both</li><li>changes the state of each cell</li><li>finds the neighbors of a cell</li><li>calculates the the next generation</li><li>randomly sets up the Cells matrix</li><li>plays and stops itself.</li></ol><p>Whew.</p><p>Again, coupling with representation?! Seems that I really LOVED doing that back then&#8230;</p><p>Aside from that, I don&#8217;t like how it has the Play and Stop methods, I don&#8217;t think this belongs to this class, so I will extract it to a player a bit later. So here&#8217;s the redesign.</p><pre class="brush: jscript; title: ; notranslate">
gameOfLife.game = function(size) {
	var next = new Array(size);
	var iterations = 0;
	function neighboursAlive(x, y) {
		var horizontalIndexes = getNeighbourIndexes(x);
		var verticalIndexes = getNeighbourIndexes(y);
		var sum = 0;
		for (var i = 0; i &lt; 3; i++) {
			for (var j = 0; j &lt; 3; j++) {
				if (verticalIndexes[i]!=y || horizontalIndexes[j]!=x) sum += (_.cells[horizontalIndexes[i]][verticalIndexes[j]].alive) ? 1 : 0;
			}
		}
		return sum;
	};
	function getNeighbourIndexes(x) {
		return new Array( (x = size - 1) ? 0 : x + 1 );
	};
	var _ = {
		size : size,
		cells : new Array(size),
		liveRule : 3,
		noChangeRule : 2,
		touch : function(x, y) {
			cells[x][y].touch();
		},
		nextStep : function () {
			var i, j;
			for(i=0; i &lt; size; i++) {
				for(j=0; j &lt; size; j++) {
					var aliveInTheHood = neighboursAlive(i, j);
					switch (aliveInTheHood) {
						case _.liveRule : { next[i][j] = true; break; }
						case _.noChangeRule : {
							next[i][j] = (_.cells[i][j].alive) ? true : false;
							break;
						}
						default : {
							next[i][j] = false;
						}
					}
				}
			}
			for(i=0; i &lt; _.size; i++)
				for(j=0; j &lt; _.size; j++)
					(next[i][j]) ? _.cells[i][j].live() : _.cells[i][j].die();
		}
	};
	for(var i = 0; i &lt; size; i++) {
		_.cells[i] = new Array(size);
		next[i] = new Array(size);
		for(var j = 0; j &lt; size; j++)
			_.cells[i][j] = new gameOfLife.cell();
	};
	return _;
};
</pre><p>While I would say that this is much better, after some thought I still didn&#8217;t like it.</p><p>First of all, I don&#8217;t like all this running around the matrix checking states, calculating next state. Looks too convoluted.</p><div
class="clearfix"><p><a
href="http://www.bjelic.net/wp-content/uploads/michelangelo-finger-of-god-lg1.jpg"><img
class="alignleft size-thumbnail wp-image-1089" title="Michalangelo's Finger Of God" src="http://www.bjelic.net/wp-content/uploads/michelangelo-finger-of-god-lg1-150x150.jpg" alt="Michalangelo's Finger Of God" width="150" height="150" /></a>Second thing can be seen as a philosophical issue too &#8211; I really hate that the game is the divine force deciding the fate of cells. Looking from the software design side, it boils down to the fact that the game is dealing with the state of a cell based on the states of the surrounding cells. Too much cell-dealing stuff in the game object. So I took another go.</p></div><h2>Round two</h2><h3>Cell</h3><p>I have decided to move all the functionality that deals with the state of cells from the game to the cell class itself.</p><pre class="brush: jscript; title: ; notranslate">
gameOfLife.cell = function () {
	&quot;use strict&quot;;
	var future, _;
	_ = {
		alive : false,
		touch : function () { _.alive = !_.alive; },
		neighbours : [],
		neighboursAlive : function () {
			var sum = 0;
			_.neighbours.forEach(function (neighbour) {
				sum += +neighbour.alive;
			});
			return sum;
		},
		progress : function () {
			if (future === undefined) {
				_.futureIsBright();
			}
			_.alive = future;
			future = undefined;
		},
		futureIsBright : function () {
			if (future === undefined) {
				var neighboursAlive = _.neighboursAlive();
				future = neighboursAlive === gameOfLife.cell.neighboursToLive || (_.alive &amp;&amp; neighboursAlive === gameOfLife.cell.neighboursToStagnate);
			}
			return future;
		}
	};
	return _;
};
gameOfLife.cell.neighboursToLive = 3;
gameOfLife.cell.neighboursToStagnate = 2;
</pre><p>So while the cell class now is nowhere clean as in the first round, it looks better.</p><p>The cell is now aware of its neighbors, talks to them, can see into the future and progress. :)</p><p>The neighbor&#8217;s changes awareness is possible due to the fact that the <i>objects</i> are passed by reference in JavaScript, so all changes that happen to neighbors will be visible because only the references are held, not the actual values.</p><p>Additionally, the game rules are now extracted to static variables on cell object.</p><p>To accommodate these changes, the game object has to change also, so the new version is below.</p><h3>Game</h3><pre class="brush: jscript; title: ; notranslate">
gameOfLife.game = function (size) {
	&quot;use strict&quot;;
	var _, i, j;
	_ = {
		cells : [],
		touch : function (x, y) {
			_.cells[x][y].touch();
		},
		progress : function () {
			_.cells.forEach(function (row) {
				row.forEach(function (cell) {
					cell.futureIsBright();
				});
			});
			_.cells.forEach(function (row) {
				row.forEach(function (cell) {
					cell.progress();
				});
			});
		}
	};
	function correctIndex(x) {
		return (x &lt; 0) ? size - 1 : ((x &gt; size - 1) ? 0 : x);
	}
	function neighbourIndexes(x) {
		return [correctIndex(x - 1), x, correctIndex(x + 1)];
	}
	for (i = 0; i &lt; size; i++) {
		_.cells[i] = [];
		for (j = 0; j &lt; size; j++) {
			_.cells[i][j] = new gameOfLife.cell();
		}
	}
	_.cells.forEach(function (row, i) {
		row.forEach(function (cell, j) {
			neighbourIndexes(i).forEach(function (x) {
				neighbourIndexes(j).forEach(function (y) {
					cell.neighbours.push(_.cells[x][y]);
				});
			});
			cell.neighbours.splice(4, 1);
		});
	});
	return _;
};
</pre><p>The game now has only the cell matrix setup role and the access point to progress to next generation. Much better.</p><p>I played with the idea of using recursion to propagate setting the future state on all cells instead of running two loops in the propagate method, but I easily ran into an stack overflow, so sticking with the less elegant but practical solution.</p><h3>Player</h3><p>As I said before, I didn&#8217;t like how the game had play and stop methods, so the logic to run the game is now moved to the player object.</p><pre class="brush: jscript; title: ; notranslate">
gameOfLife.player = function (game, screens) {
	&quot;use strict&quot;;
	var i, playerId, refreshScreens, _;
	for (i = 0; i &lt; screens.length; i++) {
		screens[i].setup(game);
	}
	refreshScreens = function () {
		var i;
		for (i = 0; i &lt; screens.length; i++) {
			screens[i].refresh();
		}
	};
	_ = {
		speed : 100,
		play : function () {
			playerId = window.setInterval(_.step, _.speed);
		},
		on : function () {
			refreshScreens();
		},
		step : function () {
			game.progress();
			refreshScreens();
		},
		stop : function () {
			if (playerId) {
				window.clearInterval(playerId);
			}
		}
	};
	return _;
};
</pre><p>Simple stuff, allowing better modularity.</p><h3>Screen</h3><p>This is the concept that will enable different visual representations of the game. But it&#8217;s pretty simple for now.</p><pre class="brush: jscript; title: ; notranslate">
gameOfLife.simpleScreen = function () {
	&quot;use strict&quot;;
	var game, el;
	return {
		setup : function (game1, elementId) {
			game = game1;
			el = document.getElementById(elementId === undefined ? 'simpleRenderer' : elementId);
		},
		refresh : function () {
			var i, j, html;
			html = '';
			for (i = 0; i &lt; game.cells.length; i++) {
				for (j = 0; j &lt; game.cells[i].length; j++) {
					html = html.concat(game.cells[i][j].alive ? '&amp;diams;' : '.');
				}
				html = html.concat('&lt;br/&gt;');
			}
			el.innerHTML = html;
		}
	};
};
</pre><h3>Random start</h3><p>You may wander where did the random start method go. Since it doesn&#8217;t have anything to do with the game, but is just a fancy feature, I have extracted it to a separate function.</p><pre class="brush: jscript; title: ; notranslate">
gameOfLife.randomize = function(game) {
	var i, j;
	for(i = 0; i &lt; game.cells.length; i++) {
		for(j = 0; j &lt; game.cells.length; j++) {
			if (Math.round(Math.round(Math.random() * 2) / 2))
				game.cells[i][j].touch();
		}
	}
};
</pre><h2>Done</h2><p>At the end of this exercise I am pretty much satisfied with the outcome.</p><p>The redesign ended up looking like MVC pattern, where the model domain consists of cell and game classes, the player class is the controller, and the screen class is the view.</p><p>Here&#8217;s the demo, the tools and full code if you&#8217;re interested to have a look. In the next article I&#8217;ll work on the visual representation of the game, and I think it will be pretty interesting.</p><pre class="brush: jscript; collapse: true; light: false; title: ; toolbar: true; notranslate">
window.gameOfLife = {};
gameOfLife.cell = function () {
	&quot;use strict&quot;;
	var future, askNeighboursFuture, _;
	askNeighboursFuture = function () {
		_.neighbours.forEach(function (neighbour) {
			neighbour.futureIsBright();
		});
	};
	_ = {
		alive : false,
		touch : function () { _.alive = !_.alive; },
		neighbours : [],
		neighboursAlive : function () {
			var sum = 0;
			_.neighbours.forEach(function (neighbour) {
				sum += +neighbour.alive;
			});
			return sum;
		},
		progress : function () {
			if (future === undefined) {
				_.futureIsBright();
			}
			_.alive = future;
			future = undefined;
		},
		futureIsBright : function () {
			if (future === undefined) {
				var neighboursAlive = _.neighboursAlive();
				future = neighboursAlive === gameOfLife.cell.neighboursToLive || (_.alive &amp;&amp; neighboursAlive === gameOfLife.cell.neighboursToStagnate);
				askNeighboursFuture();
			}
			return future;
		}
	};
	return _;
};
gameOfLife.cell.neighboursToLive = 3;
gameOfLife.cell.neighboursToStagnate = 2;
gameOfLife.game = function (size) {
	&quot;use strict&quot;;
	var _, i, j;
	_ = {
		cells : [],
		touch : function (x, y) {
			_.cells[x][y].touch();
		},
		progress : function () {
			_.cells.forEach(function (row) {
				row.forEach(function (cell) {
					cell.progress();
				});
			});
		}
	};
	function neighbourIndexes(x) {
		return [correctIndex(x - 1), x, correctIndex(x + 1)];
	}
	function correctIndex(x) {
		return (x &lt; 0) ? size - 1 : ((x &gt; size - 1) ? 0 : x);
	};
	for (i = 0; i &lt; size; i++) {
		_.cells[i] = [];
		for (j = 0; j &lt; size; j++) {
			_.cells[i][j] = new gameOfLife.cell();
		}
	}
	_.cells.forEach(function (row, i) {
		row.forEach(function (cell, j) {
			neighbourIndexes(i).forEach(function (x) {
				neighbourIndexes(j).forEach(function (y) {
					cell.neighbours.push(_.cells[x][y]);
				});
			});
			cell.neighbours.splice(4, 1);
		});
	});
	return _;
};
gameOfLife.randomize = function (game) {
	&quot;use strict&quot;;
	var i, j;
	for (i = 0; i &lt; game.cells.length; i++) {
		for (j = 0; j &lt; game.cells.length; j++) {
			game.cells[i][j].alive = (Math.random() &gt; 0.5);
		}
	}
};
gameOfLife.player = function (game, screens) {
	&quot;use strict&quot;;
	var i, playerId, refreshScreens, _;
	for (i = 0; i &lt; screens.length; i++) {
		screens[i].setup(game);
	}
	refreshScreens = function () {
		var i;
		for (i = 0; i &lt; screens.length; i++) {
			screens[i].refresh();
		}
	};
	_ = {
		speed : 100,
		play : function () {
			playerId = window.setInterval(_.step, _.speed);
		},
		on : function () {
			refreshScreens();
		},
		step : function () {
			game.progress();
			refreshScreens();
		},
		stop : function () {
			if (playerId) {
				window.clearInterval(playerId);
			}
		}
	};
	return _;
};
gameOfLife.touchScreen = function () {
	&quot;use strict&quot;;
	var game, el;
	var _ = {
		setup : function (game1, elementId) {
			var i, j, dot;
			game = game1;
			el = document.getElementById(elementId === undefined ? 'simpleRenderer' : elementId);
			for (i = 0; i &lt; game.cells.length; i++) {
				for (j = 0; j &lt; game.cells[i].length; j++) {
					dot = document.createElement('a');
					dot.addEventListener('click', _.touch(i, j), false);
					el.appendChild(dot);
					dot = null;
				}
				el.appendChild(document.createElement('br'));
			}
		},
		refresh : function () {
			var i, j, dots, dot;
			dots = el.getElementsByTagName('a');
			for (i = 0; i &lt; game.cells.length; i++) {
				for (j = 0; j &lt; game.cells[i].length; j++) {
					dot = dots[j + i * game.cells.length];
					dot.className = (game.cells[i][j].alive) ? 'cell alive' : 'cell dead';
				}
			}
		},
		touch : function(x, y) {
			return function() { game.touch(x, y); _.refresh(); };
		}
	};
	return _;
};
gameOfLife.simpleScreen = function () {
	&quot;use strict&quot;;
	var game, el;
	return {
		setup : function (game1, elementId) {
			game = game1;
			el = document.getElementById(elementId === undefined ? 'simpleRenderer' : elementId);
		},
		refresh : function () {
			var i, j, html;
			html = '';
			for (i = 0; i &lt; game.cells.length; i++) {
				for (j = 0; j &lt; game.cells[i].length; j++) {
					html = html.concat(game.cells[i][j].alive ? '&amp;diams;' : '.');
				}
				html = html.concat('&lt;br/&gt;');
			}
			el.innerHTML = html;
		}
	};
};
function run() {
	gameOfLife.spaceship = new gameOfLife.game(30);
	gameOfLife.spaceship.cells[0][2].alive = true;
	gameOfLife.spaceship.cells[1][3].alive = true;
	gameOfLife.spaceship.cells[2][1].alive = true;
	gameOfLife.spaceship.cells[2][2].alive = true;
	gameOfLife.spaceship.cells[2][3].alive = true;
	gameOfLife.station = new gameOfLife.player(gameOfLife.spaceship, [new gameOfLife.touchScreen()]);
	gameOfLife.station.on();
}
</pre><p><a
href="http://dl.dropbox.com/u/10964419/gameoflife/game2.html" class="rundemo">View the new demo</a></p><p>The tools I have used:</p><ul><li><a
href="http://www.jslint.com/">JSLint</a>, The JavaScript Code Quality Tool</li><li><a
href="http://docs.jquery.com/QUnit">QUnit</a>, An easy-to-use JavaScript Unit Testing framework</li></ul> ]]></content:encoded> <wfw:commentRss>http://www.bjelic.net/2011/10/23/coding/game-of-life-javascript-implementation/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Signal Links</title><link>http://www.bjelic.net/2011/08/16/digital-life-2/signal-links-3/</link> <comments>http://www.bjelic.net/2011/08/16/digital-life-2/signal-links-3/#comments</comments> <pubDate>Tue, 16 Aug 2011 08:42:53 +0000</pubDate> <dc:creator>Bojan Bjelić</dc:creator> <category><![CDATA[Digital Life]]></category> <category><![CDATA[archive]]></category> <category><![CDATA[links]]></category> <category><![CDATA[posts]]></category> <category><![CDATA[signal]]></category> <category><![CDATA[tweets]]></category> <guid
isPermaLink="false">http://www.bjelic.net/?p=1169</guid> <description><![CDATA[Posts, photos, interesting stuff I enjoyed during past couple of weeks (18. July 2011 - 16. August 2011).]]></description> <content:encoded><![CDATA[<p>It&#8217;s truly interesting how we deal with great amounts of interrelated data, these terms explain it in a colorful way.</p><p>[blackbirdpie url="http://twitter.com/#!/nicolasnova/status/96262390588506113"]</p><p>Nice tool to do a quick test how a site performs on different resolutions.</p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/95948269078847488"]</p><p>Ahh, the dreams of becoming an astronaut&#8230; Great photos.</p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/95778343139545088"]</p><p>Extraordinary to see this kind of robot behavior.</p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/98358415281225728"]</p><p>Cool project, something I just HAVE TO play around with.</p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/97606517817212928"]</p><p>Sometimes it&#8217;s worthy to just look at the world around. Great photo and message.</p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/99386708214292480"]</p><p>At first it was surprising to see how is minority dictating the majority opinion, but when I consider that the minority &#8220;holds an unshakable belief&#8221;, not really.</p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/102016267237601281"]</p><p>I hope this will help me remember the milk. :)</p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/101929775739838464"]</p> ]]></content:encoded> <wfw:commentRss>http://www.bjelic.net/2011/08/16/digital-life-2/signal-links-3/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Android apps for everyday use</title><link>http://www.bjelic.net/2011/08/08/digital-life-2/android-apps/</link> <comments>http://www.bjelic.net/2011/08/08/digital-life-2/android-apps/#comments</comments> <pubDate>Mon, 08 Aug 2011 09:32:57 +0000</pubDate> <dc:creator>Bojan Bjelić</dc:creator> <category><![CDATA[Digital Life]]></category> <category><![CDATA[android]]></category> <category><![CDATA[apps]]></category> <category><![CDATA[mobile]]></category> <guid
isPermaLink="false">http://www.bjelic.net/?p=1011</guid> <description><![CDATA[I just went through a process of installing the apps that I use every day - so here they are.]]></description> <content:encoded><![CDATA[<p><a
href="http://www.bjelic.net/wp-content/uploads/android1299311465678-e1312795071292.png"><img
class="alignleft size-thumbnail wp-image-1147" title="android" src="http://www.bjelic.net/wp-content/uploads/android1299311465678-e1312795071292-150x150.png" alt="android" width="150" height="150" /></a>I just went through a process of installing the apps that I use every day, after making <a
title="Android 2.3 Platform Highlights | Android Developers" href="http://developer.android.com/sdk/android-2.3-highlights.html">Gingerbread</a> work on my <a
title="Samsung Galaxy S" href="http://www.samsung.com/global/microsite/galaxyswifi/gs4/gs4_main.html">Galaxy S</a> using this <a
title="How To Update Samsung Galaxy S I9000 to Gingerbread XXJVP 2.3.4 Firmware | Android Advices" href="http://androidadvices.com/how-to-update-samsung-galaxy-s-i9000-to-gingerbread-xxjvp-2-3-4-firmware/">unofficial guide</a> (damn you, Samsung!) &#8211; so here they are.</p><h2>Dropbox</h2><p>To keep files synchronized on all the devices.</p><h2>KeePassDroid</h2><p>I stick to the policy of having a password for each service. Which means I don&#8217;t know half by heart &#8211; this is a great app to keep up.</p><h2>Google Translate</h2><p>My native language is Serbian, I work on English, and live in Vienna where people speak German. So translation is &#8230; hm what was that word&#8230; ;)</p><h2>Springpad</h2><p>Notes, bookmarks &#8211; organizer that stays in synch, works offline too. There&#8217;s a web app that is more convenient when at the computer.</p><h2>Google Docs</h2><p>Office online. &#8217;nuff said.</p><h2>AndFtp</h2><p>Great little FTP client to do things on the move.</p><h2>Feedly</h2><p>To keep up with the information overload ;) &#8211; phenomenal RSS reader, works with Google reader.</p><h2>Shush! Ringer Restorer</h2><p>I never remember to turn the ringer back on when I put my phone to silent. This one fixes that. :)</p> ]]></content:encoded> <wfw:commentRss>http://www.bjelic.net/2011/08/08/digital-life-2/android-apps/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Signal Links</title><link>http://www.bjelic.net/2011/07/18/digital-life-2/signal-links-2/</link> <comments>http://www.bjelic.net/2011/07/18/digital-life-2/signal-links-2/#comments</comments> <pubDate>Mon, 18 Jul 2011 09:33:35 +0000</pubDate> <dc:creator>Bojan Bjelić</dc:creator> <category><![CDATA[Digital Life]]></category> <category><![CDATA[archive]]></category> <category><![CDATA[links]]></category> <category><![CDATA[posts]]></category> <category><![CDATA[signal]]></category> <category><![CDATA[tweets]]></category> <guid
isPermaLink="false">http://www.bjelic.net/?p=1129</guid> <description><![CDATA[A couple of posts and videos I enjoyed for the previous week (11. July 2011 - 18. July 2011).]]></description> <content:encoded><![CDATA[<p>HTML and CSS now provide to use inline images, not requiring another HTTP request.</p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/92572136878772224"]</p><p>Interesting video on data visualization.</p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/91127931828580352"]</p><p>Please take note and use in case of stress. :)</p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/91234492097904640"]</p> ]]></content:encoded> <wfw:commentRss>http://www.bjelic.net/2011/07/18/digital-life-2/signal-links-2/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Signal Links</title><link>http://www.bjelic.net/2011/07/11/digital-life-2/signal-links/</link> <comments>http://www.bjelic.net/2011/07/11/digital-life-2/signal-links/#comments</comments> <pubDate>Mon, 11 Jul 2011 13:51:55 +0000</pubDate> <dc:creator>Bojan Bjelić</dc:creator> <category><![CDATA[Digital Life]]></category> <category><![CDATA[archive]]></category> <category><![CDATA[links]]></category> <category><![CDATA[posts]]></category> <guid
isPermaLink="false">http://www.bjelic.net/?p=1103</guid> <description><![CDATA[Links and posts I enjoyed for the previous week (4. July 2011 - 11. July 2011).]]></description> <content:encoded><![CDATA[<p>I am starting this post series as a way for me to preserve some things I have enjoyed.</p><p>So here are some links and posts I enjoyed for the previous week (4. July 2011 &#8211; 11. July 2011).</p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/90336727775977472"]</p><p><a
href="http://code.google.com/p/jslibs/wiki/JavascriptTips">http://code.google.com/p/jslibs/wiki/JavascriptTips</a></p><p>[blackbirdpie url="http://twitter.com/#!/NASA/status/90059257046761472"]</p><p>There was the live video feed of the last shuttle flight that I watched on my Android Samsung Galaxy S.</p><p>[blackbirdpie url="http://twitter.com/#!/bojanbjelic/status/88905200139640832"]</p><p><a
href="https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills">https://github.com/Modernizr/Modernizr/wiki/HTML5-Cross-browser-Polyfills</a></p><p>[blackbirdpie url="http://twitter.com/#!/shanselman/status/88143740098711552"]</p><p>This is a question everyone should ask themselves.</p> ]]></content:encoded> <wfw:commentRss>http://www.bjelic.net/2011/07/11/digital-life-2/signal-links/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
