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

<channel>
	<title>/mad/dem/code</title>
	<atom:link href="http://maddemcode.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://maddemcode.com</link>
	<description></description>
	<lastBuildDate>Fri, 28 Dec 2012 15:49:44 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>New release of django-gearman-commands</title>
		<link>http://maddemcode.com/django/new-release-of-django-gearman-commands/</link>
		<comments>http://maddemcode.com/django/new-release-of-django-gearman-commands/#comments</comments>
		<pubDate>Fri, 28 Dec 2012 15:49:44 +0000</pubDate>
		<dc:creator>jsk</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[django gearman python django-gearman-commands]]></category>

		<guid isPermaLink="false">http://maddemcode.com/?p=254</guid>
		<description><![CDATA[I&#8217;ve released new version of django-gearman-commands 0.2. New features: - support for task namespacing via GEARMAN_CLIENT_NAMESPACE - support for foreground job submission via &#8216;&#8211;foreground&#8217; command switch Available on PyPI. Forks and contributions are welcome]]></description>
				<content:encoded><![CDATA[</p>
<p>I&#8217;ve released new version of <a href="http://pypi.python.org/pypi/django-gearman-commands/0.2" title="django-gearman-commands">django-gearman-commands 0.2</a>.<br />
<strong>New features:</strong></p>
<ul>
<li>- support for task namespacing via GEARMAN_CLIENT_NAMESPACE</li>
<li>- support for foreground job submission via &#8216;&#8211;foreground&#8217; command switch</li>
</ul>
<p>Available on <a href="http://pypi.python.org/pypi/django-gearman-commands/0.2" title="PyPI">PyPI</a>.<br />
Forks and contributions are welcome <img src='http://maddemcode.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://maddemcode.com/django/new-release-of-django-gearman-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gearman and Django</title>
		<link>http://maddemcode.com/django/gearman-and-django/</link>
		<comments>http://maddemcode.com/django/gearman-and-django/#comments</comments>
		<pubDate>Sat, 07 Apr 2012 18:58:28 +0000</pubDate>
		<dc:creator>jsk</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[django gearman python]]></category>

		<guid isPermaLink="false">http://maddemcode.com/?p=231</guid>
		<description><![CDATA[Gearman is server and application framework for distributing and processing jobs between processes and machines. At CodeScale we use Gearman quite extensively therefore we&#8217;ve created library to simplify development of Gearman related modules in Django. You are welcome to read more, download and contribute on GitHub.]]></description>
				<content:encoded><![CDATA[</p>
<p><a href="http://gearman.org">Gearman</a> is server and application framework for distributing and processing jobs between processes and machines.<br />
At <a href="http://codescale.net">CodeScale</a> we use Gearman quite extensively therefore we&#8217;ve created library to simplify development of Gearman related modules in Django.<br />
You are welcome to read more, download and contribute on <a href="https://github.com/jsk/django-gearman-commands">GitHub</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://maddemcode.com/django/gearman-and-django/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Emacs and Python &#8211; The Definitive Answer</title>
		<link>http://maddemcode.com/python/emacs-and-python-the-definitive-answer/</link>
		<comments>http://maddemcode.com/python/emacs-and-python-the-definitive-answer/#comments</comments>
		<pubDate>Sat, 09 Apr 2011 21:56:03 +0000</pubDate>
		<dc:creator>jsk</dc:creator>
				<category><![CDATA[emacs]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[list]]></category>

		<guid isPermaLink="false">http://maddemcode.com/?p=210</guid>
		<description><![CDATA[Over the past year or so, I&#8217;ve used Emacs pretty extensively for Python/Django development. During that time, I&#8217;ve customized my .emacs file a lot, mostly with .el packages found on the net related to Python development in Emacs &#8211; rope, pymacs and friends. If you google python+emacs, you&#8217;ll find a lot of packages and recipes [...]]]></description>
				<content:encoded><![CDATA[</p>
<p>
Over the past year or so, I&#8217;ve used Emacs pretty extensively for Python/Django development.<br />
During that time, I&#8217;ve customized my .emacs file a lot, mostly with .el packages found on the net<br />
related to Python development in Emacs &#8211; rope, pymacs and friends.<br />
If you google python+emacs, you&#8217;ll find a lot of packages and recipes how to glue it all together,<br />
but if you are Emacs Lisp newbie like me, having all that stuff in one easy-to-install, tested package<br />
would be priceless.<br />
I was pretty sure my hacks were not best in the world and someone must have done it better.<br />
And I was right <img src='http://maddemcode.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
<strong>Gabriele Lanaro</strong> put it all into <a href="http://gabrielelanaro.github.com/emacs-for-python/">emacs-for-python</a> package which is really easy to setup<br />
and to be impressed in under a minute.<br />
If you are on Debian/Ubuntu, just install the dependencies:<br />
<code><br />
$ sudo apt-get install pymacs pyflakes<br />
</code><br />
Then extract <a href="http://github.com/gabrielelanaro/emacs-for-python/tarball/master">emacs-for-python</a> somewhere<br />
and add it to your .emacs file:<br />
<code><br />
(load-file "/path/to/epy-init.el")<br />
</code><br />
Reload or restart Emacs and you are ready to go.
</p>
<p>
There are a several pre-configured emacs/python packages out of the box and it all works together flawlessly.<br />
Thank you Gabriele, great work.</p>
]]></content:encoded>
			<wfw:commentRss>http://maddemcode.com/python/emacs-and-python-the-definitive-answer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using SQLite in Django for Unit Testing</title>
		<link>http://maddemcode.com/django/using-sqlite-in-django-for-unit-testing/</link>
		<comments>http://maddemcode.com/django/using-sqlite-in-django-for-unit-testing/#comments</comments>
		<pubDate>Sun, 03 Apr 2011 21:08:08 +0000</pubDate>
		<dc:creator>jsk</dc:creator>
				<category><![CDATA[django]]></category>
		<category><![CDATA[sqlite]]></category>
		<category><![CDATA[unittest]]></category>

		<guid isPermaLink="false">http://maddemcode.com/?p=190</guid>
		<description><![CDATA[&#160; Great thing about Django is that configuration &#8211; settings.py is pure Python file. This gives you power and expressiveness allowing to use conditions and expressions normally available in python script. On past few projects, I&#8217;ve used &#8216;trick&#8217; to automatically determine if &#8216;manage.py test&#8217; was invoked and use SQLite for unit testing instead of standard [...]]]></description>
				<content:encoded><![CDATA[<p>&nbsp;</p>
<p>Great thing about Django is that configuration &#8211; <strong>settings.py</strong> is pure Python file.<br />
This gives you power and expressiveness allowing to use conditions and expressions normally available in python script.<br />
On past few projects, I&#8217;ve used &#8216;trick&#8217; to automatically determine if &#8216;manage.py test&#8217; was invoked<br />
and use SQLite for unit testing instead of standard database used for production.<br />
I thought it&#8217;s worth sharing, so here it is <img src='http://maddemcode.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>The point is that if you have unit tests in your application(s) (which you should, believe me), running them on top of &#8216;standard&#8217; database used for development or production (PostgreSQL, MySQL&#8230;) may be not the fastest thing around.<br />
Considering you have _a lot_ of unit tests or initial_data fixtures, running them in memory would be great thing.<br />
Let&#8217;s customize settings.py a little bit.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># is ./manage.py test ?</span>
TEST <span style="color: #66cc66;">=</span> <span style="color: #483d8b;">'test'</span> <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> TEST:
    <span style="color: #808080; font-style: italic;"># in-memory SQLite used for testing</span>
    DATABASES <span style="color: #66cc66;">=</span> <span style="color: black;">&#123;</span>
            <span style="color: #483d8b;">'default'</span>: <span style="color: black;">&#123;</span>
                <span style="color: #483d8b;">'ENGINE'</span>: <span style="color: #483d8b;">'django.db.backends.sqlite3'</span><span style="color: #66cc66;">,</span>
                <span style="color: #483d8b;">'NAME'</span>: <span style="color: #483d8b;">':memory:'</span><span style="color: #66cc66;">,</span>
                <span style="color: black;">&#125;</span>
            <span style="color: black;">&#125;</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
    <span style="color: #808080; font-style: italic;"># devevelopment/production db</span>
    DATABASES <span style="color: #66cc66;">=</span> <span style="color: black;">&#123;</span>
            <span style="color: #483d8b;">'default'</span>: <span style="color: black;">&#123;</span>
                <span style="color: #483d8b;">'ENGINE'</span>: <span style="color: #483d8b;">'django.db.backends.postgresql_psycopg2'</span><span style="color: #66cc66;">,</span>
                <span style="color: #483d8b;">'NAME'</span>: <span style="color: #483d8b;">'yourproductiondb'</span><span style="color: #66cc66;">,</span>
                <span style="color: #483d8b;">'USER'</span>: <span style="color: #483d8b;">'yourproductiondbuser'</span><span style="color: #66cc66;">,</span>
                <span style="color: #483d8b;">'PASSWORD'</span>: <span style="color: #483d8b;">&quot;secret_password&quot;</span><span style="color: #66cc66;">,</span>
                <span style="color: #483d8b;">'HOST'</span>: <span style="color: #483d8b;">'localhost'</span><span style="color: #66cc66;">,</span>
                <span style="color: #483d8b;">'PORT'</span>: <span style="color: #483d8b;">''</span><span style="color: #66cc66;">,</span>
                <span style="color: black;">&#125;</span><span style="color: #66cc66;">,</span>
            <span style="color: black;">&#125;</span></pre></td></tr></table></div>

<p>
So what we did:<br />
- automatically determine if &#8216;./manage.py test&#8217; was invoked and store that in TEST variable<br />
- if TEST is True, use SQLite in-memory database instead of your production/development database</p>
<p>Assuming your tests and models are fine with SQLite, you can save some time when periodically running unit tests,<br />
which is worth some hacking <img src='http://maddemcode.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
			<wfw:commentRss>http://maddemcode.com/django/using-sqlite-in-django-for-unit-testing/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>log4net MongoDB appender</title>
		<link>http://maddemcode.com/net/log4net-mongodb-appender/</link>
		<comments>http://maddemcode.com/net/log4net-mongodb-appender/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 23:33:40 +0000</pubDate>
		<dc:creator>jsk</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[log4net]]></category>
		<category><![CDATA[mongodb]]></category>

		<guid isPermaLink="false">http://maddemcode.com/?p=178</guid>
		<description><![CDATA[&#160; I have some good news for anyone interested in logging from log4net into MongoDB. I have created log4net appender for Mongo, so it&#8217;s now easily possible to use MongoDB as a storage for the logs. Details, sources, download, everything is on GitHub: log4mongo-net at GitHub More info, quickstart: log4mongo.org]]></description>
				<content:encoded><![CDATA[<p>&nbsp;</p>
<p>
I have some good news for anyone interested in logging from <a href="http://logging.apache.org/log4net/">log4net</a> into <a href="http://www.mongodb.org">MongoDB</a>.<br />
I have created log4net appender for Mongo, so it&#8217;s now easily possible to use MongoDB as a storage for the logs.<br />
Details, sources, download, everything is on GitHub:<br />
<a href="http://github.com/log4mongo/log4mongo-net">log4mongo-net at GitHub</a><br />
More info, quickstart: <a href="http://log4mongo.org/display/PUB/Log4mongo+for+.NET">log4mongo.org</a></p>
]]></content:encoded>
			<wfw:commentRss>http://maddemcode.com/net/log4net-mongodb-appender/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Getting Started with Memcached</title>
		<link>http://maddemcode.com/memcached/getting-started-with-memcached/</link>
		<comments>http://maddemcode.com/memcached/getting-started-with-memcached/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 00:11:28 +0000</pubDate>
		<dc:creator>jsk</dc:creator>
				<category><![CDATA[memcached]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[caching]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[scalability]]></category>
		<category><![CDATA[spymemcached]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://maddemcode.com/?p=147</guid>
		<description><![CDATA[Introduction into caching with Memcached for beginners]]></description>
				<content:encoded><![CDATA[</p>
<p><strong>The goal of this article<br />
What is caching<br />
What is Memcached<br />
Installation (Linux, Windows)<br />
Basic get/set operations<br />
Where to go next<br />
Conclusion<br />
</strong></p>
<p><strong>The goal of this article</strong><br />
This article is aiming to provide basic introduction into server-side<br />
caching using open-source memcached system. If you are developer looking for caching<br />
solution for your (web)applications, this article is going to give you the overview<br />
of how to install and use memcached from several programming environments.<br />
The goal of this article is to provide quick overview for developers with zero or minimal experience<br />
with memcached, not to provide comprehensive reference of all memcached features. </p>
<p><strong>What is caching</strong><br />
Performance matters. This fact becomes more and more important in the era of the web sites<br />
with thounsands, millions or hundreds of milions of users.<br />
Caching is one of the most important performance strategy applicable independently from the type of your application.<br />
The basic idea is pretty simple &#8211; reduce the number of expensive tasks and put the results into the storage which is accesible faster.</p>
<p>You can find implementation of caching in many software products you use on daily-basis.<br />
- Web browser cache images, scripts, or whole pages retrieved from server, storing them on client disk<br />
- Text processor reads content of file from disk into memory to provide better performance when working with document<br />
- Server-side application store results read from database in memory for faster access</p>
<p><strong>What is Memcached</strong><br />
<a href="http://memcached.org/">Memcached</a> is free, open-source memory caching system with focus on high-performance,<br />
distributed deployment and scalability.<br />
Memcached started as a project for LiveJournal with very clear goal &#8211; speed up website by caching frequently<br />
used items loaded from database into memory. Today, memcached is the core infrastructure component for the biggest players on web field, including Google/YouTube, Digg, Facebook, Wikipedia, Amazon and many others. </p>
<p>The design concept is that memcached acts as an key-value store, running separately from your application.<br />
The independence from the memcached consumer is very important for easy deployment and the fact<br />
that memcached stays generic from the consumer&#8217;s perspective.<br />
Memcached runs as a separate service/daemon listening for incoming connection on TCP/IP.<br />
Clients opens TCP connection to memcached, sends storage or retrieval command, gets response and closes the connection. Clients usually use socket pools to eliminate the need to open separate connection for every memcached request and returns connection into pool after performing the operation instead of closing it.</p>
<p><strong>Installation (Linux, Windows)</strong><br />
This chapter is going to guide you through the basic installation procedure on Linux and Windows platforms<br />
with special focus on common pitfals of Windows memcached port.</p>
<p><strong>Linux</strong><br />
Linux is probably the most commonly used OS for memcached with wide support of binary, ready to use packages for various distributions.<br />
Memcached has dependency on libevent library, therefore you need also libevent to get memcached up&#038;running.<br />
On Debian/.deb-based distros, installation is pretty easy:</p>
<pre>
$ sudo apt-get install memcached
</pre>
<p>This will install memcached and required dependencies (libevent).<br />
On Debian, the config file is /etc/memcached.conf. There is a list of command-line options with comments.</p>
<p>For installation from source, get the latest source from <a href="http://memcached.org/">memcached homepage</a> and proceed<br />
with standard ./configure &#038;&#038; make commands. Note that libevent (and libevent-dev on Debian) must be available.</p>
<p><strong>Windows</strong><br />
Installation on Windows can be tricky due to the fact that there are several versions of memcached compiled for Windows. The main difference is their age and the level of potentional issues. I recommend using the most recent build from <a href="http://code.jellycan.com/memcached/">jellycan</a> which is basically memcached 1.2.6 compiled for Windows.<br />
<a href="http://code.jellycan.com/files/memcached-1.2.6-win32-bin.zip">Get it</a>, unzip, execute memcached.exe and you have the most minimal memcached setup ready.<br />
Windows is not officially supported as a target platform for which memcached is continuously built and tested.<br />
If you are more interested on the reasons for this, <a href="http://groups.google.com/group/memcached/browse_thread/thread/8c7eea241def70f9">this thread</a> is quite interesting description<br />
of actual problems.</p>
<p>The very funny part about memcached on Windows is running it as a service with non-default settings.<br />
As the default configuration of memcached allows only 64MB of RAM to be used for items, the very<br />
common requirement for running memcached is to run it as a service with more than 64MB of memory allowed.<br />
Default memcached switch for installing as a service on Windows is &#8216;-d&#8217;, which ignores additional command-line options.<br />
This problem can be resolved using &#8216;sc.exe&#8217; for service installer.</p>
<pre>
@echo off
set ramSize=512

sc create memcached binPath= "c:\memcached\memcached.exe -d runservice -m %ramSize%" start= auto DisplayName= "memcached"
sc start memcached
</pre>
<p>Save this to the install.bat file, change the path to memcached.exe and ramSize if needed, then run the bat file.</p>
<p><strong>Test if memcached is running and accepting connections</strong><br />
Memcached by default listen on TCP port 11211.<br />
After installation, you can test if memcached is accepting incoming connection just with telnet.</p>
<pre>
$ telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
version
VERSION 1.2.8
quit
Connection closed by foreign host.
$
</pre>
<p>Note that on Windows 2008 Server, telnet is not installed by default and must be added as additional component.<br />
However, I recommend using <a href="http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html">PuTTY</a> on Windows instead.</p>
<p><strong>Basic get/set operations</strong><br />
Before we jump into real code, there are few things which you should keep in mind from the start:</p>
<p>- maximum size per item in memcached is 1MB. This is by-design limitation, mostly done because of memory allocation optimizations. This problem can be partially resolved using compression on client-side before putting item into cache, but not for all cases. Memcached is not the right place to cache large images or documents. Memcached is optimized to store small chunks of data (strings, objects etc). However stored objects can be anything as memcached follows &#8216;What you set is what you get&#8217; rule, keep the size limitation in mind.</p>
<p>- memcached does not provide security/authentication mechanism. Again, this is by design. Memcached is designed to be as fast as possible and you should delegate security to different layer. The simplest way is to firewall memcached server(s) which would allow only machines connecting to memcached directly (web servers) to open the connection. In common scenarios, memcached servers are not a part of publicly visible network and only web servers know IPs of memcached servers in internal network.  </p>
<p>- memcached is not a database, it&#8217;s a key-value pair store. You can&#8217;t make something like &#8216;select * from items&#8217; on memcached to dump all items in cache or so. Normally, you can access values in cache only by knowing their key(s).</p>
<p>The most common operations with memcached are getting items from cache and setting them to cache.<br />
If you have code which query database for anything and then send the results out, you can basically<br />
rewrite it to query the memcache first. If item is found in the cache, you send this out &#8211; avoiding DB query.<br />
If item is not yet in the cache (which can be for several reasons we&#8217;ll describe later), you get results from DB query first<br />
and then set them into the cache. On next request, only cache will be hit and you get the performance boost.</p>
<p>Speaking in code, if you have something like:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="c" style="font-family:monospace;">result <span style="color: #339933;">=</span> query<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;select a,b,c from x&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> result<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>You can rewrite it into:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="c" style="font-family:monospace;">result <span style="color: #339933;">=</span> get_from_memcache<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;mykey1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>result <span style="color: #339933;">==</span> NULL<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
 result <span style="color: #339933;">=</span> query<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;select a,b,c from x&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// get result from DB</span>
 set_to_memcache<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;mykey1&quot;</span><span style="color: #339933;">,</span> result<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// set result into memcache</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">return</span> result<span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>It&#8217;s that simple. Note that there are several reasons client may return NULL/null/undefined/None value for get operation:<br />
- item is not yet in the cache under specified key<br />
- item may be expired. Memcached supports expiration of items which is very useful if you need automatically invalidate item after some period of time. You can also set expiry parameter to &#8217;0&#8242; and tell memcache not to expire item.<br />
- item may be deleted<br />
- memcached has been restarted, or &#8216;flush_all&#8217; command was sent to memcached, cleaning up all caches</p>
<p>I&#8217;d recommend following libraries for Python, Java and .NET.</p>
<p><strong>Python</strong><br />
<a href="http://www.tummy.com/Community/software/python-memcached/">python-memcached</a> package, available though apt-get or easy_install.<br />
You can also use this package with Django.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">import</span> memcache
<span style="color: #66cc66;">&gt;&gt;&gt;</span> mc <span style="color: #66cc66;">=</span> memcache.<span style="color: black;">Client</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'127.0.0.1:11211'</span><span style="color: black;">&#93;</span><span style="color: #66cc66;">,</span> debug<span style="color: #66cc66;">=</span><span style="color: #ff4500;">0</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> mc.<span style="color: #008000;">set</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;a&quot;</span><span style="color: #66cc66;">,</span> <span style="color: #483d8b;">&quot;X1&quot;</span><span style="color: black;">&#41;</span>
<span style="color: #008000;">True</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> mc.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;a&quot;</span><span style="color: black;">&#41;</span>
<span style="color: #483d8b;">'X1'</span></pre></td></tr></table></div>

<p><strong>Java</strong><br />
<a href="http://code.google.com/p/spymemcached/">spymemcached</a> is library developed and maintaned by memcached core contributor.<br />
It&#8217;s also good choice if you use Hibernate for you projects, because <a href="http://code.google.com/p/hibernate-memcached/">hibernate-memcached</a> second level cache provider is based on spymemcached. I would recommend using spymemcached even you don&#8217;t use Hibernate.</p>
<p><strong>.NET</strong><br />
<a href="http://www.codeplex.com/EnyimMemcached/">enyim.com Memcached Client</a> seems to be the best option for .NET client and is under active development.<br />
However, if you would like to use NHibernate with memcached, NHibernate memcached provider ships with different library (far older and not under active development).<br />
If you do not use NHibernate, I would recommend go with Enyim.</p>
<p><strong>Where to go next </strong><br />
Except the basic get/set operations, there is a lot of other magic available in memcached.<br />
Very detailed description of all commands and options can be found in <a href="http://github.com/memcached/memcached/blob/master/doc/protocol.txt">protocol documentation</a>, for example statistics, increment/decrement statements, multi-get retrieval, UDP protocol usage and other built-in features.</p>
<p>There is a large community around memcached and a lot of useful resources.<br />
Following links are good starting point:<br />
<a href="http://memcached.org/">Memcached official site</a><br />
<a href="http://groups.google.com/group/memcached">Memcached support mailing list</a><br />
<a href="http://code.google.com/p/memcached/wiki/Start">Memcached wiki, FAQ, HowTos </a><br />
<a href="http://code.google.com/p/memcached/wiki/Clients">List of client APIs/libraries</a><br />
<a href="http://code.google.com/p/memcached/wiki/MemcachedOffspring">Forks/reimplementations and other projects related to memcached</a></p>
<p><strong>Conclusion</strong><br />
Memcached may be the silver bullet for many scalability problems of webapplications where frequent read operations from slower store (database, disk..) occurs.<br />
However memcached can help you &#8216;make things faster&#8217;, keep in mind that the optimization rule #1 is to optimize application logic where possible.<br />
Sooner or later, nothing will save you in case of poorly designed DB queries or suboptimal algorithms.<br />
If you pass this &#8216;optimize yourself&#8217; routine and decide you need caching, memcached can be very handy because<br />
of its stability, strong adoption, excellent community support and distributed nature.</p>
<p>
Slovak translation of this article at <a href="http://zdrojak.root.cz/clanky/zrychlete-sve-webove-aplikace-s-memcached/">Zdrojak</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://maddemcode.com/memcached/getting-started-with-memcached/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>WebSockets and pywebsocket &#8211; quick &amp; dirty playground</title>
		<link>http://maddemcode.com/web/websockets-and-pywebsocket-quick-dirty-playground/</link>
		<comments>http://maddemcode.com/web/websockets-and-pywebsocket-quick-dirty-playground/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 22:33:47 +0000</pubDate>
		<dc:creator>jsk</dc:creator>
				<category><![CDATA[web]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[pywebsocket]]></category>
		<category><![CDATA[websocket]]></category>

		<guid isPermaLink="false">http://maddemcode.com/?p=125</guid>
		<description><![CDATA[Playing with HTML 5 WebSockets One of the interesting features proposed for HTML 5 is The Web Sockets API. Web Sockets API define bidirectional communication between the web browser (using Javascript) and server. The use of Web Sockets may be very interesting replacement of frequent browser-to-server calls, especially for &#8216;check if something has changed&#8217; or [...]]]></description>
				<content:encoded><![CDATA[<p>Playing with HTML 5 WebSockets</p>
<p>
One of the interesting features proposed for HTML 5 is <a href="http://dev.w3.org/html5/websockets/">The Web Sockets API</a>.<br />
Web Sockets API define bidirectional communication between the web browser (using Javascript) and server. The use of Web Sockets may be very interesting replacement of frequent browser-to-server calls, especially for &#8216;check if something has changed&#8217; or &#8216;is there something new ?&#8217; tasks. Web Sockets API also support tunneling through HTTP CONNECT statements, therefore firewalls and proxy servers would not be a problem.
</p>
<p>
Talk is cheap, show me the code !<br />
The easiest option that worked for me was checking out <a href="http://code.google.com/p/pywebsocket/">pywebsocket</a> which claims to be Web Sockets extension for Apache. The pywebsockets distribution contains standalone version of server and some samples so you don&#8217;t need to do any magic with Apache to see &#8216;the real thing&#8217;.<br />
First, checkout the pywebsocket, build it and run standalone.py:
</p>
<pre>
$ svn checkout http://pywebsocket.googlecode.com/svn/trunk/ pywebsocket-read-only
$ cd pywebsocket-read-only/src
$ python setup.py build
$ sudo python setup.py install
$ cd mod_pywebsocket/
$ sudo python standalone.py -d ../example/
</pre>
<p>
Now you have standalone version of pywebsocket up&#038;running, using &#8216;../example&#8217; as document root.<br />
There is &#8216;echo_wsh.py&#8217; script in example directory which provides basic ECHO service.<br />
Now, create the HTML file with the JavaScript which we&#8217;ll use as ECHO client:
</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
function sendMessage() {
        var msg = document.getElementById('message').value;
        if (&quot;WebSocket&quot; in window) {
                var ws = new WebSocket(&quot;ws://localhost/echo&quot;);
                ws.onopen = function() {
                        ws.send(msg); 
                };
                ws.onmessage = function (evt) { 
                        var received_msg = evt.data; 
                        showResponse(received_msg);
                };
                ws.onclose = function() { alert('socket closed'); };
        } else {
                alert('no websockets');
        }
}
&nbsp;
function showResponse(msg) {
        document.getElementById('response').innerHTML = document.getElementById('response').innerHTML + msg + '<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">br</span>&gt;</span>'
}
&nbsp;
function clearResponse() {
        document.getElementById('message').value = '';
        document.getElementById('response').innerHTML = '';
}
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;message&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;message&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Send&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sendMessage()&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">hr</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Clear&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;clearResponse()&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;response&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span></pre></td></tr></table></div>

<p>
Note that HTML/Javascript is really quick&#038;dirty, but it will work for the test.<br />
Open Chrome browser (version 4.0.249.0 and higher implements WebSockets API) and browse HTML test file.<br />
Enter something into input field and voilà, server will echo your message and you will see the response:
</p>
<p><img src="http://maddemcode.com/wp-content/uploads/2009/12/WebSockets1.png" alt="WebSockets" title="WebSockets" width="261" height="107" class="alignnone size-full wp-image-140" /></p>
<p>
You will also see alert when you interrupt standalone.py.<br />
I hope the WebSockets API will get some attention from other browser vendors (support in Firefox in progress, AFAIK) as this may be lifesaver for many cases where bidirectional messaging between browser and server comes to game.</p>
]]></content:encoded>
			<wfw:commentRss>http://maddemcode.com/web/websockets-and-pywebsocket-quick-dirty-playground/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Django 1.2 is coming</title>
		<link>http://maddemcode.com/django/django-1-2-is-coming/</link>
		<comments>http://maddemcode.com/django/django-1-2-is-coming/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 21:04:14 +0000</pubDate>
		<dc:creator>jsk</dc:creator>
				<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://maddemcode.com/?p=116</guid>
		<description><![CDATA[&#8230;and seems to be impressive. I just read What&#8217;s coming in Django 1.2 and new features are very promising. Django 1.2 final should be released on March 2010 and according to the roadmap feature list is already frozen. Here are some of them I&#8217;m very happy with: Integrating logging with Python &#8211; huge advantage for [...]]]></description>
				<content:encoded><![CDATA[<p>&#8230;and seems to be impressive.</p>
<p>
I just read <a href="http://simonwillison.net/static/2009/djugl-december.html">What&#8217;s coming in Django 1.2</a> and new features are very promising. Django 1.2 final should be released on March 2010 and according to the <a href="http://code.djangoproject.com/wiki/Version1.2Roadmap">roadmap</a> feature list is already frozen.
</p>
<p>
Here are some of them I&#8217;m very happy with:<br />
<strong>Integrating logging with Python</strong> &#8211; huge advantage for debugging<br />
<strong>QuerySet.raw()</strong> &#8211; mapping to model instances using raw SQL, automatically<br />
<strong>Multi-DB support</strong> &#8211; big step forward for sharding/clustering scenarios
</p>
<p>Can&#8217;t wait ! <img src='http://maddemcode.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://maddemcode.com/django/django-1-2-is-coming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Skype on Linux and green screen instead of video</title>
		<link>http://maddemcode.com/linux/skype-on-linux-and-green-screen-instead-of-video/</link>
		<comments>http://maddemcode.com/linux/skype-on-linux-and-green-screen-instead-of-video/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 18:57:41 +0000</pubDate>
		<dc:creator>jsk</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[skype video]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://maddemcode.com/?p=106</guid>
		<description><![CDATA[And solution for Ubuntu If you encounter seeing sluggish broken green screen in your Skype instead of the video, try to run skype like this: LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype For 64-bit Ubuntu, the path may vary (probably /usr/lib32/libv4l/v4l1compat.so). If your skype video works using this trick, you can create shell alias and put it into .bashrc. This [...]]]></description>
				<content:encoded><![CDATA[<p>And solution for Ubuntu</p>
<p>If you encounter seeing sluggish broken green screen in your Skype instead of the video, try to run skype like this:</p>
<pre>LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype</pre>
<p>For 64-bit Ubuntu, the path may vary (probably /usr/lib32/libv4l/v4l1compat.so).<br />
If your skype video works using this trick, you can create shell alias and put it into .bashrc.<br />
This fixed my issue on Ubuntu 9.10 with <a href="http://www.skype.com/go/getskype-linux-beta-ubuntu-32">Skype beta for Ubuntu</a>, hope that helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://maddemcode.com/linux/skype-on-linux-and-green-screen-instead-of-video/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install Chrome/Chromium in Ubuntu &#8211; quick &amp; easy</title>
		<link>http://maddemcode.com/linux/install-chromechromium-in-ubuntu-quic-easy/</link>
		<comments>http://maddemcode.com/linux/install-chromechromium-in-ubuntu-quic-easy/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 18:30:53 +0000</pubDate>
		<dc:creator>jsk</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[chromium]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.meowcode.com/?p=80</guid>
		<description><![CDATA[How to install Chromium daily builds on Ubuntu: UPDATE: Chrome on Linux is not officialy supported. sudo echo "deb http://ppa.launchpad.net/chromium-daily/ppa/ubuntu jaunty main" >>/etc/apt/sources.list sudo echo "deb-src http://ppa.launchpad.net/chromium-daily/ppa/ubuntu jaunty main" >>/etc/apt/sources.list sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 4E5E17B5 sudo apt-get update sudo apt-get install chromium-browser]]></description>
				<content:encoded><![CDATA[<p>How to install Chromium daily builds on Ubuntu:</p>
<p>
<strong>UPDATE: </strong>Chrome on Linux is not officialy supported.
</p>
<pre>
sudo echo "deb http://ppa.launchpad.net/chromium-daily/ppa/ubuntu jaunty main" >>/etc/apt/sources.list
sudo echo "deb-src http://ppa.launchpad.net/chromium-daily/ppa/ubuntu jaunty main" >>/etc/apt/sources.list
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 4E5E17B5
sudo apt-get update
sudo apt-get install chromium-browser
</pre>
]]></content:encoded>
			<wfw:commentRss>http://maddemcode.com/linux/install-chromechromium-in-ubuntu-quic-easy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
