<?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>Hacking Habits</title>
	<atom:link href="http://hackinghabits.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://hackinghabits.com</link>
	<description>A Journal On Machine learning, Internet &#38; Programming.</description>
	<lastBuildDate>Sat, 28 Jan 2012 22:56:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Deploying strategies for small websites</title>
		<link>http://hackinghabits.com/2012/01/28/deploying-strategies-for-small-websites/</link>
		<comments>http://hackinghabits.com/2012/01/28/deploying-strategies-for-small-websites/#comments</comments>
		<pubDate>Sat, 28 Jan 2012 22:54:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://hackinghabits.com/?p=346</guid>
		<description><![CDATA[Most one person startups do not have enough infrastructure to deploy on a distributed failsafe website. I was just looking at shared hosting options like Godaddy, Dreammhost, Bluehost and webfaction among others. I was curious about the memory limits offered at each hosting and was too lazy to read their pricing pages for the information. [...]]]></description>
			<content:encoded><![CDATA[<p>Most one person startups do not have enough infrastructure to deploy on a distributed failsafe website. I was just looking at shared hosting options like Godaddy, Dreammhost, Bluehost and webfaction among others. I was curious about the memory limits offered at each hosting and was too lazy to read their pricing pages for the information. What was easy was to write a short script in python that would just hog some memory and see when my process is taken down by the host. </p>
<p><strong>My script:</strong></p>
<blockquote><p><code><br />
a = []<br />
>>> def memory_hog():<br />
...  for i in range(1000):<br />
...   a.append(a + ["what"])<br />
>>> memory_hog()<br />
>>> memory_hog()<br />
.<br />
x times<br />
.<br />
>>> memory_hog()<br />
</code></p></blockquote>
<p>Dreamhost was pretty prompt in killing my python processes as soon as the python process hit 512MB of RAM with the following message. </p>
<p>&#8220;Yikes! One of your processes (python, pid 22279) was just killed for excessive resource usage.<br />
Please contact DreamHost Support for details.&#8221;</p>
<p>It was depressing that Godaddy hosting services only offered python 2.4 but it does not matter for this test. On the specific Godaddy server that I was testing, there was a total of 12G of memory and I was able to easily hog memory for well over 2G and my process was not killed. I did not test my limit to see if the server goes down since python 2.4 was already not worth for me to explore more.</p>
<p>Webfaction claims to have a memory limit of 256MB which is quite constrained.</p>
<p>My hope is to use a combination of AWS and a few of these other shared hosting to deploy the site. Maintaining db server, memcache and lb on aws and deploying multiple webservers on shared hosting seems like a possibility.</p>
]]></content:encoded>
			<wfw:commentRss>http://hackinghabits.com/2012/01/28/deploying-strategies-for-small-websites/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Storm WordCountTopology Error: Cannot run program &#8220;python&#8221;</title>
		<link>http://hackinghabits.com/2012/01/22/storm-wordcounttopology-error-cannot-run-program-python/</link>
		<comments>http://hackinghabits.com/2012/01/22/storm-wordcounttopology-error-cannot-run-program-python/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 23:05:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://hackinghabits.com/?p=338</guid>
		<description><![CDATA[I have been playing around with Storm which was opensourced by Twitter recently.(Checkout the github code). It is dubbed as a realtime map reduce system but it is very generic to perform a variety of operations. I explored Storm-Starter which has some examples storm topologies to help get your feet wet. Most java examples worked [...]]]></description>
			<content:encoded><![CDATA[<p>I have been playing around with <a href="http://engineering.twitter.com/2011/08/storm-is-coming-more-details-and-plans.html" title="Storm">Storm</a> which was opensourced by Twitter recently.(<a href="https://github.com/nathanmarz/storm" title="Twitter Storm">Checkout the github code</a>). It is dubbed as a realtime map reduce system but it is very generic to perform a variety of operations. </p>
<p>I explored <a href="https://github.com/nathanmarz/storm-starter" title="storm starter">Storm-Starter</a> which has some examples storm topologies to help get your feet wet. Most java examples worked fine for me but I got issues in running the WordCountTopology. The WordCountTopology example uses the python language to write its bolt. I kept getting the error below:</p>
<blockquote><p>Cannot run program &#8220;python&#8221; (in directory &#8220;/tmp/cf2bf9a &#8230;</p></blockquote>
<p><strong>The problem was solved by adding the &#8220;multilang&#8221; directory in Storm-Starter project to the class path.<br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://hackinghabits.com/2012/01/22/storm-wordcounttopology-error-cannot-run-program-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Removing HTML tags</title>
		<link>http://hackinghabits.com/2012/01/16/removing-html-tags/</link>
		<comments>http://hackinghabits.com/2012/01/16/removing-html-tags/#comments</comments>
		<pubDate>Mon, 16 Jan 2012 07:29:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://hackinghabits.com/?p=330</guid>
		<description><![CDATA[The code snippet below is a function in python for removing html tags from a text. It can be used from a python terminal as shown in the image or within a python module. Usage: 1) Remove &#8216;a&#8217; tags: Type the commands as shown in the image below in a python terminal]]></description>
			<content:encoded><![CDATA[<p>The code snippet below is a function in python for removing html tags from a text. It can be used from a python terminal as shown in the image or within a python module. </p>
<p><script src="https://gist.github.com/1619612.js?file=stip-python"></script></p>
<h2>Usage:</h2>
<p>1) Remove &#8216;a&#8217; tags: Type the commands as shown in the image below in a python terminal</p>
<p>   <a href="http://hackinghabits.com/wp-content/uploads/2012/01/Screenshot-16.png"><img src="http://hackinghabits.com/wp-content/uploads/2012/01/Screenshot-16.png" alt="Removing HTML tags" title="Removing HTML tags" width="560" height="173" class="alignnone size-full wp-image-331" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://hackinghabits.com/2012/01/16/removing-html-tags/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thunderbird RSS Notification</title>
		<link>http://hackinghabits.com/2011/12/30/thunderbird-rss-notification/</link>
		<comments>http://hackinghabits.com/2011/12/30/thunderbird-rss-notification/#comments</comments>
		<pubDate>Fri, 30 Dec 2011 07:44:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[hackinghabits]]></category>

		<guid isPermaLink="false">http://hackinghabits.com/?p=320</guid>
		<description><![CDATA[Thunderbird is a wonderful mail client but I missed something really important to me &#8211; Growl like notifications for RSS feeds. When I received new emails, Thunderbird would notify me but it would not notify when I received new RSS updates. I looked online but I could not find a good one solution to enable [...]]]></description>
			<content:encoded><![CDATA[<p>Thunderbird is a wonderful mail client but I missed something really important to me &#8211; Growl like notifications for RSS feeds. When I received new emails, Thunderbird would notify me but it would not notify when I received new RSS updates. I looked online but I could not find a good one solution to enable notifications for RSS feeds (I must be totally blind). I decided to write my own and here it is, a linux growl like feature that sends notifications on new RSS and email messages.</p>
<p><a href="https://addons.mozilla.org/en-US/thunderbird/addon/linux-growl/">https://addons.mozilla.org/en-US/thunderbird/addon/linux-growl/</a></p>
<p>Screenshot:<br />
<a href="http://hackinghabits.com/wp-content/uploads/2011/12/66184.png"><img src="http://hackinghabits.com/wp-content/uploads/2011/12/66184-300x238.png" alt="" title="Thunderbird new RSS notifications" width="300" height="238" class="alignnone size-medium wp-image-324" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://hackinghabits.com/2011/12/30/thunderbird-rss-notification/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OSQA 1.0rc on Django 1.3</title>
		<link>http://hackinghabits.com/2011/11/25/osqa-1-0rc-on-django-1-3/</link>
		<comments>http://hackinghabits.com/2011/11/25/osqa-1-0rc-on-django-1-3/#comments</comments>
		<pubDate>Fri, 25 Nov 2011 21:47:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[osqa]]></category>

		<guid isPermaLink="false">http://hackinghabits.com/?p=305</guid>
		<description><![CDATA[OSQA is a stack overflow clone in Django. It is pretty well featured and easy to use compared to a number of other counterparts. Though the next release is waiting for even, there are release candidates and the development version on trunk. If you are planning to use the 1.0 release candidate along with Django [...]]]></description>
			<content:encoded><![CDATA[<p><a title="osqa" href="http://www.osqa.net/" target="_blank">OSQA</a> is a stack overflow clone in <a title="django" href="https://www.djangoproject.com/" target="_blank">Django</a>. It is pretty well featured and easy to use compared to a number of other counterparts. Though the next release is waiting for even, there are release candidates and the development version on trunk. If you are planning to use the <a title="osqa" href="http://svn.osqa.net/svnroot/osqa/tags/osqa-1.0rc-20110802/" target="_blank">1.0 release candidate</a> along with Django 1.3, there are few things that you might likely need to get it working. The primary changes are related to modules being moved around on Django 1.3.</p>
<p style="padding-left: 30px;">In settings.p, you will require the following changes.</p>
<blockquote><p>
TEMPLATE_LOADERS = [<br />
<span style="color: #ff0000;">-'django.template.loaders.filesystem.Loader',</span><br />
<span style="color: #ff0000;"> -'django.template.loaders.app_directories.Loader',</span><br />
<span style="color: #99cc00;">+'django.template.loaders.filesystem.Loader', </span><br />
<span style="color: #99cc00;"> +'django.template.loaders.app_directories.Loader', </span><br />
'forum.modules.template_loader.module_templates_loader',<br />
'forum.skins.load_template_source',<br />
]<br />
TEMPLATE_CONTEXT_PROCESSORS = [<br />
'django.core.context_processors.request',<br />
'forum.context.application_settings',<br />
'forum.user_messages.context_processors.user_messages',<br />
<span style="color: #ff0000;">-'django.core.context_processors.auth',</span><br />
<span style="color: #99cc00;">+'django.contrib.auth.context_processors.auth',</span><br />
]</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://hackinghabits.com/2011/11/25/osqa-1-0rc-on-django-1-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Boto for Amazon Route53</title>
		<link>http://hackinghabits.com/2011/08/20/boto-for-amazon-route53/</link>
		<comments>http://hackinghabits.com/2011/08/20/boto-for-amazon-route53/#comments</comments>
		<pubDate>Sat, 20 Aug 2011 22:14:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tips N Tricks]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[boto]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[route53]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://hackinghabits.com/?p=282</guid>
		<description><![CDATA[Route53 is Amazon&#8217;s scalable Domain Name System (DNS) web service. If you are already having your infrastructure on Amazon&#8217;s EC2 infrastructure, it is an easy move from your existing DNS provider to Route53. Boto is a python package that provides a number of python interfaces to interract with Amazon Web Services (AWS) like EC2, RDS, [...]]]></description>
			<content:encoded><![CDATA[<p>Route53 is Amazon&#8217;s scalable Domain Name System (DNS) web service. If you are already having your infrastructure on Amazon&#8217;s EC2 infrastructure, it is an easy move from your existing DNS provider to Route53. </p>
<p><a href="http://code.google.com/p/boto/">Boto</a> is a python package that provides a number of python interfaces to interract with Amazon Web Services (AWS) like EC2, RDS, ELB, etc. Boto interface for Route53 is pretty simple. Boto allows adding &#8216;A&#8217;, &#8216;AAAA&#8217;, &#8216;TXT&#8217;, &#8216;CNAME&#8217;, &#8216;MX&#8217;, &#8216;PTR&#8217;, &#8216;SRV&#8217; and  &#8216;SPF&#8217; records to Route53.</p>
<p>Each zone that is created on Route53 has a zone id which can be obtained by using the command line utility provided by amazon.</p>
<blockquote><p>% ./bin/route53 ls<br />
============================================<br />
| ID:   ZXXXXXXXXXXXXXX<br />
| Name: yourdomain.com.<br />
| Ref:  xxxxxxx-xxx-xxxx-xxxx-xxxxxxxxxxxx<br />
============================================<br />
{}</p></blockquote>
<h2> Basic authentication on boto for Route53 </h2>
<p>The following step is required for all boto operations with route53. In python terminal use the following commands:</p>
<blockquote><p>
>>> import boto<br />
>>> from boto import route53<br />
>>> key = ‘AAES5WCQQBW5XZ2DAA’<br />
>>> access = ‘DMJsjdlkr0OHnrwqEsGkksjweosbg/yeISOPEOdnsK’<br />
>>> route53 = Route53Connection(key, access)<br />
>>> results = route53.get_all_hosted_zones()<br />
>>> results<br />
{u&#8217;ListHostedZonesResponse&#8217;: {u&#8217;HostedZones&#8217;: [{u'CallerReference': u'6000r000-b00-0000-8000-46000000c', u'Config': {}, u'Id': u'/hostedzone/ZXXXXXXXXXXXXXX', u'Name': u'yourdomain.com.'}], u&#8217;IsTruncated&#8217;: u&#8217;false&#8217;, u&#8217;MaxItems&#8217;: u&#8217;100&#8242;}}
</p></blockquote>
<h2>Adding A record on Route53 with Boto</h2>
<blockquote><p>
>>> import boto<br />
>>> from boto.route53.record import ResourceRecordSets<br />
>>> conn = boto.connect_route53(key, access)<br />
>>> changes = ResourceRecordSets(conn, &#8220;ZXXXXXXXXXXXXXX&#8221;)<br />
>>> change = changes.add_change(&#8220;CREATE&#8221;, &#8220;yourdomainname.com&#8221;,&#8221;A&#8221;)<br />
>>> change.add_value(&#8220;45.34.22.455&#8243;) #your ip address<br />
>>> changes.commit()
</p></blockquote>
<h2>Adding CNAME on Route53 with Boto</h2>
<blockquote><p>
>>> import boto<br />
>>> from boto.route53.record import ResourceRecordSets<br />
>>> conn = boto.connect_route53(key, access)<br />
>>> changes = ResourceRecordSets(conn, &#8220;ZXXXXXXXXXXXXXX&#8221;)<br />
>>> change = changes.add_change(&#8220;CREATE&#8221;, &#8220;subdomain.yourdomainname.com&#8221;, &#8220;CNAME&#8221;)<br />
>>> change.add_value(&#8220;some_dns_name&#8221;)<br />
>>> changes.commit()
</p></blockquote>
<h2>Adding TXT Record on Route53 with Boto</h2>
<p>Note: All text records will require you to add strings as value. Note the extra quotes around the text value, else expect to see an error as below:</p>
<p>Invalid Resource Record: FATAL problem: InvalidTXTRDATA encountered at &#8220;\&#8221;v=spf1 ip4:64.64.9.245 a mx ~all\&#8221;</p>
<blockquote><p>
>>> import boto<br />
>>> from boto.route53.record import ResourceRecordSets<br />
>>> conn = boto.connect_route53(key, access)<br />
>>> changes = ResourceRecordSets(conn, &#8220;ZXXXXXXXXXXXXXX&#8221;)<br />
>>> change = changes.add_change(&#8220;CREATE&#8221;, &#8220;yourdomainname.com&#8221;, &#8220;TXT&#8221;)<br />
>>> change.add_value(&#8220;<strong>\&#8221;v=spf1 mx ptr include:mail and other text a ~all\&#8221;</strong>&#8220;)<br />
>>> changes.commit()</p></blockquote>
<h2>Deleting CNAME on Route53 with Boto</h2>
<blockquote><p>
>>> import boto<br />
>>> from boto.route53.record import ResourceRecordSets<br />
>>> conn = boto.connect_route53()<br />
>>> changes = ResourceRecordSets(conn, &#8220;ZXXXXXXXXXXXXXX&#8221;)<br />
>>> change = changes.add_change(&#8220;DELETE&#8221;, &#8220;subdomain.yourdomainname.com&#8221;, &#8220;CNAME&#8221;)<br />
>>> change.add_value(&#8220;some_dns_name&#8221;) #Note: This value has to match exactly with the record<br />
>>> changes.commit()
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://hackinghabits.com/2011/08/20/boto-for-amazon-route53/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Invalid shift value in prefixCoded string (is encoded value really a LONG?)</title>
		<link>http://hackinghabits.com/2011/08/20/invalid-shift-value-in-prefixcoded-string-is-encoded-value-really-a-long/</link>
		<comments>http://hackinghabits.com/2011/08/20/invalid-shift-value-in-prefixcoded-string-is-encoded-value-really-a-long/#comments</comments>
		<pubDate>Sat, 20 Aug 2011 21:39:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tips N Tricks]]></category>

		<guid isPermaLink="false">http://hackinghabits.com/?p=251</guid>
		<description><![CDATA[Spatial search on documents can be performed using solr and the jteam plugin. Jteam pdf documentation is clear and a good starter. After installing the plugin in solr and changing the required entries in solr.xml and solrconfig.xml, a spatial query resulted in the following error. HTTP ERROR: 500 Invalid shift value in prefixCoded string (is [...]]]></description>
			<content:encoded><![CDATA[<p>Spatial search on documents can be performed using solr and the  <a href="http://www.jteam.nl/news/spatialsolr">jteam</a> plugin. Jteam pdf documentation is clear and a good starter. </p>
<p>After installing the plugin in solr and changing the required entries in solr.xml and solrconfig.xml, a spatial query resulted in the following error.</p>
<blockquote><p>HTTP ERROR: 500</p>
<p>Invalid shift value in prefixCoded string (is encoded value really a LONG?)</p>
<p>java.lang.NumberFormatException: Invalid shift value in prefixCoded string (is encoded value really a LONG?)<br />
	at org.apache.lucene.util.NumericUtils.prefixCodedToLong(NumericUtils.java:206)<br />
	at org.apache.lucene.search.FieldCache$10.parseDouble(FieldCache.java:294)<br />
	at org.apache.lucene.search.FieldCacheImpl$DoubleCache.createValue(FieldCacheImpl.java:635)<br />
	at org.apache.lucene.search.FieldCacheImpl$Cache.get(FieldCacheImpl.java:224)<br />
	at org.apache.lucene.search.FieldCacheImpl.getDoubles(FieldCacheImpl.java:602)<br />
	at nl.jteam.search.solrext.spatial.lucene.LatLongLocationDataSetFactory.buildLocationDataSet(LatLongLocationDataSetFactory.java:35)<br />
	at nl.jteam.search.solrext.spatial.lucene.SpatialQuery$SpatialWeight.scorer(SpatialQuery.java:186)<br />
	at org.apache.lucene.search.BooleanQuery$BooleanWeight.scorer(BooleanQuery.java:297)</p></blockquote>
<p>The solution was to delete the data folder (aka the indexes) and index the data again. </p>
]]></content:encoded>
			<wfw:commentRss>http://hackinghabits.com/2011/08/20/invalid-shift-value-in-prefixcoded-string-is-encoded-value-really-a-long/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mozilla components</title>
		<link>http://hackinghabits.com/2010/12/15/mozilla-components/</link>
		<comments>http://hackinghabits.com/2010/12/15/mozilla-components/#comments</comments>
		<pubDate>Wed, 15 Dec 2010 05:31:04 +0000</pubDate>
		<dc:creator>madan</dc:creator>
				<category><![CDATA[firefox plugin development]]></category>
		<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://hackinghabits.com/?p=232</guid>
		<description><![CDATA[Mozilla products are built based on XPCOM, a cross platform component object model. To build a mozilla product, one can make use of already available components and build additional required components. What does this mean? Mozilla components represent callable modules which are exposed to the outer world through interfaces which are XPCOM compatible. Short example [...]]]></description>
			<content:encoded><![CDATA[<p>Mozilla products are built based on XPCOM, a cross platform component object model. To build a mozilla product, one can make use of already available components and build additional required components. What does this mean? <strong>Mozilla components</strong> represent callable modules which are exposed to the outer world through interfaces which are XPCOM compatible. </p>
<h2>Short example of mozilla components:</h2>
<p>For sake of argument, assume that there is no global scoped function called &#8220;alert()&#8221; in javascript which generates a popup message. The only way of creating a popup box is to access a <strong>mozilla component</strong> as below:</p>
<blockquote><p>var sample = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].<br />
<span style="padding-left:200px"></span>getService(Components.interfaces.nsIPromptService);<br />
			sample.alert(null, &#8220;Window Title&#8221;, &#8220;Alert Message&#8221;);	</p></blockquote>
<p>So in a world where &#8220;alert()&#8221; was never an openly callable function, mozilla components like the one mentioned above  which is aptly named as &#8220;prompt-service&#8221; expose functionalities that can be accessed from outside.</p>
<p>XPCOM was developed so that different components can be developed in different languages and can all be exposed to each other via common interfaces. Hence you can imagine developing mozilla components in Javascript, C++, python and other languages as long as they maintain XPCOM interfaces appropriately. XPCOM interfaces for mozilla components are based on IDL which is an interface description language. Learn more about <a href="http://www.mozilla.org/scriptable/xpidl/idl-authors-guide/rules.html">IDL here</a> . </p>
<p>If you want to know all the mozilla components available on your firefox, you can install the <a href="https://addons.mozilla.org/af/firefox/addon/7979/">XPCOM Viewer</a> plugin. The following image shows the mozilla components installed in my firefox installation. All these components expose functions that can be accessed as we did in the above example. Since it is cross platform you will be able to find ways to access them across many languages.</p>
<p><img src="/wp-content/uploads/2011/06/xpcomviewer.png" alt="Mozilla components in firefox" title="xpcomviewer" width="546" height="544" class="alignnone size-full wp-image-237" /></p>
]]></content:encoded>
			<wfw:commentRss>http://hackinghabits.com/2010/12/15/mozilla-components/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Memcache installation : understanding memcache</title>
		<link>http://hackinghabits.com/2010/12/08/memcache-installation-understanding-memcache/</link>
		<comments>http://hackinghabits.com/2010/12/08/memcache-installation-understanding-memcache/#comments</comments>
		<pubDate>Wed, 08 Dec 2010 05:17:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[memcache]]></category>
		<category><![CDATA[setup]]></category>

		<guid isPermaLink="false">http://hackinghabits.com/?p=214</guid>
		<description><![CDATA[In this article we will see a real short python memcache installation procedure on a ubuntu server. We will also look as understanding the functionality that memcache offers us by interacting with it. Short Memcache Tutorial Dynamic websites are those in which web pages are generated on the fly using some mainstream scripting languages. Unlike [...]]]></description>
			<content:encoded><![CDATA[<p>In this article we will see a real short python memcache installation procedure on a ubuntu server. We will also look as understanding the functionality that memcache offers us by interacting with it.</p>
<h2>Short Memcache Tutorial</h2>
<p>Dynamic websites are those  in which web pages are generated on the fly using some mainstream scripting<br />
languages. Unlike static html websites that do not change, dynamic websites are characterized by their ever changing &#8220;dynamic&#8221; content. Almost without doubt a dynamic website must use some kind of data storage to update its content over time. One of the simple cases is a sql server. When a high traffic dynamic website requires to load a popular page a million times, it is wasteful of resources to run similar data acquisition queries on the sql server. To help such situations, a caching mechanism can act as a blocking layer that can store information regarding a page without having to re-fetch it from the data store of the mysql server. Memcache server is one such caching application that help your applications store /  cache some information. Memcache is an in memory application which means that it stores the cached content in RAM. You will be able to  interface with memcache using telnet but  not quite practical for applications written in various languages to interact in that manner. Hence, most languages provide a wrapper that can act as in interface between your programming language and the memcache server.</p>
<p>Memcache has a simple interface which is basically a key value store. Let us consider a single web page as an item and the page url as a unique identifier to the page. Memcache can be easily imagined as a dictionary where the index is the url and the value is the content (html) of the page. Off course it need not work in the way that I just mentioned, but a way to think about it. Usually the keys are hashed to minimize conflicts.</p>
<p>Towards the end of this article we will see a way to interface python and memecache server.</p>
<h2>Memcache installation ubuntu:</h2>
<p>On an ubuntu box, memcache installation is easy.</p>
<blockquote><p>sudo apt-get install libmemcache-dev libmemcache0</p></blockquote>
<p>That is it ! Check if memcached is running by using</p>
<blockquote><p>ps aux | grep memcached</p></blockquote>
<p>To start memcached server, just go ahead and use the command (Note:- if you did not manually start memcache, find the memcache start command details using &#8220;ps aux | grep memcache&#8221;) :</p>
<blockquote><p>memcached -d -m 64 -p 11211 -u memcache -l 127.0.0.1</p>
<p>Options:<br />
-d runs the server as a daemon<br />
-m specifies the memory that memcache is allowed to use<br />
-p port to which memcache listens to<br />
-u user<br />
-l  hostname that would like to bind to (127.0.0.1 prevent access from outside your server)</p></blockquote>
<h2>What is happening now:</h2>
<p>After you have started memcache, you can interact with it in some nice different ways. Let us first interact with it through telnet. We gave the port number while startup so lets telnet to port 11211 as below</p>
<blockquote><p># telnet 127.0.0.1 11211</p>
<p>You should expect the following result :<br />
Trying 127.0.0.1&#8230;<br />
Connected to 127.0.0.1.<br />
Escape character is &#8216;^]&#8217;.<br />
|</p></blockquote>
<p>This essentially has setup an access to memcache  via  port 11211 which the memcache server is listening to. Type in your commands and hit enter to get a response form memcache. Find a list of valid <a href="http://hackinghabits.com/2010/12/08/memcache-commands/">memcache commands</a> to interact with it.</p>
<h2>How to store value in memcache</h2>
<p>If you had followed this far, you are currently at :</p>
<blockquote><p>Trying 127.0.0.1&#8230;<br />
Connected to 127.0.0.1.<br />
Escape character is &#8216;^]&#8217;.</p></blockquote>
<p>Type the set command which has the following syntax:</p>
<blockquote><p>set  &lt;keyname&gt; &lt;flag&gt; &lt;time until expiry of data&gt; &lt;bytes of data you will store&gt;</p>
<p>Trying 127.0.0.1&#8230;<br />
Connected to 127.0.0.1.<br />
Escape character is &#8216;^]&#8217;.<br />
set testkey 0 120 4  (press enter and in the next line provide the 4 byte data)<br />
data<br />
STORED     (Response from memcache. You just stored &#8220;data&#8221; to key &#8220;testkey&#8221;)</p></blockquote>
<h2>How to get value from memcache</h2>
<p>Assuming that you had already stored a value as mentioned above, access the stored data using the get command which has the following syntax:</p>
<blockquote><p>get &lt;keyname&gt;</p>
<p>The following is the result of the issued command:<br />
Trying 127.0.0.1&#8230;<br />
Connected to 127.0.0.1.<br />
Escape character is &#8216;^]&#8217;.<br />
VALUE testkey 0 4<br />
data (You have got back the value  that you had stored !!)<br />
END</p></blockquote>
<p>Make sure you do the set and the get within a span of 120 second as you have asked memcache to store the key value pair just for 120 seconds in the set command. Increase that to a really long time as desired. We have come far in understanding the functioning of memcache server and I hope it helped.</p>
]]></content:encoded>
			<wfw:commentRss>http://hackinghabits.com/2010/12/08/memcache-installation-understanding-memcache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Memcache commands</title>
		<link>http://hackinghabits.com/2010/12/08/memcache-commands/</link>
		<comments>http://hackinghabits.com/2010/12/08/memcache-commands/#comments</comments>
		<pubDate>Wed, 08 Dec 2010 04:55:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[memcache]]></category>

		<guid isPermaLink="false">http://hackinghabits.com/?p=215</guid>
		<description><![CDATA[The following are commands that you can issue to memcache while connected to it using telent. Command Description Example get Reads a value get keyname set Set a key unconditionally set keyname 0 120 4 add Add a new key add keyname 0 120 4 replace Overwrite existing key replace key 0 120 4 append [...]]]></description>
			<content:encoded><![CDATA[<p>The following are commands that you can issue to memcache while connected to it using telent.</p>
<table border="1">
<tbody>
<tr>
<th>Command</th>
<th>Description</th>
<th>Example</th>
</tr>
<tr>
<td>get</td>
<td>Reads a value</td>
<td>get keyname</td>
</tr>
<tr>
<td>set</td>
<td>Set a key unconditionally</td>
<td>set keyname 0 120 4</td>
</tr>
<tr>
<td>add</td>
<td>Add a new key</td>
<td>add keyname 0 120 4</td>
</tr>
<tr>
<td>replace</td>
<td>Overwrite existing key</td>
<td>replace key 0 120 4</td>
</tr>
<tr>
<td>append</td>
<td>Append data to existing key</td>
<td>append key 0 120 30</td>
</tr>
<tr>
<td>prepend</td>
<td>Prepend data to existing key</td>
<td>prepend key 0 120 30</td>
</tr>
<tr>
<td>incr</td>
<td>Increments numerical key value by given number</td>
<td>incr keyname 2</td>
</tr>
<tr>
<td>decr</td>
<td>Decrements numerical key value by given number</td>
<td>decr keyname 5</td>
</tr>
<tr>
<td>delete</td>
<td>Deletes an existing key</td>
<td>delete keyname</td>
</tr>
<tr>
<td rowspan="2">flush_all</td>
<td>Invalidate specific items immediately</td>
<td>flush_all</td>
</tr>
<tr>
<td>Invalidate all items in n seconds</td>
<td>flush_all 900</td>
</tr>
<tr>
<td rowspan="7">stats</td>
<td>Prints general statistics</td>
<td>stats</td>
</tr>
<tr>
<td>Prints memory statistics</td>
<td>stats slabs</td>
</tr>
<tr>
<td>Prints memory statistics</td>
<td>stats malloc</td>
</tr>
<tr>
<td>Print higher level allocation statistics</td>
<td>stats items</td>
</tr>
<tr>
<td></td>
<td>stats detail</td>
</tr>
<tr>
<td></td>
<td>stats sizes</td>
</tr>
<tr>
<td>Resets statistics</td>
<td>stats reset</td>
</tr>
<tr>
<td>version</td>
<td>Prints server version.</td>
<td>version</td>
</tr>
<tr>
<td>verbosity</td>
<td>Increases log level</td>
<td>verbosity</td>
</tr>
<tr>
<td>quit</td>
<td>Terminate telnet session</td>
<td>quit</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://hackinghabits.com/2010/12/08/memcache-commands/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

