<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>airodig.com &#187; Uncategorized</title>
	<atom:link href="http://airodig.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://airodig.com</link>
	<description>airodig hacking industries</description>
	<lastBuildDate>Tue, 31 Aug 2010 20:17:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Controlling Your Inbox &#8212; Efficient Email Management with Mutt</title>
		<link>http://airodig.com/2010/08/31/controlling-your-inbox-efficient-email-management-with-mutt/</link>
		<comments>http://airodig.com/2010/08/31/controlling-your-inbox-efficient-email-management-with-mutt/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 20:17:10 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fetchmail]]></category>
		<category><![CDATA[gpg]]></category>
		<category><![CDATA[msmtp]]></category>
		<category><![CDATA[mutt]]></category>
		<category><![CDATA[procmail]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=492</guid>
		<description><![CDATA[It looks like my recent article (movie), extreme productivity, resonated with a lot of folk. I wanted to include my email setup in that video, as I feel having a good email solution is vital to &#8220;Getting Shit Done&#8221;™, but felt that it was just a bit too much. Also, this post is a long [...]]]></description>
			<content:encoded><![CDATA[<p>It looks like my recent article (movie), <a href="http://airodig.com/2010/08/27/extreme-productivity-with-screen-and-vim/" title="extreme productivity">extreme productivity</a>, resonated with a lot of folk. I wanted to include my email setup in that video, as I feel having a good email solution is vital to <b>&#8220;Getting Shit Done&#8221;</b>™, but felt that it was just a bit too much. Also, this post is a long time coming &#8212; I originally wanted to write about this <a href="http://groups.google.com/group/nosql-discussion/browse_thread/thread/ded62a56d5d0db94/d5c8eaf0b90fe54f?lnk=gst" nofollow="true">back when someone got offended on the nosql mailing list because a handful of us told him that he shouldn&#8217;t be on developer mailing lists without some form of client side sorting/filtering going on</a>.</p>
<p>I also decided NOT to do a video this post as many people seemed to find my lack of toastmaster skills as an extreme negative, that, and I don&#8217;t think I need to be recording my inbox with the half the internet.</p>
<p><center><a href="http://airodig.com/wp-content/uploads/2010/08/Public-Speaking-731932.gif" nofollow="true"><img src="http://airodig.com/wp-content/uploads/2010/08/Public-Speaking-731932.gif" alt="" title="Public-Speaking-731932" width="250" height="383" class="aligncenter size-full wp-image-517" /></a></center></p>
<p><strong>Background</strong><br />
Email is a REALLY <a href="http://tools.ietf.org/html/rfc918" title="pop rfc" nofollow="true">old</a> <a href="http://tools.ietf.org/html/rfc821" title="smtp rfc" nofollow="true">protocol</a>, yet as developers we still use it everyday to manage bugs, track revisions, and communicate business ideas and goals (unlike the younger generation who say <a href="http://www.slate.com/id/2177969" nofollow="true">&#8216;email is only for old people&#8217;</a>).</p>
<p>Being subscribed to even a couple of <a href="http://lkml.org/lkml/2010/8/31/">mailing</a> <a href="http://www.securityfocus.com/archive/1">lists</a> can get out of hand REAL fast &#8212; now throw in all your usual email and you&#8217;d probably want to give up on this whole &#8216;internet career&#8217; idea.</p>
<p><strongWhat is mutt?</strong><br />
<a href="http://www.mutt.org/" title="mutt email client">Mutt</a> is a shell based email client. This, among other things, allows you to <u>KEEP YOUR FINGERS ON THE KEYBOARD</u>. It also has a whole suite of different programs that guys like me like to interact with it. </p>
<p><strong>My Introduction</strong><br />
I started with pine back in the day, right after scoring my first dial-up account &#8212; 94, 95ish&#8230;. back then I would &#8220;sneak&#8221; into one of the computer science labs at the local university to play some <a href="http://www.lgm.com/bolo/">bolo</a>, hop on <a href="http://en.wikipedia.org/wiki/Hotline_Communications">Hotline</a>, and talk all sorts of shit on <a href="http://www.happyhacker.org/"> Carolyn Meinel</a> and other security pundits of the day&#8230; ah, the life of a 12-14 year old&#8230;anyways I needed an email client better than pine &#8212; so began the adventures!</p>
<p>When someone mentions using mutt for their email &#8212; they typically leave out all the extra stuff that they use with it &#8212; here&#8217;s a short list of mine:</p>
<p><strong>Progams We Use</strong></p>
<ul>
<li>Procmail &#8212; sorting/filtering your mail into different mailboxes</li>
<li>Fetchmail &#8212; downloading your email from different hosts</li>
<li>Msmtp &#8212; sending email</li>
<li>Gpg &#8212; signing/encrypting your email</li>
<li>Mutt &#8212; navigation through your email</li>
<li>Aspell/Abook &#8212; address book and spell checker</li>
<li>Vim &#8212; editor</li>
</ul>
<p>I currently have 23 mailboxes in my .muttrc (each mailing list gets one, each email account gets one, a few others).</p>
<p>A few of the common key bindings I have setup to navigate and crunch through my email:</p>
<p><strong>Common keys:</strong></p>
<ul>
<li>Ctrl-D &#8212; mass delete thread &#8212; some threads are pointless to read &#8212; why are you using your mouse to delete them individually?</li>
<li>m &#8212; create a new email</li>
<li>s &#8212; send currently selected email to a new mailbox</li>
<li>G &#8212; tell fetchmail to download new email (I used to have it be background but not anymore since I don&#8217;t want to be reminded everytime you get a new email &#8212; you can actually have it backgrounded and not pop up either as well)</li>
<li>c &#8212; switch to a diff. mailbox</li>
<li>d &#8212; delete currently selected message</li>
<li>v &#8212; view current message</li>
<li>h &#8212; toggle headers (see who sent you the email if you suspect bullshit, or just see diff. headers)</li>
<li>s &#8212; save attachement (useful for those daily google analytics pdfs you are sent &#8212; you do do this right?)</li>
<li>a &#8212; add new contact to addressbook</li>
<li>m-tab &#8212; select contact from addressbook</li>
<li>r &#8212; reply to sender</li>
<li>g &#8212; reply to group (mailing list)</li>
<li>p, e/s &#8212; (after composing new email) &#8212; sign/encrypt with gpg (it&#8217;ll prompt you for your passphrase)</li>
</ul>
<p>Just like screen, vim, emacs, and other cool unix tools you can split your screen &#8212; in this case, between folder view and mail view 2 or 3 ways and vertical versus horizontal &#8212; however you wish really.</p>
<p>Procmail is where mutt gets handed most of it&#8217;s magic I believe. A simple .muttrc macro like the following will suffice:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">macro index G <span style="color: #ff0000;color: #666666;">&quot;!fetchmail -a -m 'procmail -d %T'<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>
macro pager G <span style="color: #ff0000;color: #666666;">&quot;!fetchmail -a -m 'procmail -d %T'<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span></pre></div></div>

<p><strong>simple .procmailrc</strong><br />
<i>Note: this obviously is nowhere close to a full procmailrc &#8212; it just demonstrates it&#8217;s awesome ability to sort and filter email</i></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">:<span style="color: #000000;background-color: #000000; color: #DDD;">0</span>
<span style="color: #000000; font-weight: bold;color: #CCC;">*</span> ^Subject:.<span style="color: #000000; font-weight: bold;color: #CCC;">*</span><span style="color: #7a0874; font-weight: bold;color: #CCC;">&#40;</span>merb<span style="color: #7a0874; font-weight: bold;color: #CCC;">&#41;</span>
<span style="color: #007800;color: blue;">$MAILDIR</span><span style="color: #000000; font-weight: bold;color: #CCC;">/</span>merb
&nbsp;
:<span style="color: #000000;background-color: #000000; color: #DDD;">0</span>
<span style="color: #000000; font-weight: bold;color: #CCC;">*</span> ^Subject:.<span style="color: #000000; font-weight: bold;color: #CCC;">*</span><span style="color: #7a0874; font-weight: bold;color: #CCC;">&#40;</span>nodejs<span style="color: #7a0874; font-weight: bold;color: #CCC;">&#41;</span>
<span style="color: #007800;color: blue;">$MAILDIR</span><span style="color: #000000; font-weight: bold;color: #CCC;">/</span>node
&nbsp;
:<span style="color: #000000;background-color: #000000; color: #DDD;">0</span>
<span style="color: #000000; font-weight: bold;color: #CCC;">*</span> ^To:.<span style="color: #000000; font-weight: bold;color: #CCC;">*</span><span style="color: #7a0874; font-weight: bold;color: #CCC;">&#40;</span>GPSL\<span style="color: #000000; font-weight: bold;color: #CCC;">@</span>yahoogroups.com<span style="color: #7a0874; font-weight: bold;color: #CCC;">&#41;</span>
<span style="color: #007800;color: blue;">$MAILDIR</span><span style="color: #000000; font-weight: bold;color: #CCC;">/</span>gpsl
&nbsp;
:<span style="color: #000000;background-color: #000000; color: #DDD;">0</span>
<span style="color: #000000; font-weight: bold;color: #CCC;">*</span> ^To:.<span style="color: #000000; font-weight: bold;color: #CCC;">*</span><span style="color: #7a0874; font-weight: bold;color: #CCC;">&#40;</span>solr-user\<span style="color: #000000; font-weight: bold;color: #CCC;">@</span>lucene.apache.org<span style="color: #7a0874; font-weight: bold;color: #CCC;">&#41;</span>
<span style="color: #007800;color: blue;">$MAILDIR</span><span style="color: #000000; font-weight: bold;color: #CCC;">/</span>solr</pre></div></div>

<p>Then, as you can see, we sort through a regex to place incoming mail into their respective folders &#8212; that way I can CHOOSE what to read WHEN rather than my inbox choosing me.</p>
<p><strong>Security, or Sending/Receiving Email without Ending up in the Ownage Bin</strong></p>
<p><center><a href="http://airodig.com/wp-content/uploads/2010/08/eavesdropping.jpg"><img src="http://airodig.com/wp-content/uploads/2010/08/eavesdropping.jpg" alt="" title="eavesdropping" width="432" height="432" class="aligncenter size-full wp-image-511" /></a></center></p>
<p>I&#8217;m grouping sending/receiving email into this section since I believe it is overlooked quite a LOT. There is a difference between being a d0x dropping, obsd zealot, master of the universe security wise and just being smart since you are a developer.</p>
<p>To get our email we&#8217;d use something like fetchmail &#8212; there are a lot of people out there that have hooked this up to a desktop pager &#8212; I don&#8217;t really do that anymore because I have found it distracting to see my inbox grow over the course of even a few minutes. I just check every couple of hours instead, although it is possible to daemonize fetchmail and not have the pager go off either.</p>
<p><strong>A typical .fetchmailrc might look like the following:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">poll mail.host1.com protocol imap user <span style="color: #ff0000;color: #666666;">&quot;joe+blows.com&quot;</span> password <span style="color: #ff0000;color: #666666;">&quot;pass&quot;</span> ssl
poll mail.booda.net protocol pop3 user <span style="color: #ff0000;color: #666666;">&quot;jb&quot;</span> password <span style="color: #ff0000;color: #666666;">&quot;pass&quot;</span> ssl
poll mail.bambam.com protocol pop3 user <span style="color: #ff0000;color: #666666;">&quot;billy@bob.com&quot;</span> password <span style="color: #ff0000;color: #666666;">&quot;pass&quot;</span> ssl</pre></div></div>

<p>Yes, you are storing your passwords in plaintext but if you set up your permissions right you should be *ok* &#8212; you probably have a lot of other problems if someone has owned your home dir. Please notice the ssl entries here &#8212; while I don&#8217;t care too much about someone pretending they are bob.com when they are really evilbob.com I <b>DO</b> care that some random guy at a computer conference won&#8217;t be able to snatch my passwords in plaintext.</p>
<p>To send email we&#8217;d use msmtp &#8212; although, once again there are a billion and one programs to do this for you.</p>
<p><strong>simple .msmtprc</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">account default
host smtp.gmail.com
port <span style="color: #000000;background-color: #000000; color: #DDD;">587</span>
from blah<span style="color: #000000; font-weight: bold;color: #CCC;">@</span>gmail.com
tls on
tls_starttls on
tls_certcheck off
auth <span style="color: #c20cb9; font-weight: bold;color: #577A61;">login</span>
user blah
password <span style="color: #000000; font-weight: bold;color: #CCC;">*********</span>
logfile ~<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>.msmtp.log</pre></div></div>

<p>Notice, once again that we are ensuring tls is ON &#8212; after all auth login is no more than base64 encoded&#8230;. wireshark and friends could easily pick this up in a netcafe. The certcheck is up to you &#8212; if you are paranoid that someone is serving up a bullshit cert you might wish to turn it on, although, what is a cert worth nowadays after seeing <a href="http://www.eff.org/files/DefconSSLiverse.pdf">something like this</a>?</p>
<p>Better yet, forget the coffee shop! Just simple protection at a developer conference is enough!, Just think of those guys with their beer bellies, ponytails, and wire rimmed glasses who sit all day at a developer conf and collect packets&#8230; <u><b>ALL</u></b> <u><b>DAY</u></b> <u><b>LONG</u></b>&#8230;. how many systems do you think have been compromised this way?</p>
<p>Anywho, I believe I get a bunch more stuff done, and am able to sift through oceans of email much faster through the use of mutt and it&#8217;s friends rather then going to a point-n-click web option. What about you?</p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2010/08/31/controlling-your-inbox-efficient-email-management-with-mutt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extreme Productivity with Screen and Vim</title>
		<link>http://airodig.com/2010/08/27/extreme-productivity-with-screen-and-vim/</link>
		<comments>http://airodig.com/2010/08/27/extreme-productivity-with-screen-and-vim/#comments</comments>
		<pubDate>Fri, 27 Aug 2010 17:41:56 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[editors]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[textmate]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=471</guid>
		<description><![CDATA[A lot of people are amazed at the quantity of work I can push out in a set length of time. They assume I&#8217;m just a really good developer &#8212; I don&#8217;t think I&#8217;m bad but I know I&#8217;m definitely not the best &#8212; I know far too many other people that deserve that title. [...]]]></description>
			<content:encoded><![CDATA[<p>A lot of people are amazed at the quantity of work I can push out in a set length of time. They assume I&#8217;m just a really good developer &#8212; I don&#8217;t think I&#8217;m bad but I know I&#8217;m definitely not the best &#8212; I know far too many other people that deserve that title.</p>
<p>So what&#8217;s my secret? My tools and my workflow. I did write up a whole article on this but instead I made a short video for you all today &#8212; hopefully this is better than reading my one sentence paragraph length rants. Let me know.</p>
<p><center><br />
<iframe src="http://player.vimeo.com/video/14481789" width="400" height="300" frameborder="0"></iframe>
<p><a href="http://vimeo.com/14481789">Extreme Productivity with Screen and Vim</a> from <a href="http://vimeo.com/user3039672">feyd rautha</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p></center></p>
<p>So, in short &#8212; use vim AND use screen &#8212; make your environment comfortable to live in &#8212; as you are spending at least 8 hours if not more like 12-13 every day in it.</p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2010/08/27/extreme-productivity-with-screen-and-vim/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Garden Gnomes Sorting Flower Pots &#8212; Hamid&#8217;s StupidSort Revisited</title>
		<link>http://airodig.com/2010/08/23/garden-gnomes-sorting-flower-pots-hamids-stupidsort-revisited/</link>
		<comments>http://airodig.com/2010/08/23/garden-gnomes-sorting-flower-pots-hamids-stupidsort-revisited/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 22:20:23 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Dick Grune]]></category>
		<category><![CDATA[gnomesort]]></category>
		<category><![CDATA[o(n)]]></category>
		<category><![CDATA[o(n^2)]]></category>
		<category><![CDATA[quicksort]]></category>
		<category><![CDATA[sorting algorithm]]></category>
		<category><![CDATA[stupidsort]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=442</guid>
		<description><![CDATA[Was rolling around on hackernews a couple weeks ago and found this totally awesome audibilization/visualization of different sorting algorithims. It mentioned all the usual suspects, bubblesort, mergesort, the veritable quicksort, but towards the end I noticed one I had never heard before &#8212; gnomesort. It caught my eye because of the music it made and [...]]]></description>
			<content:encoded><![CDATA[<p>Was rolling around on hackernews a couple weeks ago and found this <a nofollow="true" href="http://www.youtube.com/watch?v=t8g-iYGHpEA">totally awesome audibilization/visualization of different sorting algorithims</a>. It mentioned all the usual suspects, bubblesort, mergesort, the veritable quicksort, but towards the end I noticed one I had never heard before &#8212; gnomesort. It caught my eye because of the music it made and how it spent most of it&#8217;s time flipping points that were closer together rather than farther apart.</p>
<p>It&#8217;s very much like insertion sort in that it only keeps track of the current item and it&#8217;s like bubblesort that uses a series of swaps but in this case it will reverse direction instead of making a pass and coming back around. <a nofollow="true" href="http://sharif.ir/~azad/">Hamid Sarbazi-Azad</a> published it in 2000 (this is probably why I&#8217;m just now finding out about it).</p>
<p>It turns out this algorithm is incredibly easy to implement &#8212; easier than bubblesort.</p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/08/Gnome_450.jpg"><img src="http://airodig.com/wp-content/uploads/2010/08/Gnome_450.jpg" alt="" title="Gnome_450" width="450" height="640" class="aligncenter size-full wp-image-480" /></a></center></p>
<p><strong>The Problem</strong></p>
<p>Imagine you are a garden gnome. You typically have your flower pots sorted by the height of the flower so you know where your belladonnas are verus the location of your daturas. Last night, some drunk punk came stumbling through your garden trying to steal your herbs and ended up mixing everything up. You, being a very methodical gnome, have to put everything back in order. The problem is, you have tunnel vision because you ate a bunch of salvia last night and while you were lost exploring the 10th dimension that drunk punk took a plumbers wrench to your head. This of course prevents you from having peripheral vision &#8212; you can only see what is in front of you. In this case you can only look at two garden pots at a time to compare them to put them back in order.</p>
<p><strong>Rules</strong><br />
Here are a few rules to get our precious plants put back in order. </p>
<blockquote><p>
You pick up two pots and measure their height.</p>
<p>If the one on the left is shorter than the one on the right move onto the next pot on the right and measure again. </p>
<p>If the one on the left is higher than the one on the right swap their position and move back one pot. </p>
<p>If you have no pots on your left move forward one pot. </p>
<p>Once you have no pots on your right you are done.
</p></blockquote>
<p>I suck at using my words &#8212; therefore let me try my best to make a pretty little picture for you (note: this took like 200X longer to make then the succeeding code, and eventually I just ended up adding description/markup to the code to generate this instead):</p>
<p><center><a href="http://airodig.com/wp-content/uploads/2010/08/pots.png"><img src="http://airodig.com/wp-content/uploads/2010/08/pots.png" alt="gnomesort" title="pots" width="475" height="439" /></a></center></p>
<p>Seems simple huh? Something that would be easier to explain to a comp. sci 53 freshmen versus bubblesort? Yeh, I think its very tiny codesize (even in c) let&#8217;s anyone understand it. Like it&#8217;s colleague, bubblesort it shares o(n) for best case and o(n^2) for worst case, so I can&#8217;t really recommend you use this for anything but learning/teaching purposes.</p>
<p>Typically you have two <u>popular</u> different groups of sorting algorithms:</p>
<ul>
<li>1) algos using recursion &#8212; (nlogn) &#8212; ex: quicksort</li>
<li>2) algos using 2 nested loops &#8212; (n^2) &#8212; ex: bubblesort</li>
</ul>
<p>Yes there are quite a few more but these are the ones mentioned usually.</p>
<p>Gnomesort is interesting though since it only has 1 loop and it&#8217;s not recursive &#8212; I don&#8217;t know where you would find yourself with limitations like these but if you do maybe you can actually use this algorithm.</p>
<p><strong>Code</strong></p>
<p>So, at first I wanted to write this up in ruby as I default to it for quick 5 minute deals like this. Turns out <a href="http://ruby-doc.org/doxygen/1.8.4/array_8c-source.html#l01602" nofollow="true">ruby apparently uses quicksort for it&#8217;s array.sort</a>. Hrm&#8230; well, I figured comparing this to quicksort in ruby wouldn&#8217;t show me anything. I&#8217;ve also been starting to write more c code lately (as I&#8217;ve not done any for closer to a decade), so I figured why not try some ruby inline?</p>
<p>To check this out you&#8217;ll need rubyinline (which you probably have if you do any rails dev at all).</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'rubygems'</span>
gem <span style="color:#996600;color: #666666;">'RubyInline'</span>
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'inline'</span>
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'benchmark'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;color: #B83A24;">class</span> <span style="color:#CC0066; font-weight:bold;color: #8FB394;">Array</span>
&nbsp;
  inline <span style="color:#9966CC; font-weight:bold;color: #B83A24;">do</span> <span style="color:#006600; font-weight:bold;color: #CCC;">|</span>builder<span style="color:#006600; font-weight:bold;color: #CCC;">|</span>
    builder.<span style="color:#9900CC;">c_raw</span> <span style="color:#996600;color: #666666;">&quot;
      static VALUE gnomesort(int argc, VALUE *argv, VALUE self) {
        long len;
        int i, tmp; 
&nbsp;
        VALUE *array = RARRAY(self)-&gt;ptr;
        len = RARRAY(self)-&gt;len;
&nbsp;
        for(i=1; i&lt;len; ){
          if(array[i-1] &lt;= array[i]) {
            ++i;
          } else {
            tmp = array[i];
            array[i] = array[i-1];
            array[i-1] = tmp;
            --i;
            if(i == 0)
               i = 1;
          }
        }
&nbsp;
        rb_iv_set(self, <span style="color:#000099;">\&quot;</span>@unit<span style="color:#000099;">\&quot;</span>, *array);
        return self;
      }
    &quot;</span>
  <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;color: #B83A24;">def</span> make_ray
  sizer = <span style="color:#006666;background-color: #000000; color: #DDD;">1000</span>
&nbsp;
  blah = <span style="color:#006600; font-weight:bold;color: #CCC;">&#91;</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#93;</span>
  1000.<span style="color:#9900CC;">times</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">do</span> <span style="color:#006600; font-weight:bold;color: #CCC;">|</span>i<span style="color:#006600; font-weight:bold;color: #CCC;">|</span>
    blah.<span style="color:#9900CC;">push</span> <span style="color:#CC0066; font-weight:bold;color: #8FB394;">rand</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#006666;background-color: #000000; color: #DDD;">1000</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
&nbsp;
  <span style="color:#0000FF; font-weight:bold;color: #577A61;">return</span> blah
<span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
&nbsp;
a = make_ray
&nbsp;
<span style="color:#CC00FF; font-weight:bold;color: #343832;">Benchmark</span>.<span style="color:#9900CC;">bmbm</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">do</span> <span style="color:#006600; font-weight:bold;color: #CCC;">|</span>x<span style="color:#006600; font-weight:bold;color: #CCC;">|</span>
  x.<span style="color:#9900CC;">report</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#996600;color: #666666;">&quot;C&quot;</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>    <span style="color:#9966CC; font-weight:bold;color: #B83A24;">do</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">for</span> i <span style="color:#9966CC; font-weight:bold;color: #B83A24;">in</span> 1..10000; a.<span style="color:#9900CC;">gnomesort</span>; <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
  x.<span style="color:#9900CC;">report</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#996600;color: #666666;">&quot;Ruby&quot;</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">do</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">for</span> i <span style="color:#9966CC; font-weight:bold;color: #B83A24;">in</span> 1..10000; a.<span style="color:#9900CC;">sort</span>; <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
<span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span></pre></div></div>

<p>Now, keep in mind, this is NOT a fair comparison towards the relative speed of these sorts:</p>
<ul>
<li> it only sorts ints not strings and so forth</li>
<li>it&#8217;s in c, the other is in ruby</li>
<li>I only tested relatively small lists &#8212; nothing in the millions or billions</li>
<li>the key size is at max 4 digits &#8212; nothing to sneeze at</li>
</ul>
<p>so take it with a grain of salt &#8212; I&#8217;m sure pretty much 9 out of 10 of my readers could easily turn that into a quicksort/radix implementation and blow it out of the water.</p>
<p>Anyways, I&#8217;m glad Hamid was encouraged to re-name this as it does bring a different perspective to the table and now I know how the music was made!</p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2010/08/23/garden-gnomes-sorting-flower-pots-hamids-stupidsort-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why Ryan is Right on Evented Architecture</title>
		<link>http://airodig.com/2010/08/17/why-ryan-is-right-on-evented-architecture/</link>
		<comments>http://airodig.com/2010/08/17/why-ryan-is-right-on-evented-architecture/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 01:42:16 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[evented]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[Scaling]]></category>
		<category><![CDATA[threads]]></category>
		<category><![CDATA[v8]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=419</guid>
		<description><![CDATA[[EDIT]: Wow, I did not intend for this many people to be seriously pissed at me/this post. If you do not like foul language and can&#8217;t take some light-hearted humor you should probably avoid this and all other posts on this site. Wow&#8230; So if you have been reading hackernews as of late no doubt [...]]]></description>
			<content:encoded><![CDATA[<p><strong>[EDIT]</strong>: Wow, I did not intend for this many people to be seriously pissed at me/this post. If you do not like foul language and can&#8217;t take some light-hearted humor you should probably avoid this and all other posts on this site. Wow&#8230;</p>
<p>So if you have been reading hackernews as of late no doubt you have seen straight up holy wars over the use of evented libraries versus threads. Frankly, I think the whole evented versus threads debate is kinda stupid and is only being used by people trying to improve their social equity off of the latest buzzwords &#8212; so I guess I&#8217;ll go ahead and enhance mine. <img src='http://airodig.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><center><a href="http://airodig.com/wp-content/uploads/2010/08/dicks1.jpg" nofollow="true"><img src="http://airodig.com/wp-content/uploads/2010/08/dicks1-300x158.jpg" alt="" title="dicks" width="300" height="158" class="aligncenter size-medium wp-image-455" /></a></center></p>
<p>So, wait, the audience cries &#8212; </p>
<div style="margin-bottom: 10px; font-size: 18px; font-weight: bold; text-align: center;">&#8220;Are you saying the whole debate is a sham?&#8221;</div>
<p>In a way, yes. If you choose to use any of numerous evented frameworks out there, chances are at some level your libraries will be utilizing their own threads. Having said that, if you <b>aren&#8217;t</b> using evented libraries you are obviously not right in the head. Let me digress.</p>
<p>We all learned in school (or on irc) that there are several different types of i/o models. I&#8217;m sure someone will want to say I&#8217;m full of shit on this but this is the way I see the world:</p>
<p><strong>I/O Models</strong></p>
<ul>
<li><u>blocking I/O</u> &#8212; wait for data and completely block the rest of the program from execution (waste of cpu time)</li>
<li><u>non-blocking I/O</u> &#8212; continously poll the kernel to see if data is ready (total cpu killer)</li>
<li><u>select/poll</u> &#8212; traditional multiplexing, blocks on select between file descriptors, waits for N fds to be ready; takes more than one syscall (more expensive)</li>
<li><u>signal driven I/O</u> &#8212; returns immediately &#038;&#038; gives us a handler</li>
<li><u>asynchronous I/O</u> &#8212; sigio tells us when we can grab data versus asynch tells us when the data has BEEN grabbed</li>
</ul>
<p><strong>You have synchronous and asynchronous driven I/O.</strong><br />
  The first four are considered synchronous because they ALL block in some form or another &#8212; the last one obtained through stuff like libaio is considered asynchronous.</p>
<p><strong>Why does this shit matter!?!</strong><br />
  This shit matters because if you have one thread you have one execution stack. Multiple threads have multiple execution stacks. When you are using asynchronous I/O you WILL NOT block said execution stack and will be able to continue with things as normal. You see, you can have your cake and eat it too!</p>
<p><b>However</b>, what a lot pro-thread, fuck-the-evented-model proponents won&#8217;t tell you is that if you have a blocking thread you are STILL blocking the rest of your threads completely defeating the purpose. A <b>ton</b> of people miss this point because frankly they have never done any systems programming and have not had to learn about it.</p>
<p>Let&#8217;s hop back to IRC for a moment. Pretend your are 14 years old again and you are planning on raiding the pentagon and fucking over your best friends quake2 server. Let&#8217;s say we aren&#8217;t interested in rooting their servers but more just interested in shitting all over it through a DoS attack so they can&#8217;t get their porn on. Our vectors of attack here are pretty easy to identify:</p>
<ul>
<li>Look for syscalls that use BLOCKING I/O &#8212; if we can queue up enough requests than we are gravy.</li>
<li>Look for places where they are not using seperate threads or processes on BLOCKING I/O.</li>
<li>Look for places where they are not setting timeouts on BLOCKING I/O.</li>
</ul>
<p>get the pattern here? blocking I/O is terrible and we are all guilty of it &#8212; I guess it&#8217;s a good thing that we have the entire goddamn military to look up to and try to emulate through FPS video games rather than hackers like ryan that want to dominate the world through computers instead. &#8212; </p>
<p>rant aside&#8230;.</p>
<p>but as someone pointed out earlier on &#8212; does it come down to the nature of the work involved? I/O or processor (reading/writing data or doing math?) really, your bottlenecks SHOULD NOT be the processor as long as you aren&#8217;t trying to re-invent bubblesort from the ground up and you are missing your left side of the brain &#8212; it should be the database, file access, and network access as the system time involved in processing that data is orders of magnitude longer than hitting the cpu or the registers &#8212; and let&#8217;s face it &#8212; all of you reading this or probably working on webapps nowadays so you are inherently dealing with databases and reading template files and so forth so this argument of &#8216;I/O versus processor&#8217; is just fucking retarded</p>
<p><a href="http://measuringmeasures.com/blog/2010/8/16/clojure-workers-and-large-scale-http-fetching.html" nofollow="true">Bradford Cross</a> says &#8220;Blocking vs. non-blocking work is related to the issues of return values vs. side effects and being invoked directly vs. polling a work queue&#8221; &#8212; what a great quote this was! &#8212; unfortunately, I&#8217;m not quite sure everyone read this article the same way I did</p>
<p>So is my suggestion to abandon threads and just fork everything? No, I hope I made it clear that both are good to have &#8212; besides fork is fucking expensive cause you have to copy everything over &#8212; even copy-on-write solutions and IPC is not the coolest thing to deal with, that and for our .NET friends &#8212; they don&#8217;t get to fork.</p>
<p><strong>so what about node?</strong></p>
<p><a href="http://nodejs.org" nofollow="true">node.js</a> brings to the table the ability to spawn thousands of connections w/out all the bullshit involved in making it safe and using ONLY ONE PROCESS &#8212; I have yet to see any implementations that make it this easy in ruby or python &#8212; yes, there are eventmachine implementations, but it&#8217;s nowhere even close to comparable, end of story, argument over, period, finale!</p>
<p><a nofollow="true" href="http://shootout.alioth.debian.org/u32/javascript.php">alioth</a> shows that v8 beats the shit out of python, ruby, perl, and java6 on a LOT of different cases&#8230;. &#8212; and when I mean beat the shit out of &#8212; I mean making pizza sauce out of it&#8217;s face.</p>
<p>Frankly, node could&#8217;ve been implemented in <b>ANY</b> language &#8212; it would not have mattered &#8212; what matters is the fact that it is shifting the paradigm of things towards evented style programming rather than betting the house on threads.</p>
<p><strong>so what&#8217;s the problem with ruby threads/et. al.?</strong></p>
<p>practically <b>ALL</b> io, file, networking, database libraries and gems are synchronous and blocking &#8212; this is the same for pretty much everything else as well, face it &#8212; we&#8217;ve been collectively programing like retards for a while and this attitude MUST change otherwise this universe&#8217;s space/time continuum will come to an end and Oersted himself will jump in from another dimension yelling at us</p>
<div style="text-align: center; margin-bottom: 10px; font-size: 18px; font-weight: bold;">&#8220;You toe-jobbing camelsuckers! I didn&#8217;t invent electromagnetism and all of modern day society for this fucking shit!&#8221;</div>
<p>The cool thing that node brings to the table is that you <b><u>can&#8217;t make</u></b> native javascript I/O (synch or asynch) calls cause javascript does not have any I/O!!! This is important to realize because it doesn&#8217;t allow a huge repository of synchronous style crap to be built upon (say in the form of the behemoth of elephant crap that rubygems is) and later wake up the next morning with a hangover wondering why you were banging that code all night and didn&#8217;t even get pictures.</p>
<p><center><a href="http://airodig.com/wp-content/uploads/2010/08/sad.jpg" nofollow="true"><img src="http://airodig.com/wp-content/uploads/2010/08/sad.jpg" alt="" title="sad" width="118" height="118" class="aligncenter size-full wp-image-452" /></a></center></p>
<p>To sum up &#8212; I think the threads vs. event loop argument is completely and utterly retarded.</p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2010/08/17/why-ryan-is-right-on-evented-architecture/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Node.js &#8212; Non Blocking Evented ServerSide Javascript</title>
		<link>http://airodig.com/2010/07/27/node-js-non-blocking-evented-serverside-javascript/</link>
		<comments>http://airodig.com/2010/07/27/node-js-non-blocking-evented-serverside-javascript/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 21:53:33 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[evented]]></category>
		<category><![CDATA[express]]></category>
		<category><![CDATA[jade]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[npm]]></category>
		<category><![CDATA[v8]]></category>
		<category><![CDATA[web frameworks]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=401</guid>
		<description><![CDATA[&#8220;Because nothing blocks, less-than-expert programmers are able to develop fast systems.&#8221; http://nodejs.org Birds Eye View of Node.js I&#8217;m sure you&#8217;ve all seen/heard stuff about using real-time websockets &#8212; this guy used node.js but a lot of ppl don&#8217;t know that there is so much more to this framework than meets the eye. First off, it [...]]]></description>
			<content:encoded><![CDATA[<p><center><br />
  <i>&#8220;Because nothing blocks, less-than-expert programmers are able to develop fast systems.&#8221;</i><br /> <a href="http://nodejs.org" nofollow="true" title="node js">http://nodejs.org</a><br />
</center></p>
<p><strong>Birds Eye View of Node.js</strong></p>
<p>I&#8217;m sure you&#8217;ve all seen/heard stuff about using <a href="http://jeffkreeftmeijer.com/2010/experimenting-with-node-js/" tite="node.js cursor demo">real-time websockets</a> &#8212; this guy used node.js but a lot of ppl don&#8217;t know that there is so much more to this framework than meets the eye.</p>
<p>First off, it has no locks, is non-blocking in as many places as possible and uses very little memory. Oh yeh, pretty much everything has a callback, following an evented model. Some POSIX operations return a &#8216;promise&#8217; which signal a &#8216;success&#8217; or &#8216;error&#8217;. Node is ridiculously powerful as you can see by reading over the api. There is so much here to do and really allows you to do some &#8216;system-level&#8217; style of programming with a whole slew of POSIX style (compliant?) system calls</p>
<p><strong>Concurrency without Multi-Threading?</strong><br />
Most of the built in hard-core concurrency comes from the evented nature of the framework. Being able to immediately respond to incoming requests while something is off reading from a database provides much needed clock cycles. Right now it appears there is no straight-forward way of utilizing multiple cores other than putting a load balancer of sorts in front and sending over unix sockets or something but there are plans to including forking in the future so that different processes may emerge taking advantage of the cores and utilize message passing to talk to each other. You can of course fork new processes using the system calls available.</p>
<p>Apparently the developers of node are looking towards using <a href="http://www.whatwg.org/specs/web-workers/current-work/" nofollow="true">web workers</a> available in HTML5 which will also alleviate some concurrency issues.</p>
<p>So who uses it? Is it production quality yet? Well, you can always ask the good folks over at <a href="http://plurk.com" title="plurk" nofollow="true">Plurk.com</a> (twitter for japan) who run it w/over 100k concurrent users &#8212; apparently this runs on one box with 8 proccesses&#8230;. uhhhh&#8230;</p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/07/wtf-pics-galactic-mugging.jpg"><img src="http://airodig.com/wp-content/uploads/2010/07/wtf-pics-galactic-mugging-241x300.jpg" alt="wtf" title="wtf-pics-galactic-mugging" width="241" height="300" class="aligncenter size-medium wp-image-437" /></a><br />
</center></p>
<p><center>&#8230;. that&#8217;s what I was thinking <strong>tha fuck!?</strong></center></p>
<p>&#8230; maybe I should go spend some time in japan &#8230; I keep finding all sorts of shit I like from there</p>
<p><strong>Hello World in Node.js</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #003366; font-weight: bold;color: #577A61;">var</span> sys <span style="color: #339933;color: #CCC;">=</span> require<span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #3366CC;color: #666666;">'sys'</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
sys.<span style="color: #660066;">puts</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #3366CC;color: #666666;">'hello!'</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span></pre></div></div>

<p>so first off we include the sys lib then we do our puts statement .. pretty simple<br />
let&#8217;s take a look at a </p>
<p><strong>Simple Node.js HTTP Server</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #003366; font-weight: bold;color: #577A61;">var</span> http <span style="color: #339933;color: #CCC;">=</span> require<span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #3366CC;color: #666666;">'http'</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
http.<span style="color: #660066;">createServer</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #003366; font-weight: bold;color: #577A61;">function</span> <span style="color: #009900;color: #CCC;">&#40;</span>req<span style="color: #339933;color: #CCC;">,</span> res<span style="color: #009900;color: #CCC;">&#41;</span> <span style="color: #009900;color: #CCC;">&#123;</span>
  res.<span style="color: #660066;">writeHead</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #CC0000;background-color: #000000; color: #DDD;">200</span><span style="color: #339933;color: #CCC;">,</span> <span style="color: #009900;color: #CCC;">&#123;</span><span style="color: #3366CC;color: #666666;">'Content-Type'</span><span style="color: #339933;color: #CCC;">:</span> <span style="color: #3366CC;color: #666666;">'text/plain'</span><span style="color: #009900;color: #CCC;">&#125;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
  res.<span style="color: #660066;">end</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #3366CC;color: #666666;">'Hello World<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
<span style="color: #009900;color: #CCC;">&#125;</span><span style="color: #009900;color: #CCC;">&#41;</span>.<span style="color: #660066;">listen</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #CC0000;background-color: #000000; color: #DDD;">8124</span><span style="color: #339933;color: #CCC;">,</span> <span style="color: #3366CC;color: #666666;">&quot;127.0.0.1&quot;</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
console.<span style="color: #660066;">log</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #3366CC;color: #666666;">'Server running at http://127.0.0.1:8124/'</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span></pre></div></div>

<p>yeh&#8230; it doesn&#8217;t really get too hard but this shows the evented nature of node &#8212; shit is retardo fast</p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/07/Wiley-Coyote-Rockets.jpg"><img src="http://airodig.com/wp-content/uploads/2010/07/Wiley-Coyote-Rockets-300x226.jpg" alt="wiley coyote rockets" title="Wiley Coyote Rockets" width="300" height="226" class="aligncenter size-medium wp-image-427" /></a><br />
</center></p>
<p><strong>Speed Demon Benches</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">ab <span style="color: #660033;">-c</span> <span style="color: #000000;background-color: #000000; color: #DDD;">100</span> <span style="color: #660033;">-n</span> <span style="color: #000000;background-color: #000000; color: #DDD;">1000</span> http:<span style="color: #000000; font-weight: bold;color: #CCC;">//</span>127.0.0.1:<span style="color: #000000;background-color: #000000; color: #DDD;">8124</span><span style="color: #000000; font-weight: bold;color: #CCC;">/</span>
Requests per second:    <span style="color: #000000;background-color: #000000; color: #DDD;">6792.23</span> <span style="color: #7a0874; font-weight: bold;color: #CCC;">&#91;</span><span style="color: #666666; font-style: italic;">#/sec] (mean)</span></pre></div></div>

<p>&#8230; but it&#8217;s not just for HTTP</p>
<p>if you have any need for networking this is a badass framework to be using. It uses a microkernel design by including modules that you need rather than a bunch of shit you <b>*might*</b> use &#8212; big win in my favor..even down to sys/http modules.</p>
<p>you can find a list of <a href="http://wiki.github.com/ry/node/modules" title="node.js modules">supporting modules here</a></p>
<p><strong>Binary Data</strong></p>
<p>I&#8217;m including this section here because when I was looking for information on sending bytes here and there I found lots of articles on the internet saying this was not easily done with node.js &#8212; this IS EASILY DONE now. You <b>CAN</b> make a buffer with binary data now and <u>NOT</u> have to specify &#8216;utf8&#8242;, &#8216;ascii&#8217;, &#8216;base64&#8242;, etc&#8230;the <i>&#8216;net2 branch&#8217;</i> that you might see referenced to on the net is already merged in and the <a href="http://nodejs.org/api.html" title="node.js api docs" nofollow="true">api docs</a> are current though can be rather confusing after reading older documentation found around&#8230;so ignore that old shit &#8212; so, just to clarify, if you are sending binary data through some random socket you can do that now.</p>
<p><strong>Want to see an example of this mysterious byte buffer?</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">  Buffer <span style="color: #339933;color: #CCC;">=</span> require<span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #3366CC;color: #666666;">'buffer'</span><span style="color: #009900;color: #CCC;">&#41;</span>.<span style="color: #660066;">Buffer</span><span style="color: #339933;color: #CCC;">;</span>
  buf <span style="color: #339933;color: #CCC;">=</span> <span style="color: #003366; font-weight: bold;color: #577A61;">new</span> Buffer<span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #CC0000;background-color: #000000; color: #DDD;">8</span><span style="color: #009900;color: #CCC;">&#41;</span><span style="color: #339933;color: #CCC;">;</span>
  <span style="color: #000066; font-weight: bold;color: #B83A24;">for</span><span style="color: #009900;color: #CCC;">&#40;</span>i <span style="color: #339933;color: #CCC;">=</span><span style="color: #CC0000;background-color: #000000; color: #DDD;">0</span><span style="color: #339933;color: #CCC;">;</span> i <span style="color: #339933;color: #CCC;">&lt;</span> <span style="color: #CC0000;background-color: #000000; color: #DDD;">8</span><span style="color: #339933;color: #CCC;">;</span> i<span style="color: #339933;color: #CCC;">+=</span><span style="color: #CC0000;background-color: #000000; color: #DDD;">1</span><span style="color: #009900;color: #CCC;">&#41;</span> <span style="color: #009900;color: #CCC;">&#123;</span> buf<span style="color: #009900;color: #CCC;">&#91;</span>i<span style="color: #009900;color: #CCC;">&#93;</span> <span style="color: #339933;color: #CCC;">=</span> <span style="color: #CC0000;background-color: #000000; color: #DDD;">0</span><span style="color: #339933;color: #CCC;">;</span> <span style="color: #009900;color: #CCC;">&#125;</span></pre></div></div>

<p><center><i>be careful as your buffer will be initialized with random data so I&#8217;d advise clearing it first</i></center></p>
<p>very interesting that you can do this now since javascript doesn&#8217;t like binary data that well</p>
<p>buffer.copy does a memcpy() &#8230;. begging to get owned by some hackers &#8212; remember to sanitize your data</p>
<p><strong>Downloading/Installing</strong></p>
<p>before doing anything else go ahead and grab the latest (as of this writing):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">wget</span> http:<span style="color: #000000; font-weight: bold;color: #CCC;">//</span>nodejs.org<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>dist<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>node-v0.1.102.tar.gz
.<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>configure <span style="color: #000000; font-weight: bold;color: #CCC;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">make</span> <span style="color: #000000; font-weight: bold;color: #CCC;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">make</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">install</span></pre></div></div>

<p>woohoo! simple build process ftw</p>
<p>want to use express? it&#8217;s pretty cool, like sinatra and it&#8217;ll allow you to get to know the most tubular npm tool.</p>
<p>let&#8217;s check our version because all of this code is bleeding edge stuff</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">feydr<span style="color: #000000; font-weight: bold;color: #CCC;">@</span>mhu:~$ node <span style="color: #660033;">-v</span>
v0.1.102</pre></div></div>

<p>also, let&#8217;s grab <a href="http://github.com/isaacs/npm" title="node.js package manager">npm</a> first:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">git clone http:<span style="color: #000000; font-weight: bold;color: #CCC;">//</span>github.com<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>isaacs<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>npm
<span style="color: #7a0874; font-weight: bold;color: #8FB394;">cd</span> npm; <span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">make</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">install</span></pre></div></div>

<p>now we can install <a href="http://expressjs.com/" nofollow="true">express</a> and it&#8217;s supporting modules that we want:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> npm <span style="color: #c20cb9; font-weight: bold;color: #577A61;">install</span> jade
<span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> npm <span style="color: #c20cb9; font-weight: bold;color: #577A61;">install</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">less</span>
<span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> npm <span style="color: #c20cb9; font-weight: bold;color: #577A61;">install</span> connect
<span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> npm <span style="color: #c20cb9; font-weight: bold;color: #577A61;">install</span> express</pre></div></div>

<p>playing with it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">mkdir</span> test<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>; <span style="color: #7a0874; font-weight: bold;color: #8FB394;">cd</span> <span style="color: #7a0874; font-weight: bold;color: #8FB394;">test</span>;
express <span style="color: #666666; font-style: italic;"># generates a new app</span>
node app.js <span style="color: #666666; font-style: italic;"># to start the server</span>
<span style="color: #666666; font-style: italic;"># switch to a diff. window</span>
curl 127.0.0.1:<span style="color: #000000;background-color: #000000; color: #DDD;">3000</span></pre></div></div>

<p>speed?<br />
much slower than native node.js but hey, it takes a lot of pain away<br />
it&#8217;s still slightly retarded fast compared to say rails and django</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">ab <span style="color: #660033;">-c</span> <span style="color: #000000;background-color: #000000; color: #DDD;">100</span> <span style="color: #660033;">-n</span> <span style="color: #000000;background-color: #000000; color: #DDD;">1000</span> http:<span style="color: #000000; font-weight: bold;color: #CCC;">//</span>127.0.0.1:<span style="color: #000000;background-color: #000000; color: #DDD;">3000</span><span style="color: #000000; font-weight: bold;color: #CCC;">/</span>
Requests per second:    <span style="color: #000000;background-color: #000000; color: #DDD;">1200.16</span> <span style="color: #7a0874; font-weight: bold;color: #CCC;">&#91;</span><span style="color: #666666; font-style: italic;">#/sec] (mean)</span></pre></div></div>

<p><strong>Support &#038;&#038; References</strong><br />
shit tons of ppl on the #node.js irc channel</p>
<p>Need something to show the boss &#8212; <a href="http://www.paulbarry.com/node/" nofollow="true">some slides</a></p>
<p>My mind is literally wheeling with the crazy shit that this framework allows you to do&#8230; particularly remotely&#8230;</p>
<p>Last thing before you leave, <a href="http://jsconf.eu/2009/video_nodejs_by_ryan_dahl.html" title="node.js presented by ryan dahl at jsconf 2009" nofollow="true">watch this</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2010/07/27/node-js-non-blocking-evented-serverside-javascript/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Stopping the OOM Pain &#8212; Removing JVM Memory Leaks</title>
		<link>http://airodig.com/2010/07/09/stopping-the-oom-pain-removing-jvm-memory-leaks/</link>
		<comments>http://airodig.com/2010/07/09/stopping-the-oom-pain-removing-jvm-memory-leaks/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 17:11:20 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[jvm]]></category>
		<category><![CDATA[memory leak]]></category>
		<category><![CDATA[profiling]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=386</guid>
		<description><![CDATA[If you are like me you probably have to be working in several different languages at any given time and monitoring more than a handful of daemons. Sometimes your tests do not catch crucial items that they should be catching. As my loyal readers might already know I do not consider myself as knowledgeable about [...]]]></description>
			<content:encoded><![CDATA[<p>If you are like me you probably have to be working in several different languages at any given time and monitoring more than a handful of daemons. Sometimes your tests do not catch crucial items that they should be catching. As my loyal readers might already know I do not consider myself as knowledgeable about the JVM and java as I should be. These past couple of days were a lesson in humliity when it comes to garbage collection on the JVM.</p>
<p>I grew up learning how to write code using C from man pages managing memory on my own. Malloc and free were my friends and I would pride myself on running <a href="http://valgrind.org" nofollow="true">valgrind</a> on a paritcular piece of code passing through it&#8217;s tests.</p>
<p><center><br />
<img src="http://airodig.com/wp-content/uploads/2010/07/final.gif" /><br />
</center></p>
<p>The JVM of course uses a managed memory model with it&#8217;s garbage collector. This means no more memory leaks right? <b>Wrong.</b></p>
<h2>Example:</h2>
<p>Let&#8217;s suppose you have an object you instantiated called Blah. Blah gets used but is never de-referenced nor does it have a way to tell the GC that it is a candidate for removing. (You never actually remove an object &#8212; you just tell the garbage collector that is is ready to be removed. </p>
<p><i>&#8221; Note the wording: Just because an object is a candidate for collection doesn&#8217;t mean it will be immediately collected.&#8221;</i> <a href="http://java.sun.com/docs/books/performance/1st_edition/html/JPAppGC.fm.html#997429" nofollow="true" />Candidate for Removal</a></p>
<p>What happens after you instantitate 300k of these Blah objects that use 80 bytes a pop? You just lost 22 meg that you won&#8217;t regain until you kill that process!</p>
<p>So to cut to the chase I had a tomcat servlet that kept dying about once a week and I didn&#8217;t allocate any time to look at it what the problem was until now as I could just restart it and everything would be peachy. I finally decided to look at it.</p>
<p>This is what I did.</p>
<h2>Get a Heap Dump</h2>
<p>First, you need to obtain a heap dump &#8212; without the heap dump you are having better luck at the casino. Chances are if you are crashing cause of an OOM memory error you won&#8217;t be able to get your heap dump from the production site &#8212; we don&#8217;t really want to screw with that anyways.</p>
<p>So, let&#8217;s duplicate our results on our dev box. Like I said before, we were looking at a tomcat servlet that was not working so in theory we should be able to hit our servlet with enough requests to trigger some heap growth.</p>
<p>I wrote a quick little script in ruby to slam our servlet, here it is:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color:#008000; font-style:italic;color: #CDC;">#!/usr/bin/ruby</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'rubygems'</span>
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'uri'</span>
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'net/http'</span>
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'cgi'</span>
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'timeout'</span>
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'open-uri'</span>
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'monitor'</span>
&nbsp;
<span style="color:#CC00FF; font-weight:bold;color: #343832;">File</span>.<span style="color:#CC0066; font-weight:bold;color: #8FB394;">open</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#996600;color: #666666;">'b.txt'</span>, <span style="color:#996600;color: #666666;">'r'</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">do</span> <span style="color:#006600; font-weight:bold;color: #CCC;">|</span>f<span style="color:#006600; font-weight:bold;color: #CCC;">|</span> <span style="color:#0066ff; font-weight:bold;color: blue;">@filetopost</span> = f.<span style="color:#9900CC;">read</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
<span style="color:#0066ff; font-weight:bold;color: blue;">@params</span> = <span style="color:#006600; font-weight:bold;color: #CCC;">&#123;</span><span style="color:#996600;color: #666666;">'text'</span> <span style="color:#006600; font-weight:bold;color: #CCC;">=&gt;</span> <span style="color:#CC00FF; font-weight:bold;color: #343832;">CGI</span>::escapeHTML<span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span>@filetopost<span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>, <span style="color:#996600;color: #666666;">'submit'</span> <span style="color:#006600; font-weight:bold;color: #CCC;">=&gt;</span> <span style="color:#996600;color: #666666;">'Submit'</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#125;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;color: #B83A24;">def</span> pingsite
  500.<span style="color:#9900CC;">times</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">do</span> <span style="color:#006600; font-weight:bold;color: #CCC;">|</span>i<span style="color:#006600; font-weight:bold;color: #CCC;">|</span>
    x = <span style="color:#6666ff; font-weight:bold;">Net::HTTP</span>.<span style="color:#9900CC;">post_form</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#CC00FF; font-weight:bold;color: #343832;">URI</span>.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#996600;color: #666666;">'http://127.0.0.1:8080/upload/process'</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>, <span style="color:#0066ff; font-weight:bold;color: blue;">@params</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
    <span style="color:#CC0066; font-weight:bold;color: #8FB394;">puts</span> i
  <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
<span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
&nbsp;
threads = <span style="color:#006600; font-weight:bold;color: #CCC;">&#91;</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#93;</span>
<span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span>1..20<span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">do</span> <span style="color:#006600; font-weight:bold;color: #CCC;">|</span>i<span style="color:#006600; font-weight:bold;color: #CCC;">|</span>
  threads <span style="color:#006600; font-weight:bold;color: #CCC;">&lt;&lt;</span> <span style="color:#CC00FF; font-weight:bold;color: #343832;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">do</span>
    pingsite
  <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
<span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
&nbsp;
threads.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">do</span> <span style="color:#006600; font-weight:bold;color: #CCC;">|</span>t<span style="color:#006600; font-weight:bold;color: #CCC;">|</span>
  t.<span style="color:#9900CC;">join</span>
<span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span></pre></div></div>

<p>This essentially as you might have guessed posts the contents of a text file through a form to our servlet for processing (text into xml). It makes 10k requests (500 at 20 threads).</p>
<p><b>BEFORE</b> you run this you&#8217;ll want to hop into jconsole. <a href="http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html" nofollow="true">JConsole</a> will allow you to watch the action live as you see your heap grow and be garbage collected. You&#8217;ll see that the faster the heap grows the faster the garbage collector will start to run so your graph will start to have it&#8217;s lines closer together. What you are wanting to do here is just make the graph curve upward &#8212; that&#8217;s it.</p>
<p>Once you have a graph that looks like this:</p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/07/heap.png"><img src="http://airodig.com/wp-content/uploads/2010/07/heap-162x300.png" alt="" title="heap" width="162" height="300" class="aligncenter size-medium wp-image-403" /></a><br />
</center></p>
<p>we are ready for the next step. This graph actually grew up into the 400s and was much more pronounced by the time my 10k requests were done &#8212; all you really need to do is show proof that there is a growth &#8212; the more the merrier as it should help you drill down more easily to determine what is piling up.</p>
<h2>Dump the Heap</h2>
<p>Find out the process we need to dump:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">ps</span> aux <span style="color: #000000; font-weight: bold;color: #CCC;">|</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">grep</span> tomcat</pre></div></div>

<p>dump it:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">jmap -dump:live,<span style="color: #007800;">format</span>=b,<span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">file</span></span>=heap.bin <span style="color: #000000;background-color: #000000; color: #DDD;">6608</span></pre></div></div>

<p>The dump will need to be initiated by the same user owning the tomcat process or someone with perms for it (tomcat6, root, joebob, whatever).</p>
<p>Great! Let&#8217;s take a quick look at the size</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">ls</span> <span style="color: #660033;">-lh</span> heap.bin</pre></div></div>

<p>200 meg! WTF!?</p>
<h2>Get Relevant Stats</h2>
<p>Ok, now let&#8217;s hop into jvisualvm (visualvm). I went ahead and changed the perms on the dump file so I could run it as my own user. Once in visualvm we want to go to our classes view in the top right hand corner. From here we can sort by # of instances or % of how much the heap is towards the object. I focused on instance count because that seemed like something that would let me know what was up. I noticed that at least one thing was wrong here. I had something like 300k prepared statement instances being built &#8212; what the fuck?! </p>
<h2>Fix the Problem</h2>
<p>So I went back to my code and did a .close() on them.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">        <span style="color: #666666; font-style: italic;color: #CDC;">// note this is scala</span>
        pStmt.<span style="color: #006633;">executeUpdate</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #009900;color: #CCC;">&#41;</span>
&nbsp;
        pStmt.<span style="color: #006633;">close</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #009900;color: #CCC;">&#41;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;color: #B83A24;">if</span><span style="color: #009900;color: #CCC;">&#40;</span>stmt <span style="color: #339933;color: #CCC;">!=</span> <span style="color: #000066; font-weight: bold;color: #577A61;">null</span><span style="color: #009900;color: #CCC;">&#41;</span> <span style="color: #009900;color: #CCC;">&#123;</span>
          stmt.<span style="color: #006633;">close</span><span style="color: #009900;color: #CCC;">&#40;</span><span style="color: #009900;color: #CCC;">&#41;</span>
        <span style="color: #009900;color: #CCC;">&#125;</span></pre></div></div>

<h2>Measure Again to Ensure the Problem is Fixed</h2>
<p>After this was done we compile our jar, throw it back to our servlet, <b>restart</b> tomcat and run through our bulk POSTing again. The theory here is that we should be able to have a noticeable impact our instance count for prepared statements and have a noticeably different graph as well. I did not know that simply copying your webapp over to the root directory was not enough &#8212; you NEED to restart tomcat to get accurate results as items in the PermGen space will be duplicated if you simply copy a new webapp over (and after doing that a couple of times you&#8217;ll find a nice little PermGen OOM error in your catalina log files.)</p>
<p>Here&#8217;s the new graph:</p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/07/dramatic.jpg"><img src="http://airodig.com/wp-content/uploads/2010/07/dramatic-160x300.jpg" alt="" title="dramatic" width="160" height="300" class="aligncenter size-medium wp-image-404" /></a><br />
</center></p>
<p>The new heap size is :<b>20 meg!!</b></p>
<p>Well, we might not have squashed all of our bugs but I&#8217;d bet good money that this servlet doesn&#8217;t die again in the next week or so.</p>
<h2>Other Profiling Tools I Used but Did not Like:</h2>
<p><b>jhat</b>: I tried this out and it seems like it is supposed to be used on remote servers, however, there was absolute NO thought put into making it a nice UI to use by a human and it didn&#8217;t particularly lend itself well to a computer looking at information so frankly I think it&#8217;s a piece of shit.</p>
<p><b>Memory Analyzer</b>: Speaking of piece of shit, this rotten crap came with Eclipse (now, I have my own opinions about how horrible eclipse is to begin with so maybe that&#8217;s just my prejudice rubbing off) but this kept crashing every fucking time I tried to load the heap. I tried passing in the arguments -Xms128m -Xmx1024m and all but it just did not like me. Fuck it &#8212; I got the job done regardless.</p>
<p>Anyways, I hope this information was somewhat useful for someone else &#8212; while documentation exists on the internet for this it wasn&#8217;t the most readily available info.</p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2010/07/09/stopping-the-oom-pain-removing-jvm-memory-leaks/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Join the Sax Parsing Party</title>
		<link>http://airodig.com/2010/07/01/join-the-sax-parsing-party/</link>
		<comments>http://airodig.com/2010/07/01/join-the-sax-parsing-party/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 03:24:03 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=388</guid>
		<description><![CDATA[Many people utilize the DOM based parsing methods available in easy to use libraries throughout most languages but few ever need to utilize the power of SAX. Let me invite you to the party! We&#8217;ve all been there &#8212; we need to parse an xml document so we pull out some xpath expression and get [...]]]></description>
			<content:encoded><![CDATA[<p>Many people utilize the DOM based parsing methods available in easy to use libraries throughout most languages but few ever need to utilize the power of SAX. Let me invite you to the party!</p>
<p>We&#8217;ve all been there &#8212; we need to parse an xml document so we pull out some xpath expression and get to work on grabbing our little bit of data from our document.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">token = <span style="color:#6666ff; font-weight:bold;">REXML::XPath</span>.<span style="color:#9900CC;">first</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span>doc, <span style="color:#996600;color: #666666;">&quot;/books/title/&quot;</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span></pre></div></div>

<p>This works great and is easy to use no matter your language of choice for <b>MOST</b> things. Now, let&#8217;s pretend this particular document is 10 meg &#8212; fuck that, let&#8217;s pretend it&#8217;s 100 meg &#8212; actually let&#8217;s get real and call it 2.5 gig of xml. </p>
<p><center><b><i>2.5!!! WTF!? That won&#8217;t fit into my memory!?!?</i></b></center></p>
<p>No, it won&#8217;t if you are using DOM parsing since that is based upon building a tree. That is if you are willing to wait for the fucker to even load itself into the tree &#8212; forget the memory usage.</p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/07/xml-rom-tree.png"><img src="http://airodig.com/wp-content/uploads/2010/07/xml-rom-tree-300x152.png" alt="" title="xml-rom-tree" width="300" height="152" class="aligncenter size-medium wp-image-394" /></a><br />
</center></p>
<p>I ran into this problem earlier today &#8212; memory hit a little over what the document size was in htop but the cpu just kept <a href="http://www.youtube.com/watch?v=eFTLKWw542g">burning while the world was turning</a>. I eventually killed it and contemplated splitting the xml apart &#8212; of course &#8230; I was going to run into the exact same problem if I continued to utilize the old worn out DOM parsing methods.</p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/07/fuuu.png"><img src="http://airodig.com/wp-content/uploads/2010/07/fuuu-300x224.png" alt="" title="fuuu" width="300" height="224" class="aligncenter size-medium wp-image-395" /></a><br />
</center></p>
<p>This is when I was turned onto SAX parsing from some random mailing list plea for help. All I need to know I learnt from man pages and mailing lists. I had ran across SAX in the past but was not too excited that I had to prepare a language <b>JUST</b> to parse my document rather than pass it some tried and true xpath &#8212; basically I was used to parsing html DOM &#8212; NOT million line xml documents. I had read that it was faster in the past but my feeble attempts at comparing documents of the 200k size were just an exercise in futility to find any meaning in using SAX. </p>
<p><center><br />
<i>Needless to say knowing the power of SAX is like shooting Columbian cocaine, XPath is drinking a pot of coffee, and regex is getting punched in the nuts while you are asleep.</i><br />
</center></p>
<p>Now let me address the audience in what happened. That little job I killed that was bitch-smacking one of my cores around for over 10 minutes and using over 10% of 6gig of memory did the EXACT same extraction under 10 seconds utilizing something like 0.1% of memory and only 70%ish CPU. I, to use the phrase slightly, shit a fucking brick!</p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/07/ShitBrick.jpg"><img src="http://airodig.com/wp-content/uploads/2010/07/ShitBrick-300x227.jpg" alt="" title="ShitBrick" width="300" height="227" class="aligncenter size-medium wp-image-391" /></a><br />
</center></p>
<p>Want to see an utterly contrived example of pulling 40+k urls from a sitemap which tied up my cores for-fucking-ever using old style DOM parsing but was done in less than 10 seconds with SAX?</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'rexml/document'</span>
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'rexml/streamlistener'</span>
<span style="color:#CC0066; font-weight:bold;color: #8FB394;">require</span> <span style="color:#996600;color: #666666;">'mysql'</span>
<span style="color:#9966CC; font-weight:bold;color: #B83A24;">include</span> REXML
&nbsp;
MY = Mysql.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#996600;color: #666666;">&quot;host&quot;</span>, <span style="color:#996600;color: #666666;">&quot;luser&quot;</span>, <span style="color:#996600;color: #666666;">&quot;assword&quot;</span>, <span style="color:#996600;color: #666666;">&quot;dbname&quot;</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;color: #B83A24;">class</span> ParseThatShit
  <span style="color:#9966CC; font-weight:bold;color: #B83A24;">include</span> <span style="color:#6666ff; font-weight:bold;">REXML::StreamListener</span>
  <span style="color:#9966CC; font-weight:bold;color: #B83A24;">def</span> tag_start<span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#006600; font-weight:bold;color: #CCC;">*</span>args<span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;color: #B83A24;">def</span> text<span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span>data<span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;color: #577A61;">return</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">if</span> data =~ <span style="color:#006600; font-weight:bold;color: #CCC;">/</span>^\w<span style="color:#006600; font-weight:bold;color: #CCC;">*</span>$<span style="color:#006600; font-weight:bold;color: #CCC;">/</span>
    <span style="color:#0000FF; font-weight:bold;color: #577A61;">return</span> <span style="color:#9966CC; font-weight:bold;color: #B83A24;">if</span> data =~ <span style="color:#006600; font-weight:bold;color: #CCC;">/</span>\d\.\d<span style="color:#006600; font-weight:bold;color: #CCC;">/</span>
    st = MY.<span style="color:#9900CC;">prepare</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#996600;color: #666666;">&quot;insert into links (name) values (?)&quot;</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
    st.<span style="color:#9900CC;">execute</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span>data<span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
    st.<span style="color:#9900CC;">close</span>
  <span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
<span style="color:#9966CC; font-weight:bold;color: #B83A24;">end</span>
&nbsp;
pts = ParseThatShit.<span style="color:#9900CC;">new</span>
xmlfile = <span style="color:#CC00FF; font-weight:bold;color: #343832;">File</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span><span style="color:#996600;color: #666666;">&quot;big-ass-sitemap.xml&quot;</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span>
Document.<span style="color:#9900CC;">parse_stream</span><span style="color:#006600; font-weight:bold;color: #CCC;">&#40;</span>xmlfile, pts<span style="color:#006600; font-weight:bold;color: #CCC;">&#41;</span></pre></div></div>

<p>Remember boys and girls &#8212; this <b>Example</b> is just an example to show you the power of SAX &#8212; does it take more LOC than a 3 line xpath block? Yeh, but so does your mother.</p>
<p>Use the power of SAX and drink the spice while you slip into the higher dimension of parsing power!</p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2010/07/01/join-the-sax-parsing-party/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dancing Your Way into EffortLess Web Development with Dancer and Perl</title>
		<link>http://airodig.com/2010/05/26/dancing-your-way-into-effortless-web-development-with-dancer-and-perl/</link>
		<comments>http://airodig.com/2010/05/26/dancing-your-way-into-effortless-web-development-with-dancer-and-perl/#comments</comments>
		<pubDate>Wed, 26 May 2010 20:27:56 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dancer]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=352</guid>
		<description><![CDATA[Sentiments found on hackernews and dzone recently regarding Perl: &#8220;fuck a bunch of perl monk motherfuckers!&#8221; &#8220;perl sucks!&#8221; &#8220;perl can suck a dick!&#8221; ok, well that was slightly exagerrated =) but .. so seems the sentiment sometimes browsing certain portions of the net (dzone, hackernews, etc.) Really, imo perl was one of the first dynamic [...]]]></description>
			<content:encoded><![CDATA[<h1 style="margin: 10px;">Sentiments found on hackernews and dzone recently regarding Perl:</h1>
<p> <u style="font-size: 18px; margin: 10px;">&#8220;fuck a bunch of perl monk motherfuckers!&#8221;</u></p>
<p> <u style="font-size: 18px; margin: 10px;">&#8220;perl sucks!&#8221;</u></p>
<p> <u style="font-size: 18px; margin: 10px;">&#8220;perl can suck a dick!&#8221;</u></p>
<p>ok, well that was slightly exagerrated =)</p>
<p>but .. so seems the sentiment sometimes browsing certain portions of the net<br />
(dzone, hackernews, etc.)</p>
<p>Really, imo perl was one of the first dynamic interpreted languages that a <strong>LOT</strong> of people<br />
got on board with and really opened the door to web development&#8230; say what<br />
you want but perl was the &#8220;first web language&#8221;™</p>
<h2>Dancer</h2>
<p>A couple of weeks I ran into <a href="http://perldancer.org/" title="perl web framework" nofollow="true">dancer</a>. I was really quite interested because it&#8217;s cousin,<br />
<a href="http://www.sinatrarb.com/" title="sinatra rub framework" nofollow="true">sinatra</a> from rubyland is my favorite framework from that language.</p>
<p>I have to admit that I have not used perl for a while but I had dancer up and tapping it&#8217;s toes<br />
within minutes and it is pretty damn fast.</p>
<p>can I sum it up?<br />
yes &#8230;. dancer turns perl web development from this&#8230;<br />
<center><br />
<a href="http://airodig.com/wp-content/uploads/2010/05/perl.jpg"><img src="http://airodig.com/wp-content/uploads/2010/05/perl-270x300.jpg" alt="perl" title="perl" width="270" height="300" class="aligncenter size-medium wp-image-358" /></a><br />
</center></p>
<p><center><br />
into this&#8230;<br />
</center></p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/05/perl-camel.jpg"><img src="http://airodig.com/wp-content/uploads/2010/05/perl-camel-231x300.jpg" alt="marlboros camel" title="perl-camel" width="231" height="300" class="aligncenter size-medium wp-image-366" /></a><br />
</center</p>
<h2>installing</h2>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">feydr<span style="color: #000000; font-weight: bold;color: #CCC;">@</span>mhu:~$ <span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> cpan Dancer</pre></div></div>

<p>cpan will block when it&#8217;s dling new modules so make sure to pay attn to any visual beeps if you are in screen or something, or you could always use expect or whatever</p>
<p><strong>Sample Hello World written in Dancer</strong></p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #666666; font-style: italic;color: #CDC;">#!/usr/bin/perl</span>
&nbsp;
<span style="color: #000000; font-weight: bold;color: #577A61;">use</span> Dancer<span style="color: #339933;color: #CCC;">;</span>
&nbsp;
get <span style="color: #ff0000;">'/hi'</span> <span style="color: #339933;color: #CCC;">=&gt;</span> <span style="color: #000000; font-weight: bold;color: #577A61;">sub</span> <span style="color: #009900;color: #CCC;">&#123;</span>
  <span style="color: #ff0000;color: #666666;">&quot;Hello World!&quot;</span>
<span style="color: #009900;color: #CCC;">&#125;</span><span style="color: #339933;color: #CCC;">;</span>
&nbsp;
dance<span style="color: #339933;color: #CCC;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;">feydr<span style="color: #000000; font-weight: bold;color: #CCC;">@</span>mhu:~$ <span style="color: #c20cb9; font-weight: bold;color: #577A61;">perl</span> .<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>hi.pl</pre></div></div>

<p>hit it up at: http://127.0.0.1:3000/hi</p>
<p><strong>Some Slightly Drunken Made Benchmarks:</strong><br />
<i>That last red bar should be at 672 request/second.</i></p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/05/benches.jpg"><img src="http://airodig.com/wp-content/uploads/2010/05/benches-300x150.jpg" alt="" title="benches" width="300" height="150" class="aligncenter size-medium wp-image-362" /></a><br />
</center></p>
<p>need some more example code? check out the <a nofollow="true" href="http://github.com/sukria/perldancer-website" title="dancer website source">dancer website source</a> built using dancer</p>
<h2>Deploying Dancer into Production</h2>
<p>I&#8217;d avoid abusing this <strong>ass-rocking software</strong> with something as terrible as apache as you just won&#8217;t get the same performance and you&#8217;ll have to do stupid CGI/FastCGI tricks. However, if you must use apache (because you are already using it for 10 other websites on the same box) then you can still use PSGI.</p>
<p>Dancer runs best under <a nofollow="true" href="http://plackperl.org/" title="PSGI/PLACK">PSGI/PLACK</a></p>
<p>Wait! What the fuck is that shit? PSGI is a spec akin to Python&#8217;s <a href="http://wsgi.org/wsgi/" title="WSGI" nofollow="true">WSGI</a> while PLACK is to <a title="ruby rack" nofollow="true" href="http://rack.rubyforge.org/">ruby&#8217;s Rack</a>.</p>
<p>confused? just use <strong><a href="http://github.com/miyagawa/Starman" title="starman -- perl web server" nofollow="true">Starman</a>!!</strong>&#8211; <a href="http://search.cpan.org/~miyagawa/Starman-0.1000/lib/Starman.pm" title="starman" nofollow="true">Perl Reference</a></p>
<p><strong>StarMan Features</strong></p>
<ul>
<li>preforking web server that reaps dead kids and does auto restarts</li>
<li>can utilize unix sockets</li>
<li>very little memory footprint (like 7-12 meg little)</li>
<li>No Win32 Support, yes this is a feature</li>
</ul>
<p>It&#8217;s also written by Japanese hackers. I don&#8217;t think I need to mention why Japanese hackers rock..</p>
<p><center><a href="http://airodig.com/wp-content/uploads/2010/05/yukihiro_matsumoto.jpg"><img src="http://airodig.com/wp-content/uploads/2010/05/yukihiro_matsumoto-201x300.jpg" alt="Yukihiro Matsumoto" title="yukihiro_matsumoto" width="201" height="300" class="aligncenter size-medium wp-image-355" /></a><br />
</center></p>
<p>back to dancer&#8230;</p>
<p><strong>supported session engines by default:</strong></p>
<ul>
<li>memory (no persistence &#8212; useful for debugging)</li>
<li>yaml file-based (puke!)</li>
<li>memcached (distributed production env ftw!)</li>
<li>cookie (make sure you protect your shit from timing attacks)</li>
</ul>
<p><strong>other features:</strong></p>
<ul>
<li>wilcard routing path matching</li>
<li>before filters</li>
</ul>
<p>In comparison to Catalyst? Well, the most obvious is that Dancer is light-weight &#8212; like cheerleader on prom night light-weight.</p>
<h2>In Closing</h2>
<p>For my next &#8216;small&#8217; project this will probably be written with Dancer rather than Sinatra.<br />
Yes, the terse syntax of perl might not meet the eloquence of ruby but for memory usage<br />
Dancer will win hands down everytime.</p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2010/05/26/dancing-your-way-into-effortless-web-development-with-dancer-and-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Oriented with OrientDB</title>
		<link>http://airodig.com/2010/05/22/getting-oriented-with-orientdb/</link>
		<comments>http://airodig.com/2010/05/22/getting-oriented-with-orientdb/#comments</comments>
		<pubDate>Sat, 22 May 2010 18:46:47 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[document database]]></category>
		<category><![CDATA[graph database]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[nosql]]></category>
		<category><![CDATA[orientdb]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=341</guid>
		<description><![CDATA[Was on the nosql mailing list the other day and I ran across a message from Cliff Moon trolling it up &#8220;I find the name of your database to be extremely racist.&#8221; To tell you the truth I usually am ctrl-D&#8217;ng (mutt mass deleting) all threads from this mailing list since I just do not [...]]]></description>
			<content:encoded><![CDATA[<p>Was on the nosql mailing list the other day and I ran across a <a href="http://groups.google.com/group/nosql-discussion/browse_thread/thread/9195b95348477716/9b150aefddcd2718#msg_b4fb3cc1dfffed63">message</a> from <a href="http://twitter.com/moonpolysoft">Cliff Moon</a> trolling it up </p>
<p><center></p>
<h2>
<b><i>&#8220;I find the name of your database to be extremely racist.&#8221;</i></b><br />
</h2>
<p></center></p>
<p>To tell you the truth I usually am ctrl-D&#8217;ng (mutt mass deleting) all threads from this mailing list since I just do not have time to read them all. This of course caught my eye though and I&#8217;ve been waiting for a day to set aside some time to write up an article on it. So that day is today and this is that article.</p>
<p>These guys make a TON of claims and the description page is chockful of buzzwords describing what exactly OrientDB is. Let&#8217;s take a quick look.<br />
<strong>Features</strong></p>
<ul>
<li>Written in Java</li>
<li>40k inserts/second on commodity hardware</li>
<li>Document/Graph Based DataBase</li>
<li>Supports Schema-less, schema-full, schema-mixed modes</li>
<li>Security Profiling for users/roles Based Access</li>
<li>Supports SQL as a query language</li>
<li>ACID compliant with support for transactions</li>
<li>Less than 400k Footprint for Full Server (embeddable)</li>
</ul>
<p>It is truthly very easy to get started unlike other solutions out there. It unfortuantely has a XML config file but the default one that comes with the release I downloaded (0.9.13) clocks in at only 22 lines and is fairly readable. It listens for binary connections on port 2424 by default and a built-in web interface on 2480 by default. The <a href="http://orient.googlecode.com/files/orient-database-0.9.14.zip">package I downloaded</a> came with jars ready to go so there was no bullshit to configure or anything but if you grab sources ant should work things out for you.</p>
<p><b>Example:</b></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">svn</span> checkout https:<span style="color: #000000; font-weight: bold;color: #CCC;">//</span>orient.googlecode.com<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>svn<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>trunk<span style="color: #000000; font-weight: bold;color: #CCC;">/</span> orient
<span style="color: #7a0874; font-weight: bold;color: #8FB394;">export</span> <span style="color: #007800;">JAVA_HOME</span>=<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>usr<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>lib<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>jvm<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>java-<span style="color: #000000;background-color: #000000; color: #DDD;">6</span>-sun-1.6.0.20<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>
<span style="color: #c20cb9; font-weight: bold;color: #577A61;">chmod</span> a+x build.sh
.<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>build.sh</pre></div></div>

<p>Like any good startup script it proudly displays it&#8217;s ascii logo.<br />
It really is quite a nice little web interface I have to admit. For those of you who have/want to care about licenses it is under the Apache 2.0 License. There are currently 12 members on it&#8217;s <a href="http://groups.google.com/group/orient-database/about">google groups mailing list</a>.</p>
<p><strong>Web Interface</strong><br />
The web interface has a RESTful interface that supports GET, PUT, POST, and DELETE operations. This is really cool because then you can do all your requests with javascript and pull down result sets with json. Being able to put this crap behind a load balancer allows you to scale like a motherfucker when it comes to reads, which is one reason why other databases that have RESTful interfaces caught on so quickly. It has a built in profiler that really rocks out and I firmly believe all software should have built in shit like this &#8212; it is just common sense for applications like this. There are tabs right next to it that show you configurations, connections and and database pools &#8212; cool stuff indeed.</p>
<div id="attachment_348" class="wp-caption aligncenter" style="width: 310px"><a href="http://airodig.com/wp-content/uploads/2010/05/profiler.png"><img src="http://airodig.com/wp-content/uploads/2010/05/profiler-300x168.png" alt="OrientDB Profiler" title="profiler" width="300" height="168" class="size-medium wp-image-348" /></a><p class="wp-caption-text">OrientDB Profiler</p></div>
<p>The schema view is pretty cool as well as you can see all of your classes (tables) , their record count and their cluster count. Physical clusters make for fast IO, whereas logicals save space but are slower. Of course in the day and age of pocket terrabyte storage drives &#8212; who the hell needs more space? We need ram and cpu damnit!</p>
<p><strong>Security</strong><br />
I must say that out of all the NoSQL solutions out there <a href="http://www.orientechnologies.com/">OrientDB</a> really fucking shines with it&#8217;s security built-in from the get-go &#8212; almost every other system out there has added it on as an *optional* feature &#8212; as if security should ever be treated that way &#8212; it&#8217;s like modern day programmers for some reason still do not know that 14 year old kids have scripts that scan the net for open things like this &#8212; some mid-20s kids have those exact same scripts. <img src='http://airodig.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Apparently the underlying data structure is a &#8220;RB+Tree&#8221; which as the authors point out is a mix of Red-Black and B+ Tree algos &#8212; this they assert give you the best mix of balancing, speed, and 50% less memory usage.</p>
<p>All in all this is a pretty nice offering and I might need to play with again here in the future. I have a couple million xml documents I&#8217;m thinking about transforming to json. What are your thoughts on this fellow readers?</p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2010/05/22/getting-oriented-with-orientdb/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Play with Java and Scala Web Apps</title>
		<link>http://airodig.com/2010/04/27/play-with-java-and-scala-web-apps/</link>
		<comments>http://airodig.com/2010/04/27/play-with-java-and-scala-web-apps/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 19:56:59 +0000</pubDate>
		<dc:creator>feydr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[play]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[test]]></category>
		<category><![CDATA[webapps]]></category>

		<guid isPermaLink="false">http://airodig.com/?p=323</guid>
		<description><![CDATA[I got wind of the play framework a couple of months ago and have been passively reading their mailing list each day. I have to say &#8212; it&#8217;s very active and the framework is just top notch. We here at telematter have used a lot of the frameworks in ruby land and our main app [...]]]></description>
			<content:encoded><![CDATA[<p>I got wind of the <a href="http://playframework.org">play framework</a> a couple of months ago and have been passively reading their mailing list each day. I have to say &#8212; it&#8217;s very active and the framework is just top notch. We here at <a href="http://telematter.com">telematter</a> have used a lot of the frameworks in ruby land and our main app is written in merb. Lately though merb has become a ghost-town of support, documentation, and community involvement. Upgrading a server takes an exorbinant amount of time, patience and the willingness <b>NOT</b> to throw you computer through the window.</p>
<p><a href="http://yehudakatz.com/2010/04/17/ruby-require-order-problems/">Dependencies are a big problem</a> here but so are the tests. With the ruby community&#8217;s ever so crushing pride about various ways to accomplish a task you usually wind up having to either pick between the options of using a LOT of plugins/dependencies or not using any. Also, you know you have problems when after spending the better part of a morning upgrading your dev environment you can&#8217;t run your tests.</p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/04/for-your-butthole.gif"><img src="http://airodig.com/wp-content/uploads/2010/04/for-your-butthole-263x300.gif" alt="" title="for-your-butthole" width="263" height="300" class="aligncenter size-medium wp-image-332" /></a><br />
</center></p>
<p>So we started looking at different web application frameworks. We have a rather large existing codebase in java already to do some text parsing but xml config files and the ever-growing concern of java developers to deal with encapsulation in the most fucked up manner imaginable leads us having java with a sour taste in our mouths. Scala on the other hand has been what I have deemed <i><b>&#8220;what java SHOULD have been&#8221;</b></i>. Seriously, that language is so elegant compared to it&#8217;s predecessor that they should just scrap everything and move on from that point forward. The JVM is really solid shit but java itself &#8212; ehh&#8230;</p>
<p>Anyways on to the meat of this quick article. Why do I like play?</p>
<ul>
<li> class reloading</li>
<li> easy setup</li>
<li>fucking awesome test runner</li>
<li> great documentation &#038;&#038; active community </li>
<li> NO xml config files </li>
<li> use with scala </li>
</ul>
<h2>Class Reloading</h2>
<p>  Do I even need to explain this one? Having the ability to reload your classes on the fly without having to go through configuration hell is so ridiculously helpful it&#8217;s insane. Your development productivity will gain leaps and bounds and with integrated auto-testing you are assured a winner.</p>
<h2>Easy Setup</h2>
<p>  It does not get easier than a:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"><span style="color: #c20cb9; font-weight: bold;color: #577A61;">wget</span> http:<span style="color: #000000; font-weight: bold;color: #CCC;">//</span>download.playframework.org<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>releases<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>play-1.0.2.1.zip
<span style="color: #c20cb9; font-weight: bold;color: #577A61;">unzip</span> play<span style="color: #000000; font-weight: bold;color: #CCC;">*</span>
<span style="color: #c20cb9; font-weight: bold;color: #577A61;">sudo</span> <span style="color: #c20cb9; font-weight: bold;color: #577A61;">cp</span> <span style="color: #660033;">-R</span> play<span style="color: #000000; font-weight: bold;color: #CCC;">*</span> <span style="color: #000000; font-weight: bold;color: #CCC;">/</span>usr<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>bin<span style="color: #000000; font-weight: bold;color: #CCC;">/</span>play
play new my_new_app
play run</pre></div></div>

<h2>Fucking Awesome Test Runner</h2>
<p> I need to attach these screenshots to show you the awesomeness of this.</p>
<p><b>Test Index</b><br />
<center><br />
<a href="http://airodig.com/wp-content/uploads/2010/04/Screenshot.png"><img src="http://airodig.com/wp-content/uploads/2010/04/Screenshot-300x168.png" alt="play framework test index" title="play framework test index" width="300" height="168" class="aligncenter size-medium wp-image-324" /></a><br />
</center></p>
<p><b>Selenium Test Runner</b></p>
<p><center><br />
<a href="http://airodig.com/wp-content/uploads/2010/04/Screenshot-1.png"><img src="http://airodig.com/wp-content/uploads/2010/04/Screenshot-1-300x168.png" alt="play framework selenium test" title="play framework selenium test" width="300" height="168" class="aligncenter size-medium wp-image-326" /></a><br />
</center></p>
<h2>Great Documentation &#038;&#038; Active Community </h2>
<p>  When you first boot up Play (and it boots FAST) you will find that you have all the basics to start hacking up the HelloWorld into whatever you wish. A simple click of the mouse gives you your environment settings (which show you everything from paths to thread info, to monitors). Play also has a cool little route built in http://127.0.0.1:9000/@documentation that has screencasts, sample apps, faqs, and pretty much everything you need to know to start playing around.</p>
<p>  Admittedly there were only 12 users online in IRC earlier today when I wrote it but the mailing list has ~30 emails/day with active development/discussion.</p>
<h2>NO XML Config Files </h2>
<p> Yes, that&#8217;s right ladies and gentlemen &#8212; no goddamn config files written in fucking XML. WTF! Your main config file, application.conf is just your basic java properties set &#8212; no need to get all crazy and declare everything under the sun.</p>
<p>  What&#8217;s the routes look like?</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;background-color: #000000; color: #FCFFBA;"># Routes
# <span style="color: #000000; font-weight: bold;color: #B83A24;">This</span> file defines all application routes <span style="color: #009900;color: #CCC;">&#40;</span>Higher priority routes first<span style="color: #009900;color: #CCC;">&#41;</span>
# ~~~~
&nbsp;
# Home page
GET     <span style="color: #339933;color: #CCC;">/</span>                                       Application.<span style="color: #006633;">index</span>
&nbsp;
# <span style="color: #003399;color: #8FB394;">Map</span> <span style="color: #000000; font-weight: bold;color: #B83A24;">static</span> resources from the <span style="color: #339933;color: #CCC;">/</span>app<span style="color: #339933;color: #CCC;">/</span><span style="color: #000000; font-weight: bold;color: #B83A24;">public</span> folder to the <span style="color: #339933;color: #CCC;">/</span><span style="color: #000000; font-weight: bold;color: #B83A24;">public</span> path
GET     <span style="color: #339933;color: #CCC;">/</span><span style="color: #000000; font-weight: bold;color: #B83A24;">public</span><span style="color: #339933;color: #CCC;">/</span>                                staticDir<span style="color: #339933;color: #CCC;">:</span><span style="color: #000000; font-weight: bold;color: #B83A24;">public</span>
&nbsp;
# <span style="color: #000000; font-weight: bold;color: #B83A24;">Catch</span> all
<span style="color: #339933;color: #CCC;">*</span>       <span style="color: #339933;color: #CCC;">/</span><span style="color: #009900;color: #CCC;">&#123;</span>controller<span style="color: #009900;color: #CCC;">&#125;</span><span style="color: #339933;color: #CCC;">/</span><span style="color: #009900;color: #CCC;">&#123;</span>action<span style="color: #009900;color: #CCC;">&#125;</span>                  <span style="color: #009900;color: #CCC;">&#123;</span>controller<span style="color: #009900;color: #CCC;">&#125;</span>.<span style="color: #009900;color: #CCC;">&#123;</span>action<span style="color: #009900;color: #CCC;">&#125;</span></pre></div></div>

<p>yeh&#8230;.. they are that simple looking</p>
<h2>Use with Scala </h2>
<p>  There is a <a href="http://www.playframework.org/modules/scala">scala module</a> that I highly recommend you download and use &#8212; oh and if you like scala &#8212; you can get on the <a href="http://www.playframework.org/modules/akka">akka</a> bandwagon as well. It&#8217;s also highly recommended.</p>
<p>Do yourself a favor and <a href="http://playframework.org">Play Now</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://airodig.com/2010/04/27/play-with-java-and-scala-web-apps/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
