<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xml:lang="en" xml:base="http://www.codexon.com/wp-atom.php">
	<title type="text">Codexon</title>
	<subtitle type="text" />

	<updated>2010-08-04T03:18:11Z</updated>

	<link rel="alternate" type="text/html" href="http://www.codexon.com" />
	<id>http://www.codexon.com/feed/atom</id>
	

	
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/Codexon" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="codexon" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
		<author>
			<name>admin</name>
						<uri>http://www.codexon.com</uri>
					</author>
		<title type="html"><![CDATA[WordPress Spam: Javascript antispam such as WP-SpamFree/WP-HashCash don&#8217;t work anymore]]></title>
		<link rel="alternate" type="text/html" href="http://www.codexon.com/posts/wordpress-spam-javascript-antispam-such-as-wp-spamfreewp-hashcash-dont-work-anymore" />
		<id>http://www.codexon.com/?p=974</id>
		<updated>2010-08-01T23:35:53Z</updated>
		<published>2010-08-01T23:35:10Z</published>
		<category scheme="http://www.codexon.com" term="Codexon" /><category scheme="http://www.codexon.com" term="spam" /><category scheme="http://www.codexon.com" term="wordpress" />		<summary type="html"><![CDATA[Being a user of websites myself, I have always been annoyed at Captchas like this: Which is why I&#8217;ve avoided using them on Codexon, opting to use JavaScript based anti-spam like WP-SpamFree or WP-HashCash instead. Unfortunately, JavaScript anti-spam is defeated the moment spammers decide to add Javascript to their bots. It worked well up until [...]]]></summary>
		<content type="html" xml:base="http://www.codexon.com/posts/wordpress-spam-javascript-antispam-such-as-wp-spamfreewp-hashcash-dont-work-anymore">&lt;p&gt;Being a user of websites myself, I have always been annoyed at Captchas like this:&lt;/p&gt;
&lt;div id="attachment_975" class="wp-caption aligncenter" style="width: 177px"&gt;&lt;img class="size-full wp-image-975" title="googlecaptcha" src="http://www.codexon.com/wp-content/uploads/2010/08/googlecaptcha.png" alt="" width="167" height="63" /&gt;&lt;p class="wp-caption-text"&gt;An annoying captcha from Google&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;Which is why I&amp;#8217;ve avoided using them on Codexon, opting to use JavaScript based anti-spam like &lt;a  href="http://www.polepositionmarketing.com/library/wp-spamfree/"&gt;WP-SpamFree&lt;/a&gt; or &lt;a  href="http://wordpress-plugins.feifei.us/hashcash/"&gt;WP-HashCash&lt;/a&gt; instead. Unfortunately, JavaScript anti-spam is defeated the moment spammers decide to add Javascript to their bots.&lt;/p&gt;
&lt;p&gt;It worked well up until a couple of months ago, but there has recently been a surge of spam getting past the JavaScript anti-spam. I believe spammers are now targeting them. After installing a captcha, spam here at Codexon has dropped from 10+ a day to zero.&lt;/p&gt;
&lt;p&gt;So if you have a website and are considering just using a convenient JavaScript solution, be wary.&lt;/p&gt;




	&lt;a  rel="nofollow" target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fwordpress-spam-javascript-antispam-such-as-wp-spamfreewp-hashcash-dont-work-anymore&amp;#038;title=Wordpress%20Spam%3A%20Javascript%20antispam%20such%20as%20WP-SpamFree%2FWP-HashCash%20don%27t%20work%20anymore" title="Reddit"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fwordpress-spam-javascript-antispam-such-as-wp-spamfreewp-hashcash-dont-work-anymore&amp;#038;t=Wordpress%20Spam%3A%20Javascript%20antispam%20such%20as%20WP-SpamFree%2FWP-HashCash%20don%27t%20work%20anymore" title="Facebook"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;amp;bkmk=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fwordpress-spam-javascript-antispam-such-as-wp-spamfreewp-hashcash-dont-work-anymore&amp;amp;title=Wordpress%20Spam%3A%20Javascript%20antispam%20such%20as%20WP-SpamFree%2FWP-HashCash%20don%27t%20work%20anymore&amp;amp;annotation=Being%20a%20user%20of%20websites%20myself%2C%20I%20have%20always%20been%20annoyed%20at%20Captchas%20like%20this%3A%0D%0A%0D%0A%0D%0A%0D%0AWhich%20is%20why%20I%27ve%20avoided%20using%20them%20on%20Codexon%2C%20opting%20to%20use%20JavaScript%20based%20anti-spam%20like%20WP-SpamFree%20or%20WP-HashCash%20instead.%20Unfortunately%2C%20JavaScript%20ant" title="Google Bookmarks"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.codexon.com/feed" title="RSS"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /&gt;&lt;/a&gt;


&lt;br/&gt;&lt;br/&gt;&lt;img src="http://www.codexon.com/?ak_action=api_record_view&amp;id=974&amp;type=feed" alt="" /&gt;&lt;hr /&gt;
&lt;a href="http://www.codexon.com/posts/wordpress-spam-javascript-antispam-such-as-wp-spamfreewp-hashcash-dont-work-anymore#comments"&gt;2 comments&lt;/a&gt; |
&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=9Y3GJVU7RBVDC&amp;lc=US&amp;item_name=www%2ecodexon%2ecom&amp;currency_code=USD&amp;bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"&gt;Donate&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/Codexon/~4/P9S-yVt41x4" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.codexon.com/posts/wordpress-spam-javascript-antispam-such-as-wp-spamfreewp-hashcash-dont-work-anymore#comments" thr:count="2" />
		<link rel="replies" type="application/atom+xml" href="http://www.codexon.com/posts/wordpress-spam-javascript-antispam-such-as-wp-spamfreewp-hashcash-dont-work-anymore/feed/atom" thr:count="2" />
		<thr:total>2</thr:total>
	</entry>
		<entry>
		<author>
			<name>admin</name>
						<uri>http://www.codexon.com</uri>
					</author>
		<title type="html"><![CDATA[Make a Python JIT compiler without writing a single line of C or 3rd party library]]></title>
		<link rel="alternate" type="text/html" href="http://www.codexon.com/posts/make-a-python-jit-compiler-without-writing-a-single-line-of-c-or-3rd-party-library" />
		<id>http://www.codexon.com/?p=963</id>
		<updated>2010-07-11T02:01:28Z</updated>
		<published>2010-07-11T01:53:17Z</published>
		<category scheme="http://www.codexon.com" term="Programming" />		<summary type="html"><![CDATA[JIT is just a fancy term for making native code during runtime; another word for &#8220;eval&#8221; except you won&#8217;t be sneered at when you implement it. I will show you how this can all be done in the comfort of Python without having to write a single line of C or use a 3rd party [...]]]></summary>
		<content type="html" xml:base="http://www.codexon.com/posts/make-a-python-jit-compiler-without-writing-a-single-line-of-c-or-3rd-party-library">&lt;p&gt;JIT is just a fancy term for making native code during runtime; another word for &amp;#8220;eval&amp;#8221; except you won&amp;#8217;t be sneered at when you implement it.&lt;/p&gt;
&lt;p&gt;I will show you how this can all be done in the comfort of Python without having to write a single line of C or use a 3rd party library.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="python" style="font-family:monospace;"&gt;&lt;span style="color: #ff7700;font-weight:bold;"&gt;from&lt;/span&gt; ctypes &lt;span style="color: #ff7700;font-weight:bold;"&gt;import&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;*&lt;/span&gt;
&amp;nbsp;
code32 = &lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #483d8b;"&gt;'&lt;span style="color: #000099; font-weight: bold;"&gt;\x&lt;/span&gt;b8&lt;span style="color: #000099; font-weight: bold;"&gt;\x&lt;/span&gt;7b&lt;span style="color: #000099; font-weight: bold;"&gt;\x&lt;/span&gt;00&lt;span style="color: #000099; font-weight: bold;"&gt;\x&lt;/span&gt;00&lt;span style="color: #000099; font-weight: bold;"&gt;\x&lt;/span&gt;00'&lt;/span&gt; &lt;span style="color: #808080; font-style: italic;"&gt;# mov eax, 123&lt;/span&gt;
          &lt;span style="color: #483d8b;"&gt;'&lt;span style="color: #000099; font-weight: bold;"&gt;\x&lt;/span&gt;c3'&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;                &lt;span style="color: #808080; font-style: italic;"&gt;# ret&lt;/span&gt;
&amp;nbsp;
code64 = &lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #483d8b;"&gt;'&lt;span style="color: #000099; font-weight: bold;"&gt;\x&lt;/span&gt;48&lt;span style="color: #000099; font-weight: bold;"&gt;\x&lt;/span&gt;c7&lt;span style="color: #000099; font-weight: bold;"&gt;\x&lt;/span&gt;c0&lt;span style="color: #000099; font-weight: bold;"&gt;\x&lt;/span&gt;7b&lt;span style="color: #000099; font-weight: bold;"&gt;\x&lt;/span&gt;00&lt;span style="color: #000099; font-weight: bold;"&gt;\x&lt;/span&gt;00&lt;span style="color: #000099; font-weight: bold;"&gt;\x&lt;/span&gt;00'&lt;/span&gt; &lt;span style="color: #808080; font-style: italic;"&gt;# mov rax, 123&lt;/span&gt;
          &lt;span style="color: #483d8b;"&gt;'&lt;span style="color: #000099; font-weight: bold;"&gt;\x&lt;/span&gt;c3'&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;                        &lt;span style="color: #808080; font-style: italic;"&gt;# ret&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #ff7700;font-weight:bold;"&gt;def&lt;/span&gt; windows&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #dc143c;"&gt;code&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;:
    PAGE_EXECUTE_READWRITE = 0x40
&amp;nbsp;
    code_buffer = create_string_buffer&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #dc143c;"&gt;code&lt;/span&gt;, &lt;span style="color: #008000;"&gt;len&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #dc143c;"&gt;code&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
    code_buffer_address = addressof&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;code_buffer&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
    windll.&lt;span style="color: black;"&gt;kernel32&lt;/span&gt;.&lt;span style="color: black;"&gt;VirtualProtect&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;code_buffer_address, &lt;span style="color: #008000;"&gt;len&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #dc143c;"&gt;code&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;, PAGE_EXECUTE_READWRITE, byref&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;c_int&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
    &lt;span style="color: #ff7700;font-weight:bold;"&gt;return&lt;/span&gt; code_buffer_address
&amp;nbsp;
&lt;span style="color: #ff7700;font-weight:bold;"&gt;def&lt;/span&gt; linux&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #dc143c;"&gt;code&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;:
    PROT_WRITE = &lt;span style="color: #ff4500;"&gt;2&lt;/span&gt;
    PROT_EXEC  = &lt;span style="color: #ff4500;"&gt;4&lt;/span&gt;
&amp;nbsp;
    libc = CDLL&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #483d8b;"&gt;'libc.so.6'&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
    code_buffer_address = libc.&lt;span style="color: black;"&gt;valloc&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #008000;"&gt;len&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #dc143c;"&gt;code&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
    memmove&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;code_buffer_address, &lt;span style="color: #dc143c;"&gt;code&lt;/span&gt;, &lt;span style="color: #008000;"&gt;len&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #dc143c;"&gt;code&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
    libc.&lt;span style="color: black;"&gt;mprotect&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;code_buffer_address, &lt;span style="color: #008000;"&gt;len&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #dc143c;"&gt;code&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;, PROT_WRITE|PROT_EXEC&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
    &lt;span style="color: #ff7700;font-weight:bold;"&gt;return&lt;/span&gt; code_buffer_address
&amp;nbsp;
&lt;span style="color: #ff7700;font-weight:bold;"&gt;import&lt;/span&gt; &lt;span style="color: #dc143c;"&gt;platform&lt;/span&gt;
bit, &lt;span style="color: #dc143c;"&gt;os&lt;/span&gt; = &lt;span style="color: #dc143c;"&gt;platform&lt;/span&gt;.&lt;span style="color: black;"&gt;architecture&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #dc143c;"&gt;code&lt;/span&gt;     = code32 &lt;span style="color: #ff7700;font-weight:bold;"&gt;if&lt;/span&gt; bit == &lt;span style="color: #483d8b;"&gt;'32bit'&lt;/span&gt; &lt;span style="color: #ff7700;font-weight:bold;"&gt;else&lt;/span&gt; code64
&lt;span style="color: #dc143c;"&gt;platform&lt;/span&gt; = windows &lt;span style="color: #ff7700;font-weight:bold;"&gt;if&lt;/span&gt; &lt;span style="color: #dc143c;"&gt;os&lt;/span&gt; == &lt;span style="color: #483d8b;"&gt;'WindowsPE'&lt;/span&gt; &lt;span style="color: #ff7700;font-weight:bold;"&gt;else&lt;/span&gt; linux
&amp;nbsp;
function_prototype = CFUNCTYPE&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;c_int&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
jitfunction = function_prototype&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #dc143c;"&gt;platform&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #dc143c;"&gt;code&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
&lt;span style="color: #ff7700;font-weight:bold;"&gt;print&lt;/span&gt; jitfunction&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The code does the following:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Allocates space for the code.&lt;/li&gt;
&lt;li&gt;Writes the code to memory.&lt;/li&gt;
&lt;li&gt;Enables execution privileges on that memory.&lt;/li&gt;
&lt;li&gt;Creates a function prototype gateway so you can use it from Python. (this feature is undocumented!)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Now that I&amp;#8217;ve shown the basic steps, it should be simple for you to hook this up to a lexer or look up additional assembly codes to use.&lt;/p&gt;




	&lt;a  rel="nofollow" target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fmake-a-python-jit-compiler-without-writing-a-single-line-of-c-or-3rd-party-library&amp;#038;title=Make%20a%20Python%20JIT%20compiler%20without%20writing%20a%20single%20line%20of%20C%20or%203rd%20party%20library" title="Reddit"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fmake-a-python-jit-compiler-without-writing-a-single-line-of-c-or-3rd-party-library&amp;#038;t=Make%20a%20Python%20JIT%20compiler%20without%20writing%20a%20single%20line%20of%20C%20or%203rd%20party%20library" title="Facebook"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;amp;bkmk=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fmake-a-python-jit-compiler-without-writing-a-single-line-of-c-or-3rd-party-library&amp;amp;title=Make%20a%20Python%20JIT%20compiler%20without%20writing%20a%20single%20line%20of%20C%20or%203rd%20party%20library&amp;amp;annotation=JIT%20is%20just%20a%20fancy%20term%20for%20making%20native%20code%20during%20runtime%3B%20another%20word%20for%20%22eval%22%20except%20you%20won%27t%20be%20sneered%20at%20when%20you%20implement%20it.%0D%0A%0D%0AI%20will%20show%20you%20how%20this%20can%20all%20be%20done%20in%20the%20comfort%20of%20Python%20without%20having%20to%20write%20a%20single%20line%20o" title="Google Bookmarks"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.codexon.com/feed" title="RSS"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /&gt;&lt;/a&gt;


&lt;br/&gt;&lt;br/&gt;&lt;img src="http://www.codexon.com/?ak_action=api_record_view&amp;id=963&amp;type=feed" alt="" /&gt;&lt;hr /&gt;
&lt;a href="http://www.codexon.com/posts/make-a-python-jit-compiler-without-writing-a-single-line-of-c-or-3rd-party-library#comments"&gt;2 comments&lt;/a&gt; |
&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=9Y3GJVU7RBVDC&amp;lc=US&amp;item_name=www%2ecodexon%2ecom&amp;currency_code=USD&amp;bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"&gt;Donate&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/Codexon/~4/V5N_FENO5i0" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.codexon.com/posts/make-a-python-jit-compiler-without-writing-a-single-line-of-c-or-3rd-party-library#comments" thr:count="2" />
		<link rel="replies" type="application/atom+xml" href="http://www.codexon.com/posts/make-a-python-jit-compiler-without-writing-a-single-line-of-c-or-3rd-party-library/feed/atom" thr:count="2" />
		<thr:total>2</thr:total>
	</entry>
		<entry>
		<author>
			<name>admin</name>
						<uri>http://www.codexon.com</uri>
					</author>
		<title type="html"><![CDATA[Fun with Facebook Graph]]></title>
		<link rel="alternate" type="text/html" href="http://www.codexon.com/posts/fun-with-facebook-graph" />
		<id>http://www.codexon.com/?p=948</id>
		<updated>2010-05-12T22:23:18Z</updated>
		<published>2010-05-12T22:18:24Z</published>
		<category scheme="http://www.codexon.com" term="Uncategorized" /><category scheme="http://www.codexon.com" term="facebook" /><category scheme="http://www.codexon.com" term="privacy" />		<summary type="html"><![CDATA[Facebook has released an API to access their data through the web. Apparently you could do the same thing by logging on and using the gui, but now everyone can benefit from the lack of privacy! Who hates their boss? http://graph.facebook.com/search?q=I%20hate%20my%20boss The spammers are spamming their acai berry. http://graph.facebook.com/search?q=acai%20berry Interesting crab infections. http://graph.facebook.com/search?q=itchy%20crabs Juicy medical [...]]]></summary>
		<content type="html" xml:base="http://www.codexon.com/posts/fun-with-facebook-graph">&lt;p&gt;Facebook has released an API to access their data through the web. Apparently you could do the same thing by logging on and using the gui, but now everyone can benefit from the lack of privacy!&lt;/p&gt;
&lt;p&gt;&lt;img class="aligncenter size-full wp-image-515" title="facebook3" src="http://www.codexon.com/wp-content/uploads/2009/07/facebook3.jpg" alt="" width="375" height="280" /&gt;&lt;/p&gt;
&lt;p&gt;Who hates their boss?&lt;/p&gt;
&lt;p&gt;&lt;a  href="http://graph.facebook.com/search?q=I%20hate%20my%20boss"&gt;http://graph.facebook.com/search?q=I%20hate%20my%20boss&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The spammers are spamming their acai berry.&lt;/p&gt;
&lt;p&gt;&lt;a  href="http://graph.facebook.com/search?q=acai%20berry"&gt;http://graph.facebook.com/search?q=acai%20berry&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Interesting crab infections.&lt;/p&gt;
&lt;p&gt;&lt;a  href="http://graph.facebook.com/search?q=itchy%20crabs"&gt;http://graph.facebook.com/search?q=itchy%20crabs&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Juicy medical information for insurance companies.&lt;/p&gt;
&lt;p&gt;&lt;a  href="http://graph.facebook.com/search?q=colorectal%20surgery"&gt;http://graph.facebook.com/search?q=colorectal%20surgery&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Got any other interesting searches? Leave a comment below.&lt;/p&gt;
&lt;p&gt;&lt;a  href="http://webcache.googleusercontent.com/search?q=cache:TWpUeuegoBIJ:graph.facebook.com/+graph.facebook.com﻿"&gt;Google Cache of the API (no Facebook login necessary)&lt;/a&gt;&lt;/p&gt;




	&lt;a  rel="nofollow" target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.codexon.com%2Fposts%2Ffun-with-facebook-graph&amp;#038;title=Fun%20with%20Facebook%20Graph" title="Reddit"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.codexon.com%2Fposts%2Ffun-with-facebook-graph&amp;#038;t=Fun%20with%20Facebook%20Graph" title="Facebook"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;amp;bkmk=http%3A%2F%2Fwww.codexon.com%2Fposts%2Ffun-with-facebook-graph&amp;amp;title=Fun%20with%20Facebook%20Graph&amp;amp;annotation=Facebook%20has%20released%20an%20API%20to%20access%20their%20data%20through%20the%20web.%20Apparently%20you%20could%20do%20the%20same%20thing%20by%20logging%20on%20and%20using%20the%20gui%2C%20but%20now%20everyone%20can%20benefit%20from%20the%20lack%20of%20privacy%21%0D%0A%0D%0A%0D%0A%0D%0AWho%20hates%20their%20boss%3F%0D%0A%0D%0Ahttp%3A%2F%2Fgraph.facebook.co" title="Google Bookmarks"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.codexon.com/feed" title="RSS"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /&gt;&lt;/a&gt;


&lt;br/&gt;&lt;br/&gt;&lt;img src="http://www.codexon.com/?ak_action=api_record_view&amp;id=948&amp;type=feed" alt="" /&gt;&lt;hr /&gt;
&lt;a href="http://www.codexon.com/posts/fun-with-facebook-graph#comments"&gt;One comment&lt;/a&gt; |
&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=9Y3GJVU7RBVDC&amp;lc=US&amp;item_name=www%2ecodexon%2ecom&amp;currency_code=USD&amp;bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"&gt;Donate&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/Codexon/~4/M9fAlmKXKVk" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.codexon.com/posts/fun-with-facebook-graph#comments" thr:count="1" />
		<link rel="replies" type="application/atom+xml" href="http://www.codexon.com/posts/fun-with-facebook-graph/feed/atom" thr:count="1" />
		<thr:total>1</thr:total>
	</entry>
		<entry>
		<author>
			<name>admin</name>
						<uri>http://www.codexon.com</uri>
					</author>
		<title type="html"><![CDATA[Is Cassandra ready yet?]]></title>
		<link rel="alternate" type="text/html" href="http://www.codexon.com/posts/is-cassandra-ready-yet" />
		<id>http://www.codexon.com/?p=937</id>
		<updated>2010-03-24T21:25:34Z</updated>
		<published>2010-03-24T21:23:31Z</published>
		<category scheme="http://www.codexon.com" term="Internet" /><category scheme="http://www.codexon.com" term="Programming" />		<summary type="html"><![CDATA[With Twitter, Facebook, Digg, and Reddit using the open-source Amazon Dynamo clone, Cassandra may be the winner of the NoSQL race. But is it ready for a general purpose (excluding transactions and other obvious features) data store? There are a few kinks right now that may hamper your adoption of Cassandra. You must restart Cassandra [...]]]></summary>
		<content type="html" xml:base="http://www.codexon.com/posts/is-cassandra-ready-yet">&lt;p&gt;With Twitter, Facebook, Digg, and Reddit using the  open-source Amazon Dynamo clone, &lt;a  href="http://cassandra.apache.org/"&gt;Cassandra&lt;/a&gt; may be the winner of  the NoSQL race.&lt;/p&gt;
&lt;p&gt;&lt;img class="aligncenter size-full wp-image-938" title="cassandra_logo" src="http://www.codexon.com/wp-content/uploads/2010/03/cassandra_logo.png" alt="" width="500" height="100" /&gt;&lt;/p&gt;
&lt;p&gt;But is it ready for a general purpose (excluding transactions and other obvious features) data store? There are a few kinks right now that may hamper your adoption of Cassandra.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;You must restart Cassandra in order to add/delete/rename ColumnFamilies &lt;/strong&gt;(tables)&lt;/p&gt;
&lt;p&gt;This can be a problem if you want to run your website without interruption. A rolling restart is recommended, but that will  also impact your uptime if you choose a consistency level of &amp;#8220;ALL&amp;#8221;. A patch to solve this problem is being worked on and is scheduled for version 0.7. The current version is 0.5&lt;/p&gt;
&lt;p&gt;&lt;a  href="https://issues.apache.org/jira/browse/CASSANDRA-44"&gt;Issue 44&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Getting a range of rows may return empty &amp;#8220;tombstoned&amp;#8221; rows&lt;br /&gt;
&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Due to the way that Cassandra is engineered, Cassandra must mark deleted rows as &amp;#8220;tombstones&amp;#8221; so other nodes will know that it has been deleted instead of the other node not having a copy propagated yet. Tombstones will only disappear after a costly &amp;#8220;compact&amp;#8221; command.&lt;/p&gt;
&lt;p&gt;The problem is that if you want to return users 40-50, you may get 10 empty rows. To fix this you would then have to repeatedly query Cassandra until you get 10 non-empty rows. This back and forth may cause significant overhead on your network. Before it was done server-side, but apparently the early adopters preferred to return empty rows . This is a mistake in my opinion.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;No distributed versioning (only last write wins)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Vector clocks support is scheduled to be added, but there is no ETA. This may be important for some applications. For example, if you have a shopping cart and you add Item A on Server 1 and Item B on Server 2 and the servers momentarily split, your shopping cart may end up with only Item B if you use &amp;#8220;last write wins&amp;#8221;. With vector clocks, you will get the chance to merge them.&lt;/p&gt;
&lt;p&gt;&lt;a  href="https://issues.apache.org/jira/browse/CASSANDRA-580"&gt;Issue 580&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;No advanced queries through map/reduce (yet?)&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Hadoop integration is planned, but to my knowledge, this isn&amp;#8217;t ready yet. Your application may or may not need this feature.&lt;/p&gt;
&lt;p&gt;&lt;a  href="http://issues.apache.org/jira/browse/CASSANDRA-342"&gt;Issue 342&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;No atomic increment/decrement&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This feature is necessary for counting things like page-views accurately. There is a hack here using a 3rd party application called zookeeper.&lt;/p&gt;
&lt;p&gt;&lt;a  href="http://issues.apache.org/jira/browse/CASSANDRA-721"&gt;Issue 721&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Even with these current shortcomings, you may find Cassandra to be suitable for you right away. It is definitely one of the best NoSQL solutions available.&lt;/p&gt;




	&lt;a  rel="nofollow" target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fis-cassandra-ready-yet&amp;#038;title=Is%20Cassandra%20ready%20yet%3F" title="Reddit"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fis-cassandra-ready-yet&amp;#038;t=Is%20Cassandra%20ready%20yet%3F" title="Facebook"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;amp;bkmk=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fis-cassandra-ready-yet&amp;amp;title=Is%20Cassandra%20ready%20yet%3F&amp;amp;annotation=With%20Twitter%2C%20Facebook%2C%20Digg%2C%20and%20Reddit%20using%20the%20%20open-source%20Amazon%20Dynamo%20clone%2C%20Cassandra%20may%20be%20the%20winner%20of%20%20the%20NoSQL%20race.%0D%0A%0D%0A%0D%0A%0D%0ABut%20is%20it%20ready%20for%20a%20general%20purpose%20%28excluding%20transactions%20and%20other%20obvious%20features%29%20data%20store%3F%20There%20ar" title="Google Bookmarks"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.codexon.com/feed" title="RSS"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /&gt;&lt;/a&gt;


&lt;br/&gt;&lt;br/&gt;&lt;img src="http://www.codexon.com/?ak_action=api_record_view&amp;id=937&amp;type=feed" alt="" /&gt;&lt;hr /&gt;
&lt;a href="http://www.codexon.com/posts/is-cassandra-ready-yet#comments"&gt;Leave a Comment&lt;/a&gt; |
&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=9Y3GJVU7RBVDC&amp;lc=US&amp;item_name=www%2ecodexon%2ecom&amp;currency_code=USD&amp;bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"&gt;Donate&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/Codexon/~4/wxdKtYOkY1Q" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.codexon.com/posts/is-cassandra-ready-yet#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://www.codexon.com/posts/is-cassandra-ready-yet/feed/atom" thr:count="0" />
		<thr:total>0</thr:total>
	</entry>
		<entry>
		<author>
			<name>admin</name>
						<uri>http://www.codexon.com</uri>
					</author>
		<title type="html"><![CDATA[Hot code swapping for servers not written in Erlang]]></title>
		<link rel="alternate" type="text/html" href="http://www.codexon.com/posts/hot-code-swapping-for-servers-not-written-in-erlang" />
		<id>http://www.codexon.com/?p=928</id>
		<updated>2010-01-20T03:40:42Z</updated>
		<published>2010-01-20T03:39:18Z</published>
		<category scheme="http://www.codexon.com" term="Internet" /><category scheme="http://www.codexon.com" term="Programming" /><category scheme="http://www.codexon.com" term="Python" />		<summary type="html"><![CDATA[The recent server benchmark posted here comparing Erlang, Haskell, and Python understandably upset many people. Today we will move away from polarizing benchmarks and more about features. Even though Erlang may not be the fastest language, it still has at least one great feature: hot swapping code without restarting the server. This is something that [...]]]></summary>
		<content type="html" xml:base="http://www.codexon.com/posts/hot-code-swapping-for-servers-not-written-in-erlang">&lt;p&gt;The recent server benchmark posted here comparing Erlang, Haskell, and Python understandably upset many people. Today we will move away from polarizing benchmarks and more about features.&lt;/p&gt;
&lt;p&gt;Even though Erlang may not be the fastest language, it still has at least one great feature: hot swapping code without restarting the server. This is something that every long running server should have, but unfortunately it comes at the cost of performance, and some languages simply are not built to support it.&lt;/p&gt;
&lt;p&gt;However, here is a way to emulate it for a web server, thanks to techniques borrowed from Nginx.&lt;/p&gt;
&lt;p&gt;Here are the steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Use the spawn family of system calls (ex. spawnl spawnvp) with the flag P_NOWAIT to execute itself. This new process has access to the open sockets.&lt;/li&gt;
&lt;li&gt;The new process should open a predetermined file containing the file descriptors of the sockets it needs to use saved by the old process.&lt;/li&gt;
&lt;li&gt;Start calling &amp;#8220;accept&amp;#8221; on the same listening sockets that the old process was accepting.&lt;/li&gt;
&lt;li&gt;Signal the old process to stop accepting, and to quit when all requests are finished.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;While Python has a rudimentary reload, it may still be preferable to use this method as it greatly simplifies the upgrade logic. Upgrading functions piecewise may lead to corruption of logic and data.&lt;/p&gt;
&lt;p&gt;Here is an example in Python that reloads itself in a loop using this method. It saves the file descriptors for 2 connected sockets which allows the new process to signal the old one at will. Simply run the program, and then edit the print statements below to watch it change.&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="python" style="font-family:monospace;"&gt;&lt;span style="color: #ff7700;font-weight:bold;"&gt;import&lt;/span&gt; &lt;span style="color: #dc143c;"&gt;os&lt;/span&gt;
&lt;span style="color: #ff7700;font-weight:bold;"&gt;import&lt;/span&gt; &lt;span style="color: #dc143c;"&gt;time&lt;/span&gt;
&lt;span style="color: #ff7700;font-weight:bold;"&gt;import&lt;/span&gt; &lt;span style="color: #dc143c;"&gt;socket&lt;/span&gt;
&lt;span style="color: #ff7700;font-weight:bold;"&gt;import&lt;/span&gt; &lt;span style="color: #dc143c;"&gt;sys&lt;/span&gt;
&lt;span style="color: #ff7700;font-weight:bold;"&gt;import&lt;/span&gt; &lt;span style="color: #dc143c;"&gt;fcntl&lt;/span&gt;
&lt;span style="color: #ff7700;font-weight:bold;"&gt;import&lt;/span&gt; _multiprocessing
&lt;span style="color: #ff7700;font-weight:bold;"&gt;from&lt;/span&gt; multiprocessing &lt;span style="color: #ff7700;font-weight:bold;"&gt;import&lt;/span&gt; Pipe
&amp;nbsp;
&lt;span style="color: #808080; font-style: italic;"&gt;# global pipe variable&lt;/span&gt;
pipe       = &lt;span style="color: #008000;"&gt;None&lt;/span&gt;
spare_pipe = &lt;span style="color: #008000;"&gt;None&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #ff7700;font-weight:bold;"&gt;def&lt;/span&gt; PipeFromFD&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;fd&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;:
    &lt;span style="color: #ff7700;font-weight:bold;"&gt;return&lt;/span&gt; _multiprocessing.&lt;span style="color: black;"&gt;Connection&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;fd&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #ff7700;font-weight:bold;"&gt;def&lt;/span&gt; recordPipe&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;p1, p2&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;:
    &lt;span style="color: #ff7700;font-weight:bold;"&gt;with&lt;/span&gt; &lt;span style="color: #008000;"&gt;open&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #483d8b;"&gt;'fd.txt'&lt;/span&gt;, &lt;span style="color: #483d8b;"&gt;'w'&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #ff7700;font-weight:bold;"&gt;as&lt;/span&gt; f:
        f.&lt;span style="color: black;"&gt;write&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #483d8b;"&gt;'%s,%s'&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;%&lt;/span&gt; &lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;p1.&lt;span style="color: black;"&gt;fileno&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;, p2.&lt;span style="color: black;"&gt;fileno&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #ff7700;font-weight:bold;"&gt;def&lt;/span&gt; upgrade&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;:
    &lt;span style="color: #dc143c;"&gt;os&lt;/span&gt;.&lt;span style="color: black;"&gt;spawnlp&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #dc143c;"&gt;os&lt;/span&gt;.&lt;span style="color: black;"&gt;P_NOWAIT&lt;/span&gt;, &lt;span style="color: #483d8b;"&gt;'python'&lt;/span&gt;, &lt;span style="color: #483d8b;"&gt;'python'&lt;/span&gt;, &lt;span style="color: #dc143c;"&gt;sys&lt;/span&gt;.&lt;span style="color: black;"&gt;argv&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #ff4500;"&gt;0&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#93;&lt;/span&gt;, &lt;span style="color: #483d8b;"&gt;'-upgrade'&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #ff7700;font-weight:bold;"&gt;def&lt;/span&gt; upgradeBootstrap&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;:
    &lt;span style="color: #ff7700;font-weight:bold;"&gt;global&lt;/span&gt; pipe, spare_pipe
    &lt;span style="color: #ff7700;font-weight:bold;"&gt;with&lt;/span&gt; &lt;span style="color: #008000;"&gt;open&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #483d8b;"&gt;'fd.txt'&lt;/span&gt;, &lt;span style="color: #483d8b;"&gt;'r'&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #ff7700;font-weight:bold;"&gt;as&lt;/span&gt; f:
        p1, p2 = &lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #008000;"&gt;int&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;fd&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #ff7700;font-weight:bold;"&gt;for&lt;/span&gt; fd &lt;span style="color: #ff7700;font-weight:bold;"&gt;in&lt;/span&gt; f.&lt;span style="color: black;"&gt;read&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;.&lt;span style="color: black;"&gt;split&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #483d8b;"&gt;','&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
        pipe = PipeFromFD&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;p1&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
        spare_pipe = PipeFromFD&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;p2&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
    recordPipe&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;spare_pipe, pipe&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
    pipe.&lt;span style="color: black;"&gt;send&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #483d8b;"&gt;&amp;quot;I am upgraded!&amp;quot;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #ff7700;font-weight:bold;"&gt;if&lt;/span&gt; __name__ == &lt;span style="color: #483d8b;"&gt;'__main__'&lt;/span&gt;:    
&amp;nbsp;
    &lt;span style="color: #ff7700;font-weight:bold;"&gt;if&lt;/span&gt; &lt;span style="color: #483d8b;"&gt;'-upgrade'&lt;/span&gt; &lt;span style="color: #ff7700;font-weight:bold;"&gt;in&lt;/span&gt; &lt;span style="color: #dc143c;"&gt;sys&lt;/span&gt;.&lt;span style="color: black;"&gt;argv&lt;/span&gt;:
        upgradeBootstrap&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
    &lt;span style="color: #ff7700;font-weight:bold;"&gt;else&lt;/span&gt;:
        pipe, spare_pipe = Pipe&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
        recordPipe&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;spare_pipe, pipe&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
    pid = &lt;span style="color: #dc143c;"&gt;os&lt;/span&gt;.&lt;span style="color: black;"&gt;getpid&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
    &lt;span style="color: #ff7700;font-weight:bold;"&gt;print&lt;/span&gt; &lt;span style="color: #483d8b;"&gt;'%i: Version 1. Upgrade in 5 seconds.'&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;%&lt;/span&gt; pid
    &lt;span style="color: #dc143c;"&gt;time&lt;/span&gt;.&lt;span style="color: black;"&gt;sleep&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #ff4500;"&gt;5&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
    &lt;span style="color: #ff7700;font-weight:bold;"&gt;print&lt;/span&gt; &lt;span style="color: #483d8b;"&gt;'%i: Upgrading'&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;%&lt;/span&gt; pid
    upgrade&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
    &lt;span style="color: #ff7700;font-weight:bold;"&gt;print&lt;/span&gt; &lt;span style="color: #483d8b;"&gt;'%i: Message from new process: %s'&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;%&lt;/span&gt; &lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;pid, pipe.&lt;span style="color: black;"&gt;recv&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
    &lt;span style="color: #ff7700;font-weight:bold;"&gt;print&lt;/span&gt; &lt;span style="color: #483d8b;"&gt;'%i: Upgrade Complete. Exiting'&lt;/span&gt; &lt;span style="color: #66cc66;"&gt;%&lt;/span&gt; pid&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Example Output&lt;/p&gt;
&lt;pre&gt;
user@test:/mnt/shared$ python upgrade.py
22930: Version 1. Upgrade in 10 seconds.
22930: Upgrading
22971: Version 2. Upgrade in 10 seconds.
22930: Message from new process: I am upgraded!
22930: Upgrade Complete. Exiting
user@test:/mnt/shared$ 22971: Upgrading
23025: Version 3. Upgrade in 10 seconds.
22971: Message from new process: I am upgraded!
22971: Upgrade Complete. Exiting
killall python
&lt;/pre&gt;




	&lt;a  rel="nofollow" target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fhot-code-swapping-for-servers-not-written-in-erlang&amp;#038;title=Hot%20code%20swapping%20for%20servers%20not%20written%20in%20Erlang" title="Reddit"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fhot-code-swapping-for-servers-not-written-in-erlang&amp;#038;t=Hot%20code%20swapping%20for%20servers%20not%20written%20in%20Erlang" title="Facebook"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;amp;bkmk=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fhot-code-swapping-for-servers-not-written-in-erlang&amp;amp;title=Hot%20code%20swapping%20for%20servers%20not%20written%20in%20Erlang&amp;amp;annotation=The%20recent%20server%20benchmark%20posted%20here%20comparing%20Erlang%2C%20Haskell%2C%20and%20Python%20understandably%20upset%20many%20people.%20Today%20we%20will%20move%20away%20from%20polarizing%20benchmarks%20and%20more%20about%20features.%0D%0A%0D%0AEven%20though%20Erlang%20may%20not%20be%20the%20fastest%20language%2C%20it%20stil" title="Google Bookmarks"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.codexon.com/feed" title="RSS"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /&gt;&lt;/a&gt;


&lt;br/&gt;&lt;br/&gt;&lt;img src="http://www.codexon.com/?ak_action=api_record_view&amp;id=928&amp;type=feed" alt="" /&gt;&lt;hr /&gt;
&lt;a href="http://www.codexon.com/posts/hot-code-swapping-for-servers-not-written-in-erlang#comments"&gt;7 comments&lt;/a&gt; |
&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=9Y3GJVU7RBVDC&amp;lc=US&amp;item_name=www%2ecodexon%2ecom&amp;currency_code=USD&amp;bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"&gt;Donate&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/Codexon/~4/qZx1KAS3vuA" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.codexon.com/posts/hot-code-swapping-for-servers-not-written-in-erlang#comments" thr:count="7" />
		<link rel="replies" type="application/atom+xml" href="http://www.codexon.com/posts/hot-code-swapping-for-servers-not-written-in-erlang/feed/atom" thr:count="7" />
		<thr:total>7</thr:total>
	</entry>
		<entry>
		<author>
			<name>admin</name>
						<uri>http://www.codexon.com</uri>
					</author>
		<title type="html"><![CDATA[Debunking the Erlang and Haskell hype for servers]]></title>
		<link rel="alternate" type="text/html" href="http://www.codexon.com/posts/debunking-the-erlang-and-haskell-hype-for-servers" />
		<id>http://www.codexon.com/?p=902</id>
		<updated>2010-08-04T03:18:11Z</updated>
		<published>2010-01-17T01:54:37Z</published>
		<category scheme="http://www.codexon.com" term="Internet" /><category scheme="http://www.codexon.com" term="Programming" /><category scheme="http://www.codexon.com" term="benchmark" /><category scheme="http://www.codexon.com" term="statistics" /><category scheme="http://www.codexon.com" term="web" />		<summary type="html"><![CDATA[Ever since Intel and AMD have been selling multi-core cpus, the Erlang hype has been growing continuously. The number of high profile projects using Erlang were flagrantly announced over the blogosphere as the coming of the second C. We kept hearing about: rabbitmq, couchdb, nearly all of Amazon&#8217;s AWS, Heroku&#8217;s routing grid, Facebook chat, all [...]]]></summary>
		<content type="html" xml:base="http://www.codexon.com/posts/debunking-the-erlang-and-haskell-hype-for-servers">&lt;p&gt;Ever since Intel and AMD have been selling multi-core cpus, the Erlang hype has been growing continuously. The number of high profile projects using Erlang were flagrantly announced over the blogosphere as the coming of the second C.&lt;/p&gt;
&lt;p&gt;We kept hearing about: rabbitmq, couchdb, nearly all of Amazon&amp;#8217;s AWS, Heroku&amp;#8217;s routing grid, Facebook chat, all switching over to Erlang because it was the fast and concurrent language of the future. No other language could hold a candle to a language run by telecom giant Ericsson which was then validated by Amazon and Facebook! Or not? When I tried to find benchmarks for Erlang, they all showed otherwise.&lt;/p&gt;
&lt;p&gt;&lt;a  href="http://muharem.wordpress.com/2007/07/31/erlang-vs-stackless-python-a-first-benchmark/"&gt;http://muharem.wordpress.com/2007/07/31/erlang-vs-stackless-python-a-first-benchmark/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a  href="http://www.joeandmotorboat.com/2009/01/03/nginx-vs-yaws-vs-mochiweb-web-server-performance-deathmatch-part-2/"&gt;http://www.joeandmotorboat.com/2009/01/03/nginx-vs-yaws-vs-mochiweb-web-server-performance-deathmatch-part-2/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Since I initially bought into the hype, I felt compelled to test it myself to see if they made a mistake. To do this, I wrote a simple http server in Erlang, Haskell, and Python that simply outputs an HTTP reply &amp;#8220;Pong!&amp;#8221;. And here are the results in a graph.&lt;/p&gt;
&lt;div id="attachment_911" class="wp-caption aligncenter" style="width: 654px"&gt;&lt;img class="size-full wp-image-911" title="chart" src="http://www.codexon.com/wp-content/uploads/2010/01/chart.png" alt="" width="644" height="428" /&gt;&lt;p class="wp-caption-text"&gt;The green line is the maximum req/sec possible. Higher is better.&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;For more details, continue reading.&lt;/p&gt;
&lt;p&gt;&lt;span id="more-902"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;&lt;br /&gt;
See comments for a faster implementation for Haskell that puts it almost on par with the Erlang.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Summary&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;A simple server was written in Python, Haskell, and Erlang. The server accepts any input from clients and outputs&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="plain" style="font-family:monospace;"&gt;HTTP/1.0 200 OK
Content-Length: 5
&amp;nbsp;
Pong!&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and then disconnects. The servers were benchmarked with httperf compiled with increased select limit of 65535 connections. In every test, 0 errors occurred.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Python&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;1st place&lt;/li&gt;
&lt;li&gt;Using a single process/thread epoll sustained the most connections per second before hitting a cpu bottleneck.&lt;/li&gt;
&lt;li&gt;This was highly unexpected since we are comparing it with Erlang and Haskell.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Erlang&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;2nd place.&lt;/li&gt;
&lt;li&gt; Having SMP/multicore enabled reduced requests/sec by a factor of 4!&lt;/li&gt;
&lt;li&gt;Enabling kernel polling (epoll) made a negligble performance impact (less than  +- 1%).&lt;/li&gt;
&lt;li&gt;Someone suggested enabling &amp;#8220;active&amp;#8221; receive mode which asynchronously puts received packets in the Erlang message queue. This made a negligible difference.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Haskell&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;3rd place&lt;/li&gt;
&lt;li&gt;This might be because it uses select instead of epoll. However, this did not make a difference for Erlang, so I suspect it would not for Haskell as well.&lt;/li&gt;
&lt;li&gt;The program was compiled with -O2 with modest performance gains. Compiling with &amp;#8211;threaded for SMP support reduced performance by a factor of 2!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;DO NOT WRITE A SERVER IN ERLANG JUST BECAUSE YOU HEARD ERLANG IS THE FASTEST AND MOST CONCURRENT LANGUAGE.&lt;/p&gt;
&lt;p&gt;Erlang is not &amp;#8220;made for multicore&amp;#8221;. Erlang only just received SMP support in 2006!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Setup&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;2 x 4 core Xeon E5420  @ 2.50GHz&lt;/p&gt;
&lt;p&gt;The following steps were done to lift the usual limits that prevent default installations of Linux from being able to hammer servers. Neglecting this step will artificially cap concurrent connections at 1024 while timeout errors will increase. This is an important step that many other benchmarks have left out, and it shows in the error rate. All tests here resulted in 0 errors.&lt;/p&gt;
&lt;p&gt;Httperf also depends on select, so the select limit was increased to 65,535 file descriptors.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;edit /etc/security/limits.conf and add the lines: &amp;#8220;&lt;code&gt;*       hard    nofile  65535&lt;/code&gt;&amp;#8221; and &amp;#8220;&lt;code&gt;* soft    nofile  65535" (reboot if ulimit -n does not change)&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;edit /usr/include/bits/typesizes.h and change &amp;#8220;#define __FD_SET_SIZE 1024&amp;#8243; to &amp;#8220;#define __FD_SET_SIZE 65535&amp;#8243;&lt;/li&gt;
&lt;li&gt;compile httperf from source&lt;/li&gt;
&lt;li&gt;Increase kernel file descriptor limit:  &lt;span style="text-decoration: underline;"&gt;sudo bash -c &amp;#8220;echo &amp;#8220;128000&amp;#8243; &gt; /proc/sys/fs/file-max&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Increase the backlog:&lt;em&gt; &lt;/em&gt;&lt;span style="text-decoration: underline;"&gt;sudo sysctl -w net.core.netdev_max_backlog=60000&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;Increase maximum connection limit: &lt;span style="text-decoration: underline;"&gt;sudo sysctl -w net.core.somaxconn=250000&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Software&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Ubuntu 9.04 x64&lt;/p&gt;
&lt;p&gt;Erlang: BEAM 5.6.5&lt;/p&gt;
&lt;p&gt;Haskell: GHC 6.10.4&lt;/p&gt;
&lt;p&gt;Python: CPython 2.6.4&lt;/p&gt;
&lt;p&gt;Httperf: 0.9.0&lt;/p&gt;
&lt;p&gt;Httperf was run with the following settings, where port and rate were adjusted accordingly:&lt;/p&gt;
&lt;p&gt;httperf &amp;#8211;port=8000 &amp;#8211;num-conns=40000 &amp;#8211;rate=5000&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Erlang active mode&lt;/strong&gt;&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="erlang" style="font-family:monospace;"&gt;&lt;span style="color: #014ea4;"&gt;-&lt;/span&gt;&lt;span style="color: #5400b3;"&gt;module&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#40;&lt;/span&gt;echo&lt;span style="color: #109ab8;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;.&lt;/span&gt;
&lt;span style="color: #014ea4;"&gt;-&lt;/span&gt;&lt;span style="color: #5400b3;"&gt;export&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#91;&lt;/span&gt;listen&lt;span style="color: #014ea4;"&gt;/&lt;/span&gt;&lt;span style="color: #ff9600;"&gt;1&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;.&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #014ea4;"&gt;-&lt;/span&gt;&lt;span style="color: #5400b3;"&gt;define&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #6941fd;"&gt;TCP_OPTIONS&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt; &lt;span style="color: #109ab8;"&gt;&amp;#91;&lt;/span&gt;&lt;span style="color: #fa6fff;"&gt;binary&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt; &lt;span style="color: #109ab8;"&gt;&amp;#123;&lt;/span&gt;packet&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt; &lt;span style="color: #ff9600;"&gt;0&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt; &lt;span style="color: #109ab8;"&gt;&amp;#123;&lt;/span&gt;active&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt; true&lt;span style="color: #109ab8;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt; &lt;span style="color: #109ab8;"&gt;&amp;#123;&lt;/span&gt;reuseaddr&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt; true&lt;span style="color: #109ab8;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt; &lt;span style="color: #109ab8;"&gt;&amp;#123;&lt;/span&gt;backlog&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt; &lt;span style="color: #ff9600;"&gt;60000&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#125;&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#93;&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;.&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #666666; font-style: italic;"&gt;% Call echo:listen(Port) to start the service.&lt;/span&gt;
&lt;span style="color: #ff3c00;"&gt;listen&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #45b3e6;"&gt;Port&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #6bb810;"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span style="color: #109ab8;"&gt;&amp;#123;&lt;/span&gt;ok&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt; &lt;span style="color: #45b3e6;"&gt;LSocket&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#125;&lt;/span&gt; &lt;span style="color: #014ea4;"&gt;=&lt;/span&gt; &lt;span style="color: #ff4e18;"&gt;gen_tcp&lt;/span&gt;:&lt;span style="color: #ff3c00;"&gt;listen&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #45b3e6;"&gt;Port&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt; ?&lt;span style="color: #6941fd;"&gt;TCP_OPTIONS&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt;
    &lt;span style="color: #ff3c00;"&gt;spawn&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #ff3c00;"&gt;fun&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #6bb810;"&gt;-&amp;gt;&lt;/span&gt; &lt;span style="color: #ff3c00;"&gt;accept&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #45b3e6;"&gt;LSocket&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #186895;"&gt;end&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;.&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #666666; font-style: italic;"&gt;% Wait for incoming connections and spawn the echo loop when we get one.&lt;/span&gt;
&lt;span style="color: #ff3c00;"&gt;accept&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #45b3e6;"&gt;LSocket&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #6bb810;"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span style="color: #109ab8;"&gt;&amp;#123;&lt;/span&gt;ok&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt; &lt;span style="color: #45b3e6;"&gt;Socket&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#125;&lt;/span&gt; &lt;span style="color: #014ea4;"&gt;=&lt;/span&gt; &lt;span style="color: #ff4e18;"&gt;gen_tcp&lt;/span&gt;:&lt;span style="color: #ff3c00;"&gt;accept&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #45b3e6;"&gt;LSocket&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt;
    &lt;span style="color: #45b3e6;"&gt;Pid&lt;/span&gt; &lt;span style="color: #014ea4;"&gt;=&lt;/span&gt; &lt;span style="color: #ff3c00;"&gt;spawn&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #ff3c00;"&gt;fun&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #6bb810;"&gt;-&amp;gt;&lt;/span&gt; &lt;span style="color: #ff3c00;"&gt;loop&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #45b3e6;"&gt;Socket&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #186895;"&gt;end&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt;
    &lt;span style="color: #ff4e18;"&gt;gen_tcp&lt;/span&gt;:&lt;span style="color: #ff3c00;"&gt;controlling_process&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #45b3e6;"&gt;Socket&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt; &lt;span style="color: #45b3e6;"&gt;Pid&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt;
    &lt;span style="color: #ff3c00;"&gt;accept&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #45b3e6;"&gt;LSocket&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;.&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #666666; font-style: italic;"&gt;% Echo back whatever data we receive on Socket.&lt;/span&gt;
&lt;span style="color: #ff3c00;"&gt;loop&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #45b3e6;"&gt;Socket&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #6bb810;"&gt;-&amp;gt;&lt;/span&gt;
    &lt;span style="color: #186895;"&gt;receive&lt;/span&gt;
        &lt;span style="color: #109ab8;"&gt;&amp;#123;&lt;/span&gt;tcp&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt; &lt;span style="color: #45b3e6;"&gt;Socket&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt; &lt;span style="color: #45b3e6;"&gt;Data&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#125;&lt;/span&gt; &lt;span style="color: #6bb810;"&gt;-&amp;gt;&lt;/span&gt;
            &lt;span style="color: #ff4e18;"&gt;gen_tcp&lt;/span&gt;:&lt;span style="color: #ff3c00;"&gt;send&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #45b3e6;"&gt;Socket&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt; &lt;span style="color: #ff7800;"&gt;&amp;quot;HTTP/1.0 200 OK&lt;span style="color: #000099; font-weight: bold;"&gt;\r&lt;/span&gt;&lt;span style="color: #000099; font-weight: bold;"&gt;\n&lt;/span&gt;Content-Length: 5&lt;span style="color: #000099; font-weight: bold;"&gt;\r&lt;/span&gt;&lt;span style="color: #000099; font-weight: bold;"&gt;\n&lt;/span&gt;&lt;span style="color: #000099; font-weight: bold;"&gt;\r&lt;/span&gt;&lt;span style="color: #000099; font-weight: bold;"&gt;\n&lt;/span&gt;Pong!&lt;span style="color: #000099; font-weight: bold;"&gt;\r&lt;/span&gt;&lt;span style="color: #000099; font-weight: bold;"&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt;
            &lt;span style="color: #ff4e18;"&gt;gen_tcp&lt;/span&gt;:&lt;span style="color: #ff3c00;"&gt;close&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #45b3e6;"&gt;Socket&lt;/span&gt;&lt;span style="color: #109ab8;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;;&lt;/span&gt;
        &lt;span style="color: #109ab8;"&gt;&amp;#123;&lt;/span&gt;error&lt;span style="color: #6bb810;"&gt;,&lt;/span&gt; eaddrinuse&lt;span style="color: #109ab8;"&gt;&amp;#125;&lt;/span&gt; &lt;span style="color: #6bb810;"&gt;-&amp;gt;&lt;/span&gt;
            &lt;span style="color: #006600;"&gt;done&lt;/span&gt;
    &lt;span style="color: #186895;"&gt;end&lt;/span&gt;&lt;span style="color: #6bb810;"&gt;.&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Haskell&lt;/strong&gt;&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="haskell" style="font-family:monospace;"&gt;&lt;span style="color: #06c; font-weight: bold;"&gt;import&lt;/span&gt; &lt;span style="color: #cccc00; font-weight: bold;"&gt;IO&lt;/span&gt;
&lt;span style="color: #06c; font-weight: bold;"&gt;import&lt;/span&gt; Control&lt;span style="color: #339933; font-weight: bold;"&gt;.&lt;/span&gt;Exception &lt;span style="color: #06c; font-weight: bold;"&gt;hiding&lt;/span&gt; &lt;span style="color: green;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="font-weight: bold;"&gt;catch&lt;/span&gt;&lt;span style="color: green;"&gt;&amp;#41;&lt;/span&gt;
&lt;span style="color: #06c; font-weight: bold;"&gt;import&lt;/span&gt; Control&lt;span style="color: #339933; font-weight: bold;"&gt;.&lt;/span&gt;Concurrent
&lt;span style="color: #06c; font-weight: bold;"&gt;import&lt;/span&gt; Network
&lt;span style="color: #06c; font-weight: bold;"&gt;import&lt;/span&gt; System&lt;span style="color: #339933; font-weight: bold;"&gt;.&lt;/span&gt;Posix
&amp;nbsp;
main &lt;span style="color: #339933; font-weight: bold;"&gt;=&lt;/span&gt; withSocketsDo &lt;span style="color: green;"&gt;&amp;#40;&lt;/span&gt;installHandler sigPIPE Ignore Nothing &lt;span style="color: #339933; font-weight: bold;"&gt;&amp;gt;&amp;gt;&lt;/span&gt; main'&lt;span style="color: green;"&gt;&amp;#41;&lt;/span&gt;
main' &lt;span style="color: #339933; font-weight: bold;"&gt;=&lt;/span&gt; listenOn &lt;span style="color: green;"&gt;&amp;#40;&lt;/span&gt;PortNumber &lt;span style="color: red;"&gt;9900&lt;/span&gt;&lt;span style="color: green;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #339933; font-weight: bold;"&gt;&amp;gt;&amp;gt;=&lt;/span&gt; acceptConnections
&amp;nbsp;
acceptConnections sock &lt;span style="color: #339933; font-weight: bold;"&gt;=&lt;/span&gt; &lt;span style="color: #06c; font-weight: bold;"&gt;do&lt;/span&gt;
        conn&lt;span style="color: #339933; font-weight: bold;"&gt;@&lt;/span&gt;&lt;span style="color: green;"&gt;&amp;#40;&lt;/span&gt;h&lt;span style="color: #339933; font-weight: bold;"&gt;,&lt;/span&gt;host&lt;span style="color: #339933; font-weight: bold;"&gt;,&lt;/span&gt;port&lt;span style="color: green;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #339933; font-weight: bold;"&gt;&amp;lt;-&lt;/span&gt; accept sock
        forkIO &lt;span style="color: #339933; font-weight: bold;"&gt;$&lt;/span&gt; &lt;span style="font-weight: bold;"&gt;catch&lt;/span&gt; &lt;span style="color: green;"&gt;&amp;#40;&lt;/span&gt;talk conn `finally` hClose h&lt;span style="color: green;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: green;"&gt;&amp;#40;&lt;/span&gt;\e &lt;span style="color: #339933; font-weight: bold;"&gt;-&amp;gt;&lt;/span&gt; &lt;span style="font-weight: bold;"&gt;print&lt;/span&gt; e&lt;span style="color: green;"&gt;&amp;#41;&lt;/span&gt;
        acceptConnections sock
&amp;nbsp;
talk conn&lt;span style="color: #339933; font-weight: bold;"&gt;@&lt;/span&gt;&lt;span style="color: green;"&gt;&amp;#40;&lt;/span&gt;h&lt;span style="color: #339933; font-weight: bold;"&gt;,_,_&lt;/span&gt;&lt;span style="color: green;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #339933; font-weight: bold;"&gt;=&lt;/span&gt; hPutStrLn h &lt;span style="background-color: #3cb371;"&gt;&amp;quot;HTTP/1.0 200 OK&lt;span style="background-color: #3cb371; font-weight: bold;"&gt;\r&lt;/span&gt;&lt;span style="background-color: #3cb371; font-weight: bold;"&gt;\n&lt;/span&gt;Content-Length: 5&lt;span style="background-color: #3cb371; font-weight: bold;"&gt;\r&lt;/span&gt;&lt;span style="background-color: #3cb371; font-weight: bold;"&gt;\n&lt;/span&gt;&lt;span style="background-color: #3cb371; font-weight: bold;"&gt;\r&lt;/span&gt;&lt;span style="background-color: #3cb371; font-weight: bold;"&gt;\n&lt;/span&gt;Pong!&lt;span style="background-color: #3cb371; font-weight: bold;"&gt;\r&lt;/span&gt;&lt;span style="background-color: #3cb371; font-weight: bold;"&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt; &lt;span style="color: #339933; font-weight: bold;"&gt;&amp;gt;&amp;gt;&lt;/span&gt;
                    hFlush h &lt;span style="color: #339933; font-weight: bold;"&gt;&amp;gt;&amp;gt;&lt;/span&gt;
                    hClose h&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Python&lt;/strong&gt;&lt;/p&gt;

&lt;div class="wp_syntax"&gt;&lt;div class="code"&gt;&lt;pre class="python" style="font-family:monospace;"&gt;&lt;span style="color: #ff7700;font-weight:bold;"&gt;import&lt;/span&gt; &lt;span style="color: #dc143c;"&gt;select&lt;/span&gt;
&lt;span style="color: #ff7700;font-weight:bold;"&gt;import&lt;/span&gt; &lt;span style="color: #dc143c;"&gt;socket&lt;/span&gt;
&amp;nbsp;
EPOLLIN = &lt;span style="color: #dc143c;"&gt;select&lt;/span&gt;.&lt;span style="color: black;"&gt;EPOLLIN&lt;/span&gt;
EPOLLOUT = &lt;span style="color: #dc143c;"&gt;select&lt;/span&gt;.&lt;span style="color: black;"&gt;EPOLLOUT&lt;/span&gt;
&amp;nbsp;
epoll = &lt;span style="color: #dc143c;"&gt;select&lt;/span&gt;.&lt;span style="color: black;"&gt;epoll&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #ff4500;"&gt;60000&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
connections = &lt;span style="color: black;"&gt;&amp;#123;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #ff7700;font-weight:bold;"&gt;class&lt;/span&gt; Server&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #008000;"&gt;object&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;:
    &lt;span style="color: #ff7700;font-weight:bold;"&gt;def&lt;/span&gt; &lt;span style="color: #0000cd;"&gt;__init__&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #008000;"&gt;self&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;:
        sock = &lt;span style="color: #dc143c;"&gt;socket&lt;/span&gt;.&lt;span style="color: #dc143c;"&gt;socket&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #dc143c;"&gt;socket&lt;/span&gt;.&lt;span style="color: black;"&gt;AF_INET&lt;/span&gt;, &lt;span style="color: #dc143c;"&gt;socket&lt;/span&gt;.&lt;span style="color: black;"&gt;SOCK_STREAM&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
        sock.&lt;span style="color: black;"&gt;setsockopt&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #dc143c;"&gt;socket&lt;/span&gt;.&lt;span style="color: black;"&gt;SOL_SOCKET&lt;/span&gt;, &lt;span style="color: #dc143c;"&gt;socket&lt;/span&gt;.&lt;span style="color: black;"&gt;SO_REUSEADDR&lt;/span&gt;, &lt;span style="color: #ff4500;"&gt;1&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
        sock.&lt;span style="color: black;"&gt;setblocking&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #ff4500;"&gt;0&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
        sock.&lt;span style="color: black;"&gt;bind&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #483d8b;"&gt;''&lt;/span&gt;, &lt;span style="color: #ff4500;"&gt;8050&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
        sock.&lt;span style="color: black;"&gt;listen&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #ff4500;"&gt;60000&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
        &lt;span style="color: #008000;"&gt;self&lt;/span&gt;.&lt;span style="color: #dc143c;"&gt;socket&lt;/span&gt; = sock
&amp;nbsp;
        fileno = sock.&lt;span style="color: black;"&gt;fileno&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
        connections&lt;span style="color: black;"&gt;&amp;#91;&lt;/span&gt;fileno&lt;span style="color: black;"&gt;&amp;#93;&lt;/span&gt; = &lt;span style="color: #008000;"&gt;self&lt;/span&gt;
        epoll.&lt;span style="color: black;"&gt;register&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;fileno, EPOLLIN&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
    &lt;span style="color: #ff7700;font-weight:bold;"&gt;def&lt;/span&gt; onInput&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #008000;"&gt;self&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;:
        sock, address = &lt;span style="color: #008000;"&gt;self&lt;/span&gt;.&lt;span style="color: #dc143c;"&gt;socket&lt;/span&gt;.&lt;span style="color: black;"&gt;accept&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
        Client&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;sock&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #ff7700;font-weight:bold;"&gt;class&lt;/span&gt; Client&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #008000;"&gt;object&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;:
    &lt;span style="color: #008000;"&gt;input&lt;/span&gt;  = &lt;span style="color: #483d8b;"&gt;''&lt;/span&gt;
    output = &lt;span style="color: #483d8b;"&gt;&amp;quot;HTTP/1.0 200 OK&lt;span style="color: #000099; font-weight: bold;"&gt;\r&lt;/span&gt;&lt;span style="color: #000099; font-weight: bold;"&gt;\n&lt;/span&gt;Content-Length: 5&lt;span style="color: #000099; font-weight: bold;"&gt;\r&lt;/span&gt;&lt;span style="color: #000099; font-weight: bold;"&gt;\n&lt;/span&gt;&lt;span style="color: #000099; font-weight: bold;"&gt;\r&lt;/span&gt;&lt;span style="color: #000099; font-weight: bold;"&gt;\n&lt;/span&gt;Pong!&lt;span style="color: #000099; font-weight: bold;"&gt;\r&lt;/span&gt;&lt;span style="color: #000099; font-weight: bold;"&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;
&amp;nbsp;
    &lt;span style="color: #ff7700;font-weight:bold;"&gt;def&lt;/span&gt; &lt;span style="color: #0000cd;"&gt;__init__&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #008000;"&gt;self&lt;/span&gt;, sock&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;:
        sock.&lt;span style="color: black;"&gt;setblocking&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #ff4500;"&gt;0&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
        fileno = sock.&lt;span style="color: black;"&gt;fileno&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
        epoll.&lt;span style="color: black;"&gt;register&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;fileno, EPOLLIN|EPOLLOUT&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
        connections&lt;span style="color: black;"&gt;&amp;#91;&lt;/span&gt;fileno&lt;span style="color: black;"&gt;&amp;#93;&lt;/span&gt; = &lt;span style="color: #008000;"&gt;self&lt;/span&gt;
        &lt;span style="color: #008000;"&gt;self&lt;/span&gt;.&lt;span style="color: #dc143c;"&gt;socket&lt;/span&gt; = sock
&amp;nbsp;
    &lt;span style="color: #ff7700;font-weight:bold;"&gt;def&lt;/span&gt; onInput&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #008000;"&gt;self&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;:
        newdata = &lt;span style="color: #008000;"&gt;self&lt;/span&gt;.&lt;span style="color: #dc143c;"&gt;socket&lt;/span&gt;.&lt;span style="color: black;"&gt;recv&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #ff4500;"&gt;1024&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
        &lt;span style="color: #ff7700;font-weight:bold;"&gt;if&lt;/span&gt; &lt;span style="color: #008000;"&gt;len&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;newdata&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #ff7700;font-weight:bold;"&gt;is&lt;/span&gt; &lt;span style="color: #ff4500;"&gt;0&lt;/span&gt;:
            &lt;span style="color: #008000;"&gt;self&lt;/span&gt;.&lt;span style="color: black;"&gt;close&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
        &lt;span style="color: #008000;"&gt;self&lt;/span&gt;.&lt;span style="color: #008000;"&gt;input&lt;/span&gt; += newdata
&amp;nbsp;
    &lt;span style="color: #ff7700;font-weight:bold;"&gt;def&lt;/span&gt; onOutput&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #008000;"&gt;self&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;:
        sent = &lt;span style="color: #008000;"&gt;self&lt;/span&gt;.&lt;span style="color: #dc143c;"&gt;socket&lt;/span&gt;.&lt;span style="color: black;"&gt;send&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #008000;"&gt;self&lt;/span&gt;.&lt;span style="color: black;"&gt;output&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
        &lt;span style="color: #008000;"&gt;self&lt;/span&gt;.&lt;span style="color: black;"&gt;output&lt;/span&gt; = &lt;span style="color: #008000;"&gt;self&lt;/span&gt;.&lt;span style="color: black;"&gt;output&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#91;&lt;/span&gt;sent:&lt;span style="color: black;"&gt;&amp;#93;&lt;/span&gt;
        &lt;span style="color: #ff7700;font-weight:bold;"&gt;if&lt;/span&gt; &lt;span style="color: #008000;"&gt;len&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #008000;"&gt;self&lt;/span&gt;.&lt;span style="color: black;"&gt;output&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #ff7700;font-weight:bold;"&gt;is&lt;/span&gt; &lt;span style="color: #ff4500;"&gt;0&lt;/span&gt;:
            &lt;span style="color: #008000;"&gt;self&lt;/span&gt;.&lt;span style="color: black;"&gt;close&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
    &lt;span style="color: #ff7700;font-weight:bold;"&gt;def&lt;/span&gt; close&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #008000;"&gt;self&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;:
        fileno = &lt;span style="color: #008000;"&gt;self&lt;/span&gt;.&lt;span style="color: #dc143c;"&gt;socket&lt;/span&gt;.&lt;span style="color: black;"&gt;fileno&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
        &lt;span style="color: #ff7700;font-weight:bold;"&gt;del&lt;/span&gt; connections&lt;span style="color: black;"&gt;&amp;#91;&lt;/span&gt;fileno&lt;span style="color: black;"&gt;&amp;#93;&lt;/span&gt;
        epoll.&lt;span style="color: black;"&gt;unregister&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;fileno&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
        &lt;span style="color: #008000;"&gt;self&lt;/span&gt;.&lt;span style="color: #dc143c;"&gt;socket&lt;/span&gt;.&lt;span style="color: black;"&gt;close&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
Server&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
&lt;span style="color: #ff7700;font-weight:bold;"&gt;while&lt;/span&gt; &lt;span style="color: #ff4500;"&gt;1&lt;/span&gt;:
    &lt;span style="color: #ff7700;font-weight:bold;"&gt;for&lt;/span&gt; fd, event &lt;span style="color: #ff7700;font-weight:bold;"&gt;in&lt;/span&gt; epoll.&lt;span style="color: black;"&gt;poll&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;:
        &lt;span style="color: #ff7700;font-weight:bold;"&gt;if&lt;/span&gt; event &lt;span style="color: #66cc66;"&gt;&amp;amp;&lt;/span&gt;amp&lt;span style="color: #66cc66;"&gt;;&lt;/span&gt; EPOLLIN:
            connections&lt;span style="color: black;"&gt;&amp;#91;&lt;/span&gt;fd&lt;span style="color: black;"&gt;&amp;#93;&lt;/span&gt;.&lt;span style="color: black;"&gt;onInput&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
        &lt;span style="color: #ff7700;font-weight:bold;"&gt;if&lt;/span&gt; event &lt;span style="color: #66cc66;"&gt;&amp;amp;&lt;/span&gt;amp&lt;span style="color: #66cc66;"&gt;;&lt;/span&gt; EPOLLOUT:
            connections&lt;span style="color: black;"&gt;&amp;#91;&lt;/span&gt;fd&lt;span style="color: black;"&gt;&amp;#93;&lt;/span&gt;.&lt;span style="color: black;"&gt;onOutput&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: black;"&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Source Code&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="../wp-content/uploads/2010/01/hello.erl"&gt;Erlang version 1 (active mode): hello.erl&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a  href="http://www.codexon.com/wp-content/uploads/2010/01/hello2.erl"&gt;Erlang version 2 (passive mode): hello2.erl&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a  href="http://www.codexon.com/wp-content/uploads/2010/01/hello.py"&gt;Python: hello.py&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a  href="http://www.codexon.com/wp-content/uploads/2010/01/hello.hs"&gt;Haskell: hello.hs&lt;/a&gt;&lt;/p&gt;




	&lt;a  rel="nofollow" target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fdebunking-the-erlang-and-haskell-hype-for-servers&amp;#038;title=Debunking%20the%20Erlang%20and%20Haskell%20hype%20for%20servers" title="Reddit"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fdebunking-the-erlang-and-haskell-hype-for-servers&amp;#038;t=Debunking%20the%20Erlang%20and%20Haskell%20hype%20for%20servers" title="Facebook"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;amp;bkmk=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fdebunking-the-erlang-and-haskell-hype-for-servers&amp;amp;title=Debunking%20the%20Erlang%20and%20Haskell%20hype%20for%20servers&amp;amp;annotation=Ever%20since%20Intel%20and%20AMD%20have%20been%20selling%20multi-core%20cpus%2C%20the%20Erlang%20hype%20has%20been%20growing%20continuously.%20The%20number%20of%20high%20profile%20projects%20using%20Erlang%20were%20flagrantly%20announced%20over%20the%20blogosphere%20as%20the%20coming%20of%20the%20second%20C.%0D%0A%0D%0AWe%20kept%20heari" title="Google Bookmarks"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.codexon.com/feed" title="RSS"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /&gt;&lt;/a&gt;


&lt;br/&gt;&lt;br/&gt;&lt;img src="http://www.codexon.com/?ak_action=api_record_view&amp;id=902&amp;type=feed" alt="" /&gt;&lt;hr /&gt;
&lt;a href="http://www.codexon.com/posts/debunking-the-erlang-and-haskell-hype-for-servers#comments"&gt;116 comments&lt;/a&gt; |
&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=9Y3GJVU7RBVDC&amp;lc=US&amp;item_name=www%2ecodexon%2ecom&amp;currency_code=USD&amp;bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"&gt;Donate&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/Codexon/~4/iq1squug64k" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.codexon.com/posts/debunking-the-erlang-and-haskell-hype-for-servers#comments" thr:count="116" />
		<link rel="replies" type="application/atom+xml" href="http://www.codexon.com/posts/debunking-the-erlang-and-haskell-hype-for-servers/feed/atom" thr:count="116" />
		<thr:total>116</thr:total>
	</entry>
		<entry>
		<author>
			<name>admin</name>
						<uri>http://www.codexon.com</uri>
					</author>
		<title type="html"><![CDATA[How to create jobs in the US: Keep the corporate tax, lower consumer tax.]]></title>
		<link rel="alternate" type="text/html" href="http://www.codexon.com/posts/how-to-create-jobs-in-the-us-keep-the-corporate-tax-lower-consumer-tax" />
		<id>http://www.codexon.com/?p=888</id>
		<updated>2010-01-06T08:58:22Z</updated>
		<published>2010-01-03T08:30:43Z</published>
		<category scheme="http://www.codexon.com" term="Economics" />		<summary type="html"><![CDATA[Many Republicans believe in Reagan&#8217;s trickle down theory. They believe that by offering businesses a tax break, they will use the money to hire more people. You don’t improve the economy by paying people to sit around and not work. You improve the economy by lowering taxes so small businesses will create more jobs. - [...]]]></summary>
		<content type="html" xml:base="http://www.codexon.com/posts/how-to-create-jobs-in-the-us-keep-the-corporate-tax-lower-consumer-tax">&lt;p&gt;Many Republicans believe in Reagan&amp;#8217;s trickle down theory. They believe that by offering businesses a tax break, they will use the money to hire more people.&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;You don’t improve the economy by paying people to sit around and not work. You improve the economy by lowering taxes so small businesses will create more jobs.&lt;/p&gt;
&lt;p&gt;- Representative John Linder Georgia Republican&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;How this frequently parroted sentiment is so popular is understandable, but&amp;#8230; does anyone else see the problem with this argument?&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;If you give businesses tax breaks, they are going to horde it because they know that consumers aren&amp;#8217;t going to have any money for them to earn.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;However, if you give consumers and families a tax break, it encourages businesses to produce more, likely hiring more people in the process because that&amp;#8217;s where the money is. Individuals and families also pay a higher tax rate than corporations that like to:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Deduct everything as a business expense or low capital gains tax. Like &lt;span style="text-decoration: line-through;"&gt;personal&lt;/span&gt; business laptops and cars.&lt;/li&gt;
&lt;li&gt;Hide it in tax haven states or countries &lt;a  href="http://www.economist.com/businessfinance/displayStory.cfm?story_id=6919139"&gt;like Ikea&lt;/a&gt; and Walmart&lt;/li&gt;
&lt;li&gt;Use it to boost company stock which can be cashed out at a rock-bottom 15% capital gains tax, the same tax rate as someone earning a paltry $8,026-32,550 in 2008.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;img class="aligncenter size-full wp-image-892" title="reit_taxevasion_graphic" src="http://www.codexon.com/wp-content/uploads/2010/01/reit_taxevasion_graphic.gif" alt="" width="484" height="583" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Potential Rebuttals&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;But individuals will also horde money&lt;strong&gt;!&lt;/strong&gt;&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span id="more-888"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Individuals cannot horde as much as a corporation. Individuals need to pay rent or land tax at the minimum. A business could essentially exist without paying anything but rent.&lt;/p&gt;
&lt;p&gt;On top of that, a &amp;#8220;business&amp;#8221; owner could deduct part of the cost of his own home from tax if s/he claims it was being used for business purposes.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;But businesses also spend money!&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While this may be true, b2b (business selling to businesses) cannot survive without b2c (business selling to consumers). You could argue that businesses could just always be exchanging goods/currency to other businesses, but &lt;strong&gt;someone &lt;/strong&gt;has to provide necessary services like water, food, and shelter to individuals.&lt;/p&gt;
&lt;p&gt;Actually, a purely b2b society would be possible. But it would consist of businesses doling out bundles of basic living needs to individuals, effectively becoming a mini-government to employees who don&amp;#8217;t have any voting rights (unless they own a considerable amount of stock), and could usually be fired on a whim.&lt;/p&gt;




	&lt;a  rel="nofollow" target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fhow-to-create-jobs-in-the-us-keep-the-corporate-tax-lower-consumer-tax&amp;#038;title=How%20to%20create%20jobs%20in%20the%20US%3A%20Keep%20the%20corporate%20tax%2C%20lower%20consumer%20tax." title="Reddit"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fhow-to-create-jobs-in-the-us-keep-the-corporate-tax-lower-consumer-tax&amp;#038;t=How%20to%20create%20jobs%20in%20the%20US%3A%20Keep%20the%20corporate%20tax%2C%20lower%20consumer%20tax." title="Facebook"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;amp;bkmk=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fhow-to-create-jobs-in-the-us-keep-the-corporate-tax-lower-consumer-tax&amp;amp;title=How%20to%20create%20jobs%20in%20the%20US%3A%20Keep%20the%20corporate%20tax%2C%20lower%20consumer%20tax.&amp;amp;annotation=Many%20Republicans%20believe%20in%20Reagan%27s%20trickle%20down%20theory.%20They%20believe%20that%20by%20offering%20businesses%20a%20tax%20break%2C%20they%20will%20use%20the%20money%20to%20hire%20more%20people.%0D%0AYou%20don%E2%80%99t%20improve%20the%20economy%20by%20paying%20people%20to%20sit%20around%20and%20not%20work.%20You%20improve%20the" title="Google Bookmarks"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.codexon.com/feed" title="RSS"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /&gt;&lt;/a&gt;


&lt;br/&gt;&lt;br/&gt;&lt;img src="http://www.codexon.com/?ak_action=api_record_view&amp;id=888&amp;type=feed" alt="" /&gt;&lt;hr /&gt;
&lt;a href="http://www.codexon.com/posts/how-to-create-jobs-in-the-us-keep-the-corporate-tax-lower-consumer-tax#comments"&gt;Leave a Comment&lt;/a&gt; |
&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=9Y3GJVU7RBVDC&amp;lc=US&amp;item_name=www%2ecodexon%2ecom&amp;currency_code=USD&amp;bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"&gt;Donate&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/Codexon/~4/BMJsL6OjbZI" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.codexon.com/posts/how-to-create-jobs-in-the-us-keep-the-corporate-tax-lower-consumer-tax#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://www.codexon.com/posts/how-to-create-jobs-in-the-us-keep-the-corporate-tax-lower-consumer-tax/feed/atom" thr:count="0" />
		<thr:total>0</thr:total>
	</entry>
		<entry>
		<author>
			<name>admin</name>
						<uri>http://www.codexon.com</uri>
					</author>
		<title type="html"><![CDATA[A Better US Income Tax]]></title>
		<link rel="alternate" type="text/html" href="http://www.codexon.com/posts/a-better-us-income-tax" />
		<id>http://www.codexon.com/?p=826</id>
		<updated>2009-12-17T01:48:31Z</updated>
		<published>2009-12-17T01:47:48Z</published>
		<category scheme="http://www.codexon.com" term="Economics" />		<summary type="html"><![CDATA[People hate taxes, and everyone can agree to disagree on them. One thing most people agree on though is that it&#8217;s too complicated. Here is a diagram of the US income tax in 2008. What&#8217;s wrong with the current piecemeal tax rate? It&#8217;s complicated. People want to earn less if taking a raise barely puts [...]]]></summary>
		<content type="html" xml:base="http://www.codexon.com/posts/a-better-us-income-tax">&lt;p&gt;People hate taxes, and everyone can agree to disagree on them. One thing most people agree on though is that it&amp;#8217;s too complicated.&lt;/p&gt;
&lt;p&gt;Here is a diagram of the US income tax in 2008.&lt;/p&gt;
&lt;div id="attachment_827" class="wp-caption aligncenter" style="width: 632px"&gt;&lt;img class="size-full wp-image-827 " title="tax" src="http://www.codexon.com/wp-content/uploads/2009/11/tax.png" alt="" width="622" height="426" /&gt;&lt;p class="wp-caption-text"&gt;US Income Tax 2008&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;What&amp;#8217;s wrong with the current piecemeal tax rate?&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;It&amp;#8217;s complicated.&lt;/li&gt;
&lt;li&gt;People want to earn less if taking a raise barely puts them in the next tax bracket.&lt;/li&gt;
&lt;li&gt;The tax rate increases faster for people earning very little compared to people earning a lot.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;What&amp;#8217;s wrong with a flat tax?&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The tax rate increases more slowly as your ability to earn more money increases exponentially.
&lt;ul&gt;
&lt;li&gt;The more money you have, the easier it is to get bargains, higher interest rates on bank accounts, and investment opportunities that allow you to own controlling shares of the next big company.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;A 20% tax of someone earning $20,000 a year can cause starving and homelessness while 20% of $10 million doesn&amp;#8217;t really make a dent.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;How do we fix this?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span id="more-826"&gt;&lt;/span&gt;Solution 1&lt;br /&gt;
&lt;/strong&gt;&lt;/p&gt;
&lt;div id="attachment_832" class="wp-caption aligncenter" style="width: 273px"&gt;&lt;img class="size-full wp-image-832" title="tax2" src="http://www.codexon.com/wp-content/uploads/2009/11/tax2.png" alt="" width="263" height="262" /&gt;&lt;p class="wp-caption-text"&gt;Exponential Curve&lt;/p&gt;&lt;/div&gt;
&lt;p style="text-align: center;"&gt;T(i) = p e^(i/G)&lt;/p&gt;
&lt;p style="text-align: center;"&gt;min( max tax rate, T(i) )&lt;/p&gt;
&lt;p style="text-align: center;"&gt;
&lt;p style="text-align: center;"&gt;p = minimum tax&lt;/p&gt;
&lt;p style="text-align: center;"&gt;e = Euler&amp;#8217;s constant&lt;/p&gt;
&lt;p style="text-align: center;"&gt;G = growth rate = i&lt;sub&gt;high threshold&lt;/sub&gt; / ln (T&lt;sub&gt;max&lt;/sub&gt; / p)&lt;/p&gt;
&lt;p style="text-align: left;"&gt;This exponential curve is one such solution that eases the problem of people on the low end of the income scale getting taxed at a higher rate of change than people who are earning the most.&lt;/p&gt;
&lt;p style="text-align: left;"&gt;One potential problem with this tax curve is deciding where and how much the maximum cutoff peak is. This is something for experienced statisticians, economists, and psychologists to decide.&lt;/p&gt;
&lt;p style="text-align: left;"&gt;A possible idea would be to set the maximum cutoff at a certain percentage of the GDP and having the tax rate close to 100% at that level. It is of course considered communist to have a tax rate at around 100% somewhere, but we can probably agree that there would be revolts should anyone control 50% or more wealth in a single nation.&lt;/p&gt;
&lt;p style="text-align: left;"&gt;&lt;strong&gt;Solution 2&lt;/strong&gt;&lt;/p&gt;
&lt;p style="text-align: left;"&gt;
&lt;p style="text-align: center;"&gt;
&lt;div id="attachment_853" class="wp-caption aligncenter" style="width: 323px"&gt;&lt;a  href="http://www.codexon.com/wp-content/uploads/2009/12/sigmoid.png"&gt;&lt;img class="size-full wp-image-853" title="sigmoid" src="http://www.codexon.com/wp-content/uploads/2009/12/sigmoid.png" alt="" width="313" height="312" /&gt;&lt;/a&gt;&lt;p class="wp-caption-text"&gt;Smoothed sigmoid curve&lt;/p&gt;&lt;/div&gt;
&lt;p style="text-align: center;"&gt;
&lt;p style="text-align: center;"&gt;
&lt;p style="text-align: center;"&gt;
&lt;p style="text-align: center;"&gt;
&lt;p style="text-align: center;"&gt;T(i) = m / (1 + e^(-i/s+p))&lt;/p&gt;
&lt;p style="text-align: center;"&gt;m = Maximum tax rate&lt;/p&gt;
&lt;p style="text-align: center;"&gt;s = stretch factor&lt;/p&gt;
&lt;p style="text-align: center;"&gt;p = poverty offset&lt;/p&gt;
&lt;p style="text-align: center;"&gt;
&lt;p style="text-align: left;"&gt;This smooth sigmoid curve is an improved version of the current tax curve. It is completely smooth instead of being piecemeal.&lt;/p&gt;
&lt;p style="text-align: left;"&gt;The one advantage this may have over the exponential curve is if you subscribe to the theory that it slowly becomes harder to get more money as you become richer. From anecdotal evidence, this is false, but could conceivably be true as you approach a large percentage of the GDP.&lt;/p&gt;
&lt;p style="text-align: left;"&gt;&lt;strong&gt;Potential Rebuttals&lt;/strong&gt;&lt;/p&gt;
&lt;p style="text-align: left;"&gt;&lt;em&gt;&amp;#8220;But the Laffer Curve blah blah&amp;#8230;&amp;#8221;&lt;/em&gt;&lt;/p&gt;
&lt;p style="text-align: left;"&gt;The Laffer Curve is a psychological curve. It is even different in some countries than others, and may fluctuate over time. The supposed optimal maximum tax rate for the US is around 35-37% which we have thanks to Bush. But even Bush&amp;#8217;s economic advisors have said that his tax breaks have not paid for themselves.&lt;/p&gt;
&lt;p style="text-align: left;"&gt;These formulas are highly adjustable, and experienced statisticians, economists, and psychologists should be the ones to tweak them.&lt;/p&gt;
&lt;p style="text-align: left;"&gt;&lt;em&gt;&amp;#8220;Higher tax rates will increase tax evasion&amp;#8221;&lt;/em&gt;&lt;/p&gt;
&lt;p style="text-align: left;"&gt;While this may be true, this is avoiding the problem. It&amp;#8217;s like putting a band-aid on the symptoms instead of curing the disease.&lt;/p&gt;
&lt;p style="text-align: center;"&gt;
&lt;p style="text-align: left;"&gt;




	&lt;a  rel="nofollow" target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fa-better-us-income-tax&amp;#038;title=A%20Better%20US%20Income%20Tax" title="Reddit"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fa-better-us-income-tax&amp;#038;t=A%20Better%20US%20Income%20Tax" title="Facebook"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;amp;bkmk=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fa-better-us-income-tax&amp;amp;title=A%20Better%20US%20Income%20Tax&amp;amp;annotation=People%20hate%20taxes%2C%20and%20everyone%20can%20agree%20to%20disagree%20on%20them.%20One%20thing%20most%20people%20agree%20on%20though%20is%20that%20it%27s%20too%20complicated.%0D%0A%0D%0AHere%20is%20a%20diagram%20of%20the%20US%20income%20tax%20in%202008.%0D%0A%0D%0A%0D%0A%0D%0AWhat%27s%20wrong%20with%20the%20current%20piecemeal%20tax%20rate%3F%0D%0A%0D%0A%09It%27s%20co" title="Google Bookmarks"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.codexon.com/feed" title="RSS"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /&gt;&lt;/a&gt;


&lt;br/&gt;&lt;br/&gt;&lt;img src="http://www.codexon.com/?ak_action=api_record_view&amp;id=826&amp;type=feed" alt="" /&gt;&lt;hr /&gt;
&lt;a href="http://www.codexon.com/posts/a-better-us-income-tax#comments"&gt;Leave a Comment&lt;/a&gt; |
&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=9Y3GJVU7RBVDC&amp;lc=US&amp;item_name=www%2ecodexon%2ecom&amp;currency_code=USD&amp;bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"&gt;Donate&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/Codexon/~4/sxyvTMiSYdY" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.codexon.com/posts/a-better-us-income-tax#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://www.codexon.com/posts/a-better-us-income-tax/feed/atom" thr:count="0" />
		<thr:total>0</thr:total>
	</entry>
		<entry>
		<author>
			<name>admin</name>
						<uri>http://www.codexon.com</uri>
					</author>
		<title type="html"><![CDATA[Website Contact Page Finally Fixed]]></title>
		<link rel="alternate" type="text/html" href="http://www.codexon.com/posts/website-contact-page-finally-fixed" />
		<id>http://www.codexon.com/?p=867</id>
		<updated>2009-12-17T01:32:28Z</updated>
		<published>2009-12-17T01:32:28Z</published>
		<category scheme="http://www.codexon.com" term="Codexon" />		<summary type="html"><![CDATA[The contact form for this website has finally been fixed! For some reason the WordPress mail sending function refused to work. All thanks go to this handy plugin which uses SMTP instead of the PHP function mail. http://www.codexon.com/contact Leave a Comment &#124; Donate]]></summary>
		<content type="html" xml:base="http://www.codexon.com/posts/website-contact-page-finally-fixed">&lt;p&gt;The contact form for this website has finally been fixed!&lt;/p&gt;
&lt;p&gt;For some reason the WordPress mail sending function refused to work.&lt;/p&gt;
&lt;p&gt;All thanks go to &lt;a  href="http://wordpress.org/extend/plugins/wp-mail-smtp/"&gt;this handy plugin&lt;/a&gt; which uses SMTP instead of the PHP function mail.&lt;/p&gt;
&lt;p&gt;&lt;a  href="http://www.codexon.com/contact"&gt;http://www.codexon.com/contact&lt;/a&gt;&lt;/p&gt;




	&lt;a  rel="nofollow" target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fwebsite-contact-page-finally-fixed&amp;#038;title=Website%20Contact%20Page%20Finally%20Fixed" title="Reddit"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fwebsite-contact-page-finally-fixed&amp;#038;t=Website%20Contact%20Page%20Finally%20Fixed" title="Facebook"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;amp;bkmk=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fwebsite-contact-page-finally-fixed&amp;amp;title=Website%20Contact%20Page%20Finally%20Fixed&amp;amp;annotation=The%20contact%20form%20for%20this%20website%20has%20finally%20been%20fixed%21%0D%0A%0D%0AFor%20some%20reason%20the%20Wordpress%20mail%20sending%20function%20refused%20to%20work.%0D%0A%0D%0AAll%20thanks%20go%20to%20this%20handy%20plugin%20which%20uses%20SMTP%20instead%20of%20the%20PHP%20function%20mail.%0D%0A%0D%0Ahttp%3A%2F%2Fwww.codexon.com%2Fcontac" title="Google Bookmarks"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.codexon.com/feed" title="RSS"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /&gt;&lt;/a&gt;


&lt;br/&gt;&lt;br/&gt;&lt;img src="http://www.codexon.com/?ak_action=api_record_view&amp;id=867&amp;type=feed" alt="" /&gt;&lt;hr /&gt;
&lt;a href="http://www.codexon.com/posts/website-contact-page-finally-fixed#comments"&gt;Leave a Comment&lt;/a&gt; |
&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=9Y3GJVU7RBVDC&amp;lc=US&amp;item_name=www%2ecodexon%2ecom&amp;currency_code=USD&amp;bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"&gt;Donate&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/Codexon/~4/EzvdRDHi_-Y" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.codexon.com/posts/website-contact-page-finally-fixed#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://www.codexon.com/posts/website-contact-page-finally-fixed/feed/atom" thr:count="0" />
		<thr:total>0</thr:total>
	</entry>
		<entry>
		<author>
			<name>admin</name>
						<uri>http://www.codexon.com</uri>
					</author>
		<title type="html"><![CDATA[Wife beating and domestic violence might be human nature]]></title>
		<link rel="alternate" type="text/html" href="http://www.codexon.com/posts/wife-beating-and-domestic-violence-might-be-human-nature" />
		<id>http://www.codexon.com/?p=804</id>
		<updated>2009-11-26T02:01:06Z</updated>
		<published>2009-11-25T20:50:56Z</published>
		<category scheme="http://www.codexon.com" term="Psychology" />		<summary type="html"><![CDATA[Recently England has mandated that children from the age of 5 would be taught &#8220;how to prevent violent relationships&#8220;. One could explain nearly any &#8220;odd&#8221; but prevalent human behavior through evolutionary psychology. You would think it would be strange to attack someone you were living with and providing benefits. But I found it hard to [...]]]></summary>
		<content type="html" xml:base="http://www.codexon.com/posts/wife-beating-and-domestic-violence-might-be-human-nature">&lt;p&gt;Recently England has mandated that children from the age of 5 would be taught &amp;#8220;&lt;a  href="http://news.bbc.co.uk/2/hi/uk_news/8376943.stm"&gt;how to prevent violent relationships&lt;/a&gt;&amp;#8220;.&lt;/p&gt;
&lt;p&gt;&lt;img class="aligncenter size-full wp-image-839" title="poster" src="http://www.codexon.com/wp-content/uploads/2009/11/poster.jpg" alt="" width="427" height="313" /&gt;&lt;/p&gt;
&lt;p&gt;One could explain nearly any &amp;#8220;odd&amp;#8221; but prevalent human behavior through evolutionary psychology. You would think it would be strange to attack someone you were living with and providing benefits. But I found it hard to be surprised when I found a paper that explained domestic abuse as mate retention behavior.&lt;/p&gt;
&lt;p&gt;In a 2002 study by Peters, Shackleford, and Buss, around 4000 cases of wife abuse in New York was analyzed. They found that abuse was positively correlated with fecundity. Fertile and younger women were 10 times more likely to suffer domestic violence compared to older women. Large decreases in risk were found after the females were  45 years of age when menopause is likely to occur.&lt;/p&gt;
&lt;p&gt;&lt;a  href="http://www.toddkshackelford.com/downloads/Peters-VV-2002.pdf"&gt;http://www.toddkshackelford.com/downloads/Peters-VV-2002.pdf&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If domestic abuse truly serves an evolutionary purpose, schooling might not be enough to curb tendencies.&lt;/p&gt;




	&lt;a  rel="nofollow" target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fwife-beating-and-domestic-violence-might-be-human-nature&amp;#038;title=Wife%20beating%20and%20domestic%20violence%20might%20be%20human%20nature" title="Reddit"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fwife-beating-and-domestic-violence-might-be-human-nature&amp;#038;t=Wife%20beating%20and%20domestic%20violence%20might%20be%20human%20nature" title="Facebook"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;amp;bkmk=http%3A%2F%2Fwww.codexon.com%2Fposts%2Fwife-beating-and-domestic-violence-might-be-human-nature&amp;amp;title=Wife%20beating%20and%20domestic%20violence%20might%20be%20human%20nature&amp;amp;annotation=Recently%20England%20has%20mandated%20that%20children%20from%20the%20age%20of%205%20would%20be%20taught%20%22how%20to%20prevent%20violent%20relationships%22.%0D%0A%0D%0A%0D%0A%0D%0AOne%20could%20explain%20nearly%20any%20%22odd%22%20but%20prevalent%20human%20behavior%20through%20evolutionary%20psychology.%20You%20would%20think%20it%20would%20be%20" title="Google Bookmarks"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /&gt;&lt;/a&gt;
	&lt;a  rel="nofollow" target="_blank" href="http://www.codexon.com/feed" title="RSS"&gt;&lt;img src="http://www.codexon.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /&gt;&lt;/a&gt;


&lt;br/&gt;&lt;br/&gt;&lt;img src="http://www.codexon.com/?ak_action=api_record_view&amp;id=804&amp;type=feed" alt="" /&gt;&lt;hr /&gt;
&lt;a href="http://www.codexon.com/posts/wife-beating-and-domestic-violence-might-be-human-nature#comments"&gt;Leave a Comment&lt;/a&gt; |
&lt;a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=9Y3GJVU7RBVDC&amp;lc=US&amp;item_name=www%2ecodexon%2ecom&amp;currency_code=USD&amp;bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"&gt;Donate&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/Codexon/~4/RL1-jEDHhKc" height="1" width="1"/&gt;</content>
		<link rel="replies" type="text/html" href="http://www.codexon.com/posts/wife-beating-and-domestic-violence-might-be-human-nature#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://www.codexon.com/posts/wife-beating-and-domestic-violence-might-be-human-nature/feed/atom" thr:count="0" />
		<thr:total>0</thr:total>
	</entry>
	</feed><!-- Dynamic page generated in 0.656 seconds. --><!-- Cached page generated by WP-Super-Cache on 2010-09-02 23:36:02 -->
