<?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>Everything&#039;s Beta</title>
	<atom:link href="http://blog.everythings-beta.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://blog.everythings-beta.com</link>
	<description>things I don&#039;t get to do at work :)</description>
	<lastBuildDate>Tue, 27 Jul 2010 03:39:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>My phone number is pretty awesome</title>
		<link>http://blog.everythings-beta.com/?p=493</link>
		<comments>http://blog.everythings-beta.com/?p=493#comments</comments>
		<pubDate>Tue, 27 Jul 2010 03:39:08 +0000</pubDate>
		<dc:creator>srijak</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.everythings-beta.com/?p=493</guid>
		<description><![CDATA[If you take f(n) to be a function that gives you the nth prime, ( f ∘ f ∘ f )  (141)  followed by the largest fermat prime you can get your hands on is my number]]></description>
			<content:encoded><![CDATA[<p><br/></p>
<p>If you take f(n) to be a function that gives you the nth prime,<br />
( f ∘ f ∘ f )  (141)  followed by the largest fermat prime you can get your hands on is my number <img src='http://blog.everythings-beta.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><br/><br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.everythings-beta.com/?feed=rss2&amp;p=493</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Quick starting Scalatra or In which I discover Scalatra and sbt</title>
		<link>http://blog.everythings-beta.com/?p=430</link>
		<comments>http://blog.everythings-beta.com/?p=430#comments</comments>
		<pubDate>Sun, 18 Jul 2010 21:43:23 +0000</pubDate>
		<dc:creator>srijak</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://blog.everythings-beta.com/?p=430</guid>
		<description><![CDATA[Over the weekend, I was researching various frameworks for implementing a REST API. Although I had already started the implementation using Tornado, I wanted to see what else was out there. And am I glad I looked. I discovered Scalatra which seems to be exactly what I was looking for; a lightweight, sinatra-esque way to [...]]]></description>
			<content:encoded><![CDATA[<p>Over the weekend, I was researching various frameworks for implementing a REST API. Although I had already started the implementation using <a href="tornadoweb.org">Tornado</a>, I wanted to see what else was out there. </p>
<p>
And am I glad I looked. I discovered <a href="http://github.com/alandipert/step"> Scalatra</a> which seems to be exactly what I was looking for; a lightweight, sinatra-esque way to map URLs to actions that easily lends itself to testing.  I especially like the uber-readable way the tests are written. </p>
<p>Who wouldn&#8217;t want to write tests like this?</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #008000; font-style: italic;">// taken from http://github.com/alandipert/step</span>
<span style="color: #0000ff; font-weight: bold;">class</span> MyScalatraServletTests <span style="color: #0000ff; font-weight: bold;">extends</span> FunSuite <span style="color: #0000ff; font-weight: bold;">with</span> ShouldMatchers <span style="color: #0000ff; font-weight: bold;">with</span> ScalatraTests <span style="color: #F78811;">&#123;</span>
  <span style="color: #008000; font-style: italic;">// `MyScalatraServlet` is your app which extends ScalatraServlet</span>
  route<span style="color: #F78811;">&#40;</span>classOf<span style="color: #F78811;">&#91;</span>MyScalatraServlet<span style="color: #F78811;">&#93;</span>, <span style="color: #6666FF;">&quot;/*&quot;</span><span style="color: #F78811;">&#41;</span>
&nbsp;
  test<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;simple get&quot;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
    get<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;/path/to/something&quot;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
      status should equal <span style="color: #F78811;">&#40;</span><span style="color: #F78811;">200</span><span style="color: #F78811;">&#41;</span>
      body should include <span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;hi!&quot;</span><span style="color: #F78811;">&#41;</span>
    <span style="color: #F78811;">&#125;</span>
  <span style="color: #F78811;">&#125;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

<p>I cloned the repo, ran the examples and decided my search had ended.</p>
<p>However, while running the example was easy enough, I wasn&#8217;t sure of how to get started with an actual app. It looked especially cryptic since I haven&#8217;t ever used maven or sbt. I even  considered bailing on scalatra for the well-known shores of tornadoweb. But, since I recently started working with Java at work, I decided to stick it out.</p>
<p>I&#8217;m glad I did because sbt is a pleasure to use, especially if you take the time to RTFM.</p>
<p>Anyway, here are the basic steps to help cut down the 0 to 60 time when starting scalatra <img src='http://blog.everythings-beta.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
</p>
<p>
<strong>Pre-reqs:</strong><br />
Install java, I have java 1.6.<br />
Setup sbt as per <a href="http://code.google.com/p/simple-build-tool/wiki/Setup">these instructions</a>.
</p>
<p>Good, now we are ready to start.<br />
Create a new sbt project &#8220;HelloScalatra&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> HelloScalatra
 <span style="color: #7a0874; font-weight: bold;">cd</span> HelloScalatra
 sbt
<span style="color: #666666; font-style: italic;"># fill out the other inputs as you want but make sure you enter 2.8.0 as scala version.</span></pre></div></div>

<p>Create a project definition for sbt and save it under project/build. Here&#8217;s a barebones one, refer to <a href="http://code.google.com/p/simple-build-tool/wiki/BuildConfiguration"> the docs</a> if you want more info on creating sbt build configs.</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #008000; font-style: italic;">// save as project/build/HelloScalatraBuild.scala</span>
<span style="color: #0000ff; font-weight: bold;">import</span> sbt.<span style="color: #000080;">_</span>
<span style="color: #0000ff; font-weight: bold;">class</span> HelloScalatraBuild<span style="color: #F78811;">&#40;</span>info<span style="color: #000080;">:</span> ProjectInfo<span style="color: #F78811;">&#41;</span> <span style="color: #0000ff; font-weight: bold;">extends</span> DefaultWebProject<span style="color: #F78811;">&#40;</span>info<span style="color: #F78811;">&#41;</span>
<span style="color: #F78811;">&#123;</span>
  <span style="color: #008000; font-style: italic;">// scalatra</span>
  <span style="color: #0000ff; font-weight: bold;">val</span> sonatypeNexusSnapshots <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;Sonatype Nexus Snapshots&quot;</span> at
<span style="color: #6666FF;">&quot;https://oss.sonatype.org/content/repositories/snapshots&quot;</span>
  <span style="color: #0000ff; font-weight: bold;">val</span> sonatypeNexusReleases <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;Sonatype Nexus Releases&quot;</span> at
<span style="color: #6666FF;">&quot;https://oss.sonatype.org/content/repositories/releases&quot;</span>
  <span style="color: #0000ff; font-weight: bold;">val</span> scalatra <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;org.scalatra&quot;</span> <span style="color: #000080;">%%</span> <span style="color: #6666FF;">&quot;scalatra&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;2.0.0-SNAPSHOT&quot;</span>
&nbsp;
  <span style="color: #008000; font-style: italic;">// jetty</span>
  <span style="color: #0000ff; font-weight: bold;">val</span> jetty6 <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;org.mortbay.jetty&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;jetty&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;6.1.22&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;test&quot;</span>
  <span style="color: #0000ff; font-weight: bold;">val</span> servletApi <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;org.mortbay.jetty&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;servlet-api&quot;</span> <span style="color: #000080;">%</span>
<span style="color: #6666FF;">&quot;2.5-20081211&quot;</span> <span style="color: #000080;">%</span> <span style="color: #6666FF;">&quot;provided&quot;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

<p>Tell sbt to account for the new dependencies:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#from project root</span>
sbt update</pre></div></div>

<p>We have the basic dependencies taken care of, so let&#8217;s create our class that will serve requests.  Create &#8220;HelloScalatra.scala&#8221; under src/main/scala/com/helloscalatra with the following content:</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #008000; font-style: italic;">// save as src/main/scala/com/helloscalatra/HelloScalatra.scala</span>
<span style="color: #0000ff; font-weight: bold;">package</span> com.<span style="color: #000000;">helloscalatra</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;">import</span> org.<span style="color: #000000;">scalatra</span>.<span style="color: #000080;">_</span>
&nbsp;
<span style="color: #0000ff; font-weight: bold;">class</span> HelloScalatra <span style="color: #0000ff; font-weight: bold;">extends</span> ScalatraServlet <span style="color: #0000ff; font-weight: bold;">with</span> UrlSupport <span style="color: #F78811;">&#123;</span>
&nbsp;
 before <span style="color: #F78811;">&#123;</span>
   contentType <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;text/html&quot;</span>
 <span style="color: #F78811;">&#125;</span>
&nbsp;
 get<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;/&quot;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
   <span style="color: #000080;">&lt;</span>html<span style="color: #000080;">&gt;</span>
     <span style="color: #000080;">&lt;</span>head<span style="color: #000080;">&gt;</span>
       <span style="color: #000080;">&lt;</span>title<span style="color: #000080;">&gt;</span> My first scalatra webapp<span style="color: #000080;">&lt;</span>/title<span style="color: #000080;">&gt;</span>
     <span style="color: #000080;">&lt;</span>/head<span style="color: #000080;">&gt;</span>
     <span style="color: #000080;">&lt;</span>body<span style="color: #000080;">&gt;</span>
       <span style="color: #000080;">&lt;</span>h1<span style="color: #000080;">&gt;</span> Hello Scalatra <span style="color: #000080;">&lt;</span>/h1<span style="color: #000080;">&gt;</span>
     <span style="color: #000080;">&lt;</span>/body<span style="color: #000080;">&gt;</span>
   <span style="color: #000080;">&lt;</span>/html<span style="color: #000080;">&gt;</span>
 <span style="color: #F78811;">&#125;</span>
&nbsp;
 <span style="color: #0000ff; font-weight: bold;">protected</span> <span style="color: #0000ff; font-weight: bold;">def</span> contextPath <span style="color: #000080;">=</span> request.<span style="color: #000000;">getContextPath</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

<p>The last thing we need to do is setup web.xml to tell jetty what to do:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">// save as src/main/webapp/WEB-INF/web.xml
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #00bbdd;">&lt;!DOCTYPE web-app</span>
<span style="color: #00bbdd;"> PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN&quot;</span>
<span style="color: #00bbdd;"> &quot;http://java.sun.com/j2ee/dtds/web-app_2_2.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>HelloScalatra<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.helloscalatra.HelloScalatra<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>HelloScalatra<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
 <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Great! We should be good to go <img src='http://blog.everythings-beta.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
Go to project root and startup the sbt console:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">sbt</pre></div></div>

<p>and start jetty:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span>jetty-run</pre></div></div>

<p>TADA!</p>
<p>Navigate over to <a href="http://localhost:8080"> localhost:8080 </a> to see the webapp in action.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.everythings-beta.com/?feed=rss2&amp;p=430</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing java in ubuntu lucid</title>
		<link>http://blog.everythings-beta.com/?p=425</link>
		<comments>http://blog.everythings-beta.com/?p=425#comments</comments>
		<pubDate>Sun, 20 Jun 2010 14:11:11 +0000</pubDate>
		<dc:creator>srijak</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.everythings-beta.com/?p=425</guid>
		<description><![CDATA[Hopefully this saves someone 10 mins: sun java was moved in the partner repos for lucid. So, you&#8217;ll need to add deb http://archive.canonical.com/ubuntu lucid partner to your sources: sudo echo &#34;deb http://archive.canonical.com/ubuntu lucid partner&#34; &#62;&#62; /etc/apt/sources.list then update and install: sudo apt-get update sudo apt-get install sun-java6-jre sun-java6-jdk]]></description>
			<content:encoded><![CDATA[<p>Hopefully this saves someone 10 mins:</p>
<p>sun java was moved in the partner repos for lucid.<br />
So, you&#8217;ll need to add deb http://archive.canonical.com/ubuntu lucid partner to your sources:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #7a0874; font-weight: bold;">echo</span>  <span style="color: #ff0000;">&quot;deb http://archive.canonical.com/ubuntu lucid partner&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apt<span style="color: #000000; font-weight: bold;">/</span>sources.list</pre></div></div>

<p>then update and install:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> update
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> sun-java6-jre sun-java6-jdk</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.everythings-beta.com/?feed=rss2&amp;p=425</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PuSH Support follow up</title>
		<link>http://blog.everythings-beta.com/?p=412</link>
		<comments>http://blog.everythings-beta.com/?p=412#comments</comments>
		<pubDate>Tue, 11 May 2010 06:34:07 +0000</pubDate>
		<dc:creator>srijak</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.everythings-beta.com/?p=412</guid>
		<description><![CDATA[Just a quick follow up from the last post. I&#8217;ve just added bots that send you updates via email or jabber. Go to rackjam.codereviewr.com to check it out. It&#8217;s a little rough around the edges in terms of UX but it gets the job done. And, although there were some constraints that will probably cause [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick follow up from the last post.</p>
<p>I&#8217;ve just added bots that send you updates via email or jabber. Go to <a href="http://rackjam.codereviewr.com">rackjam.codereviewr.com</a> to check it out.</p>
<p> It&#8217;s a little rough around the edges in terms of UX but it gets the job done. And, although there were some constraints that will probably cause me to move, all this was ridiculously easy thanks to the google app engine. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.everythings-beta.com/?feed=rss2&amp;p=412</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Release &amp; iterate and codereviewr PuSH support</title>
		<link>http://blog.everythings-beta.com/?p=391</link>
		<comments>http://blog.everythings-beta.com/?p=391#comments</comments>
		<pubDate>Mon, 10 May 2010 02:53:23 +0000</pubDate>
		<dc:creator>srijak</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[no-code]]></category>
		<category><![CDATA[codereviewr]]></category>

		<guid isPermaLink="false">http://blog.everythings-beta.com/?p=391</guid>
		<description><![CDATA[I have recently been working on CodeReviewr. It&#8217;s motivated by the need to have a place to easily stick up code and discuss it with minimum hassle. I have rewritten the code numerous time using various platforms(from mochiweb to node.js to tornadoweb) towards multiple goals (collaborative coding, reviews, etcs) as I succumbed to feature creep, [...]]]></description>
			<content:encoded><![CDATA[<p>I have recently been working on <a href="http://codereviewr.com">CodeReviewr</a>. It&#8217;s motivated by the need to have a place to easily stick up code and discuss it with minimum hassle. I have rewritten the code numerous time using various platforms(from mochiweb to node.js to tornadoweb) towards multiple goals (collaborative coding, reviews, etcs) as I succumbed to feature creep, premature optimization, not built here, et al.</p>
<p>Anyway, a couple of weekends back I decided to just deploy it so that we could use it for <a href="rackjam.codereviewr.com">rackjam</a>. I don&#8217;t consider it even close to finished. For eg, you have to refresh in order to see comments you just made (ack), and there is no documentation on how to use it. But, it&#8217;s finished enough. I decided to stop trying to release something perfect and go with the release and iterate model. So, I rounded off the minimal feature set and let dog fooding sort out the priorities.</p>
<p>A few weekends later, I am still adding features. BUT, these are user driven requirements. And I have a website that people are using <img src='http://blog.everythings-beta.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   It&#8217;s surprisingly good motivation to keep trying to make something better when you see people actually using it. Driven by feedback, I have added support for multiple versions, diffs between versions, better diff visualization, ability to download raw files, free private domain support etcs etcs. Funnily enough, I still haven&#8217;t been asked to fix commenting to address the refresh annoyance! More than anything else, this has taught me the importance of release+iterate as opposed to trying to imagine complete use cases. Of course, I will throw in real time comment updates in there, but not before the core featureset.</p>
<p>But this blog post isn&#8217;t only about extolling the virtues of MVP, release+iterate, dog-fooding blah blah blah. It&#8217;s about a new feature I have been asked to add; the ability to get emails when a review or set of reviews you are interested in changes. Before beginning this task, I wanted to make sure that sending subscribers updates should be as painless and decoupled from the current code as possible. The web app really shouldn&#8217;t care who gets updated and how. And anyway, I definitely don&#8217;t want the webapp sending email. So, my ideal solution is 1 line of code fire off an event so w/e subsystem or subsystems are in charge of updates inform interested parties as (and when) they see fit. I also wanted the update management subsystems to be as pluggable as possible. The first thing that I thought of was a message queue(à la <a href="http://kr.github.com/beanstalkd/"> beanstalkd</a>) where I push out messages whenever an update occurs. Interested consumers could then process the message and send updates to whomever and however they wanted.  All the logic in handling the complexity in delivering the message would be solely in the consumers, the webapp fires [off an event] and forgets. Sounds pretty perfect. Could we do better? Enter  <a href="http://code.google.com/apis/pubsubhubbub/"> PubSubHubBub.</a> (I&#8217;m going to assume you know about it, or will do the required research to get up to speed if you are interested). After some prototyping I decided to go with it because</p>
<ul>
<li>It met the 2 requirements I set forth.</li>
<li>It&#8217;s easy.</li>
<li>And, it allows me to have an interim solution for free that<br />
was good enough (rss feeds).</li>
</ul>
<p>So after adding rss feeds to reviews (append .rss to the url) and subdomains (/feed.rss), creating a <a href="codereviewr.superfeedr.com"> hub at superfeedr</a>, and adding the 1 line of code to ping the hub when there is an update, I am 100% there w.r.t providing users with a way to receive updates and 80% there w.r.t email alerts. All I have to do now is to write bots that will subscribe to the hub and push out notifications through w/e medium people want. The best thing about this is CodeReviewr is now PubSubHubBub capable so anyone else can subscribe to the hub right now if they don&#8217;t want to wait for me to implement the bots they want <img src='http://blog.everythings-beta.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.everythings-beta.com/?feed=rss2&amp;p=391</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How I stopped worrying and started loving my iPad</title>
		<link>http://blog.everythings-beta.com/?p=374</link>
		<comments>http://blog.everythings-beta.com/?p=374#comments</comments>
		<pubDate>Mon, 05 Apr 2010 03:46:45 +0000</pubDate>
		<dc:creator>srijak</dc:creator>
				<category><![CDATA[no-code]]></category>
		<category><![CDATA[ipad]]></category>

		<guid isPermaLink="false">http://blog.everythings-beta.com/?p=374</guid>
		<description><![CDATA[I got a nice little surprise yesterday from my girlfriend; a 32GB iPad. And, now that I&#8217;ve played with it, I think I understand why it&#8217;s such a great device. Yeah, I know, it doesn&#8217;t have X amount of RAM, Y input ports, and is a closed system etcs. I, too, scoffed at this &#8220;crippled&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>I got a nice little surprise yesterday from my girlfriend; a 32GB iPad. And, now that I&#8217;ve played with it, I think I understand why it&#8217;s such a great device. Yeah, I know, it doesn&#8217;t have X amount of RAM, Y input ports, and is a closed system etcs. I, too, scoffed at this &#8220;crippled&#8221; device and bemoaned various things missing that, if only they were present, would make it BE-AWESOME.</p>
<p>But, after owning it for a day+ish, I think I get where I was wrong. The reason I, and many others, get mired in these comparisons is because we think that the iPad is meant to be a smaller laptop. It&#8217;s not. Whereas, on a laptop you can do both content creation and consumption, the iPad is primarily a<strong> content consumption device</strong>; you can watch movies, play games, listen to music, read books, but you really can&#8217;t edit or create anything of the sort.</p>
<p><strong>And that&#8217;s perfectly fine</strong>. Think of it as a TV on steroids, rather than a downsized laptop. For lots of people, especially during their personal time, content generation really isn&#8217;t what they spend time doing. Despite this, the average computer is designed more for content generation than consumption.</p>
<p>If you think you are primarily a producer rather than a consumer, you may be surprised. I know I was. I went through the entire weekend, reading books, checking email etc. on my new iPad without missing my laptop in the least. Yeah, I need my laptop to code and I could never be without one, but the iPad fills a lot of gaps I lug my laptop around for.</p>
<p>A side effect of having a consumption only device is that now I can manage my time better. While I am on my laptop, I may be on hacker news or reddit for hours before realizing how much time I have wasted. However, by restricting the consumption activities to my iPad and productive ones to my laptop, I find it a lot easier to get more done <img src='http://blog.everythings-beta.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><b>TL;DR:</b> If you don&#8217;t think the iPad is great, then you probably don&#8217;t get it. You may need to get <a href="http://store.apple.com/us/browse/home/shop_ipad/family/ipad?mco=OTY2ODA0NQ">it</a> to get it.</p>
<p><br/><br />
P.S: No, I dont think I am suffering from the Stockholm syndrome.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.everythings-beta.com/?feed=rss2&amp;p=374</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get updates when your server&#8217;s ip changes</title>
		<link>http://blog.everythings-beta.com/?p=349</link>
		<comments>http://blog.everythings-beta.com/?p=349#comments</comments>
		<pubDate>Thu, 25 Feb 2010 04:18:48 +0000</pubDate>
		<dc:creator>srijak</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[gae]]></category>
		<category><![CDATA[kvstore]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blog.everythings-beta.com/?p=349</guid>
		<description><![CDATA[It&#8217;s a simple problem; I want to get updates when my home server&#8217;s ip address changes. It&#8217;s such a simple and pervasive problem that I&#8217;m sure there are loads of solutions out there. But, I figured it would be faster/easier to roll my own rather than evaluate+integrate w/e else is out there. My first instinct [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a simple problem; I want to get updates when my home server&#8217;s ip address changes. It&#8217;s such a simple and pervasive problem that I&#8217;m sure there are loads of solutions out there. But, I figured it would be faster/easier to roll my own rather than evaluate+integrate w/e else is out there.<br />
My first instinct at a solution comprised of 2 parts:</p>
<ol>
<li>Poll for changes to self.ip</li>
<li>Publish updated ip using/to w/e</li>
</ol>
<p>Let&#8217;s tackle part1. The main question here is how the server should get its external ip. The first thing that came to mind is a web page that echoes the visitor&#8217;s ip. So I wrote a simple <a href="http://my-ipaddr.appspot.com/">Google appengine  app</a> that echoes your ipv4 address when you hit it. My script on the server GETs its external ip by hitting http://my-ipaddr.appspot.com/ and if its changed publishes it using the passed-in function. Here&#8217;s the code:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># ipwatcher.py</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib2</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">socket</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
&nbsp;
root_url = <span style="color: #483d8b;">'http://my-ipaddr.appspot.com'</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> get_ip<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    ip = <span style="color: #dc143c;">urllib2</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>root_url<span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">try</span>:
        <span style="color: #dc143c;">socket</span>.<span style="color: black;">inet_aton</span><span style="color: black;">&#40;</span>ip<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> ip
    <span style="color: #ff7700;font-weight:bold;">except</span> <span style="color: #dc143c;">socket</span>.<span style="color: black;">error</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">None</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> watch<span style="color: black;">&#40;</span>publisher<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">callable</span><span style="color: black;">&#40;</span>publisher<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">Exception</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'The publisher needs to be a callable function'</span><span style="color: black;">&#41;</span>
&nbsp;
    last_ip = <span style="color: #008000;">None</span>
    <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #ff4500;">1</span>:
        current_ip = get_ip<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> current_ip <span style="color: #66cc66;">!</span>= last_ip:
            publisher<span style="color: black;">&#40;</span>current_ip<span style="color: black;">&#41;</span>
            last_ip = current_ip
&nbsp;
        <span style="color: #dc143c;">time</span>.<span style="color: black;">sleep</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">5</span><span style="color: #66cc66;">*</span><span style="color: #ff4500;">60</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> publish<span style="color: black;">&#40;</span>ip<span style="color: black;">&#41;</span>:
    <span style="color: #808080; font-style: italic;"># publish however</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> ip
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
    watch<span style="color: black;">&#40;</span>publish<span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;"># google app engine part</span>
<span style="color: #808080; font-style: italic;"># simpler than simple. It's just here for completeness</span>
<span style="color: #ff7700;font-weight:bold;">from</span> google.<span style="color: black;">appengine</span>.<span style="color: black;">ext</span> <span style="color: #ff7700;font-weight:bold;">import</span> webapp
<span style="color: #ff7700;font-weight:bold;">from</span> google.<span style="color: black;">appengine</span>.<span style="color: black;">ext</span>.<span style="color: black;">webapp</span>.<span style="color: black;">util</span> <span style="color: #ff7700;font-weight:bold;">import</span> run_wsgi_app
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> MainPage<span style="color: black;">&#40;</span>webapp.<span style="color: black;">RequestHandler</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> get<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># echo user ip</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">headers</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'Content-Type'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'text/plain'</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">out</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">remote_addr</span><span style="color: black;">&#41;</span>
&nbsp;
application = webapp.<span style="color: black;">WSGIApplication</span><span style="color: black;">&#40;</span>
                                     <span style="color: black;">&#91;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'/'</span>, MainPage<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>,
                                     debug=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    run_wsgi_app<span style="color: black;">&#40;</span>application<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Yeah, it&#8217;s crummy that I do GET requests every 5 minutes, but with the <a href="http://code.google.com/appengine/docs/quotas.html#Requests">GAE cap at 500requests/s</a> I&#8217;m not too worried yet. I don&#8217;t know if there is a better way to get the external IP, but as this works and it&#8217;s a means to an end, I&#8217;m going to resist getting distracted.</p>
<p>So, part1 done with no sweat. Let&#8217;s move on to part2 where we actually publish the ip. My first instinct was just to use email. But I get too many emails anyway. Second I thought of scp or ftp to push the ip out. Meh. Been there done that.</p>
<p>Since I have something running on GAE, why not use it? Let&#8217;s do it.<br />
GAE&#8217;s datastore makes it brain dead easy way to persist data. We could just do this:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">&nbsp;
name = <span style="color: #483d8b;">&quot;my-ip&quot;</span>
<span style="color: #ff7700;font-weight:bold;">class</span> IpAddress<span style="color: black;">&#40;</span>db.<span style="color: black;">Model</span><span style="color: black;">&#41;</span>:
    ip = db.<span style="color: black;">StringProperty</span><span style="color: black;">&#40;</span>required=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
    name =  db.<span style="color: black;">StringProperty</span><span style="color: black;">&#40;</span>required=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> MainPage<span style="color: black;">&#40;</span>webapp.<span style="color: black;">RequestHandler</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> get<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># echo user ip</span>
        ip = IpAddress.<span style="color: black;">gql</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;where name = :1&quot;</span>, name<span style="color: black;">&#41;</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> kv:
           ip = IpAddress<span style="color: black;">&#40;</span>ip = <span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">remote_addr</span>, name = name<span style="color: black;">&#41;</span>
           ip.<span style="color: black;">put</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> 
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            ip.<span style="color: black;">ip</span> =  <span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">remote_addr</span>
            ip.<span style="color: black;">put</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">headers</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'Content-Type'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'text/plain'</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">out</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>ip.<span style="color: black;">ip</span><span style="color: black;">&#41;</span></pre></div></div>

<p>This would probably work just fine. At least until random people/bots start hitting it. But, with maybe a hundred views a week on my blog, I don&#8217;t forsee too many people hitting the random appspot site.</p>
<p>However, since I am playing around with the GAE, might as well make it a little more interesting. Let&#8217;s try to make a simple key value store.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> KeyValue<span style="color: black;">&#40;</span>db.<span style="color: black;">Model</span><span style="color: black;">&#41;</span>:
    name = db.<span style="color: black;">StringProperty</span><span style="color: black;">&#40;</span>required=<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>
    passwd = db.<span style="color: black;">StringProperty</span><span style="color: black;">&#40;</span>required=<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>
    value = db.<span style="color: black;">TextProperty</span><span style="color: black;">&#40;</span>required=<span style="color: #008000;">False</span><span style="color: black;">&#41;</span>
    modified = db.<span style="color: black;">DateProperty</span><span style="color: black;">&#40;</span>auto_now=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span></pre></div></div>

<p>The password field is there just so random people who guess a key wont be able to edit the data. Yup, it&#8217;s not encrypted. Why? Because I already know the password of everyone who&#8217;s going to use it (me <img src='http://blog.everythings-beta.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> )<br />
If you are dying to use it and don&#8217;t want me to see your password, let me know and I can hash it or something.</p>
<p>Anyway, adding simple CRUD is easy too:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> KVStoreUpdate<span style="color: black;">&#40;</span>webapp.<span style="color: black;">RequestHandler</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> post<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># post to an existing key</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">headers</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'Content-Type'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'text/plain'</span>
        <span style="color: black;">&#40;</span>name, passwd<span style="color: black;">&#41;</span> =  <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'name'</span><span style="color: black;">&#41;</span>, <span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'passwd'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        content = <span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'content'</span><span style="color: black;">&#41;</span>
        kv = KeyValue.<span style="color: black;">gql</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;where name = :1 and passwd = :2&quot;</span>, name, passwd<span style="color: black;">&#41;</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> kv:
            <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">out</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'-1'</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            kv.<span style="color: black;">value</span> = content
            kv.<span style="color: black;">put</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">out</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>kv.<span style="color: black;">name</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> get_name_passwd<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, request<span style="color: black;">&#41;</span>:
       <span style="color: #ff7700;font-weight:bold;">return</span> 
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> KVStoreCreate<span style="color: black;">&#40;</span>webapp.<span style="color: black;">RequestHandler</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> post<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># reserve a new key or confirm old key.</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">headers</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'Content-Type'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'text/plain'</span>
        <span style="color: black;">&#40;</span>name, passwd<span style="color: black;">&#41;</span> =  <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'name'</span><span style="color: black;">&#41;</span>, <span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'passwd'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
        kv = KeyValue.<span style="color: black;">gql</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;where name = :1&quot;</span>, name<span style="color: black;">&#41;</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> kv:
            newKv = KeyValue <span style="color: black;">&#40;</span>name = name, passwd = passwd<span style="color: black;">&#41;</span>
            newKv.<span style="color: black;">put</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">out</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>name<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> kv.<span style="color: black;">passwd</span> == passwd:
            <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">out</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>name<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">out</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'-1'</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> KVStoreRead<span style="color: black;">&#40;</span>webapp.<span style="color: black;">RequestHandler</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> post<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># return stored value for the given key</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">headers</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'Content-Type'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'text/plain'</span>
        <span style="color: black;">&#40;</span>name, passwd<span style="color: black;">&#41;</span> =  <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'name'</span><span style="color: black;">&#41;</span>, <span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'passwd'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
        kv = KeyValue.<span style="color: black;">gql</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;where name = :1 and passwd = :2&quot;</span>, name, passwd<span style="color: black;">&#41;</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> kv:
            <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">out</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'-1'</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">out</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>kv.<span style="color: black;">value</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> KVStoreDelete<span style="color: black;">&#40;</span>webapp.<span style="color: black;">RequestHandler</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> post<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># delete kv </span>
        <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">headers</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'Content-Type'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'text/plain'</span>
        <span style="color: black;">&#40;</span>name, passwd<span style="color: black;">&#41;</span> =  <span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'name'</span><span style="color: black;">&#41;</span>, <span style="color: #008000;">self</span>.<span style="color: black;">request</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'passwd'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
        kv = KeyValue.<span style="color: black;">gql</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;where name = :1 and passwd = :2&quot;</span>, name, passwd<span style="color: black;">&#41;</span>.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> kv:
            <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">out</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'-1'</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">else</span>:
            kv.<span style="color: black;">delete</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">response</span>.<span style="color: black;">out</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>name<span style="color: black;">&#41;</span></pre></div></div>

<p>Now all we need is the client code:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib2</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">random</span> 
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">string</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># inbox_id is the just the key. I was going to have versioning + </span>
<span style="color: #808080; font-style: italic;"># addressing but decided not to since it was starting to look</span>
<span style="color: #808080; font-style: italic;"># like a hybrid of a queuing system and a key value store.</span>
<span style="color: #ff7700;font-weight:bold;">class</span> KeyValuePublisher:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, inbox_id, passwd, url<span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">inbox_id</span> = inbox_id
        <span style="color: #008000;">self</span>.<span style="color: black;">passwd</span> = passwd
        <span style="color: #008000;">self</span>.<span style="color: black;">url</span> = url
        <span style="color: #008000;">self</span>.<span style="color: black;">reserve_inbox</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> reserve_inbox<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">create_inbox</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> create_inbox<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        response = <span style="color: #008000;">self</span>.<span style="color: black;">make_request</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>, <span style="color: #483d8b;">&quot;/c&quot;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>response == <span style="color: #483d8b;">'-1'</span><span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">Exception</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Name already taken, or password invalid'</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> publish<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, content<span style="color: black;">&#41;</span>:
        response = <span style="color: #008000;">self</span>.<span style="color: black;">make_request</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: #483d8b;">'content'</span>: content<span style="color: black;">&#125;</span>, <span style="color: #483d8b;">&quot;/u&quot;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>response == <span style="color: #483d8b;">'-1'</span><span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">Exception</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Invalid update'</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> read<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">self</span>.<span style="color: black;">make_request</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>, <span style="color: #483d8b;">&quot;/r&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> delete<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        response = <span style="color: #008000;">self</span>.<span style="color: black;">make_request</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>, <span style="color: #483d8b;">&quot;/d&quot;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>response == <span style="color: #483d8b;">'-1'</span><span style="color: black;">&#41;</span>:
            <span style="color: #ff7700;font-weight:bold;">raise</span> <span style="color: #008000;">Exception</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Can<span style="color: #000099; font-weight: bold;">\'</span>t delete'</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> make_request<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, data, <span style="color: #dc143c;">resource</span> = <span style="color: #483d8b;">&quot;&quot;</span>, method = <span style="color: #483d8b;">'POST'</span><span style="color: black;">&#41;</span>:
        data<span style="color: black;">&#91;</span><span style="color: #483d8b;">'name'</span><span style="color: black;">&#93;</span> = <span style="color: #008000;">self</span>.<span style="color: black;">inbox_id</span>
        data<span style="color: black;">&#91;</span><span style="color: #483d8b;">'passwd'</span><span style="color: black;">&#93;</span> = <span style="color: #008000;">self</span>.<span style="color: black;">passwd</span>
        opener = <span style="color: #dc143c;">urllib2</span>.<span style="color: black;">build_opener</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">urllib2</span>.<span style="color: black;">HTTPHandler</span><span style="color: black;">&#41;</span>
        request = <span style="color: #dc143c;">urllib2</span>.<span style="color: black;">Request</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">url</span> + <span style="color: #dc143c;">resource</span>, data=<span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlencode</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        request.<span style="color: black;">add_header</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'Content-Type'</span>, <span style="color: #483d8b;">'application/x-www-form-urlencoded'</span><span style="color: black;">&#41;</span> 
        request.<span style="color: black;">get_method</span> = <span style="color: #ff7700;font-weight:bold;">lambda</span>: method
        <span style="color: #ff7700;font-weight:bold;">return</span> opener.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span>request<span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>        
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
&nbsp;
    <span style="color: #808080; font-style: italic;"># publish strings to a valid mailbox</span>
    kvs = KeyValuePublisher<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;srijak0&quot;</span>, <span style="color: #483d8b;">&quot;password&quot;</span>, <span style="color: #483d8b;">'http://my-ipaddr.appspot.com'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">20</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">len</span> = <span style="color: #dc143c;">random</span>.<span style="color: black;">randint</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0</span>,<span style="color: #ff4500;">10000</span><span style="color: black;">&#41;</span>
        content = <span style="color: #483d8b;">''</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">random</span>.<span style="color: black;">choice</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">string</span>.<span style="color: black;">letters</span><span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">xrange</span><span style="color: black;">&#40;</span><span style="color: #008000;">len</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        kvs.<span style="color: black;">publish</span><span style="color: black;">&#40;</span>content<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">assert</span> content == kvs.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #808080; font-style: italic;"># initialize with taken mailbox name</span>
    passed = <span style="color: #008000;">False</span>
    <span style="color: #ff7700;font-weight:bold;">try</span>:
        kvs = KeyValuePublisher<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;srijak0&quot;</span>, <span style="color: #483d8b;">&quot;not_password&quot;</span>, <span style="color: #483d8b;">'http://my-ipaddr.appspot.com'</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">except</span>:
        passed = <span style="color: #008000;">True</span>
    <span style="color: #ff7700;font-weight:bold;">assert</span> passed
&nbsp;
    <span style="color: #808080; font-style: italic;"># delete mailbox</span>
    kvs = KeyValuePublisher<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;srijak0&quot;</span>, <span style="color: #483d8b;">&quot;password&quot;</span>,  <span style="color: #483d8b;">'http://my-ipaddr.appspot.com'</span><span style="color: black;">&#41;</span>
    kvs.<span style="color: black;">delete</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">assert</span> kvs.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> == <span style="color: #483d8b;">'-1'</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;[Tests passed]&quot;</span></pre></div></div>

<p>Pretty self explanatory. </p>
<p>And there you have it. Not the prettiest code I&#8217;ve ever written but it gets the job done well enough for <1hour of work <img src='http://blog.everythings-beta.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.everythings-beta.com/?feed=rss2&amp;p=349</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Massaging a Tornado web pain point: restart requirement</title>
		<link>http://blog.everythings-beta.com/?p=338</link>
		<comments>http://blog.everythings-beta.com/?p=338#comments</comments>
		<pubDate>Tue, 16 Feb 2010 06:08:15 +0000</pubDate>
		<dc:creator>srijak</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tornadoweb]]></category>

		<guid isPermaLink="false">http://blog.everythings-beta.com/?p=338</guid>
		<description><![CDATA[I have been playing around with the Tornado web framework and I really like it: the shallow learning curve paired with everything it brings to the table makes for a very good framework to at least kick off your next real time app. One of the core assumptions in tornado is that request are handled quickly: [...]]]></description>
			<content:encoded><![CDATA[<p>I have been playing around with the <a href="http://www.tornadoweb.org/">Tornado web framework</a> and I really like it: the shallow learning curve paired with everything it brings to the table makes for a very good framework to at least kick off your next real time app.</p>
<p>One of the core assumptions in tornado is that request are handled quickly: if there are any blocking calls in your request handlers, it will cause other requests to queue. So, I have http wrappers around my dbs and queues so that I can handle these blocking calls from my request handlers asynchronously.</p>
<p> Well and good you say. What is the problem? The pain point is that nodes need to be restarted in order for code changes to propagate. And though it&#8217;s not a huge problem, its started to bug me that I have to waste seconds(!) restarting three nodes every time I make a change.  So, I wrote a quick python script to do so. It takes the simplest approach; polling for changes in current directory and restarting nodes if required. I was going to use inotify, but as OSX apparently doesn&#8217;t have it (has something called <a href="http://en.wikipedia.org/wiki/FSEvents">FSEvents</a>), I decided to put off learning a new lib for another day so I could keep hacking on my project.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># Simple script to poll all files of interest below the current working directory</span>
<span style="color: #808080; font-style: italic;"># for changes. On change, it will run w/e commands you want. For me, it has</span>
<span style="color: #808080; font-style: italic;"># been helpful in restarting tornado web nodes.</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">time</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">signal</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">subprocess</span> <span style="color: #ff7700;font-weight:bold;">import</span> Popen
&nbsp;
<span style="color: #808080; font-style: italic;"># define what you want to run here:</span>
<span style="color: #808080; font-style: italic;"># each task is a list of command/arguments to run, popen style</span>
tasks = <span style="color: black;">&#91;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'python'</span>,<span style="color: #483d8b;">'httpDatabase.py'</span><span style="color: black;">&#93;</span>,<span style="color: black;">&#91;</span><span style="color: #483d8b;">'python'</span>,<span style="color: #483d8b;">'main.py'</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># define the file types you want to trigger on</span>
<span style="color: #808080; font-style: italic;"># I opted for .py and html files.</span>
file_regexp = <span style="color: #dc143c;">re</span>.<span style="color: #008000;">compile</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;(.py$|.html$)&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> files_have_changed<span style="color: black;">&#40;</span>old_stats, new_stats<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>old_stats<span style="color: black;">&#41;</span> <span style="color: #66cc66;">!</span>= <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>new_stats<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> k <span style="color: #ff7700;font-weight:bold;">in</span> old_stats:
        <span style="color: #ff7700;font-weight:bold;">if</span> new_stats<span style="color: black;">&#91;</span>k<span style="color: black;">&#93;</span> <span style="color: #66cc66;">!</span>= old_stats<span style="color: black;">&#91;</span>k<span style="color: black;">&#93;</span>:
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> get_stats<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    stats = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span>
    f = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> root, folders, files <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">walk</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">getcwd</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
        f.<span style="color: black;">extend</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>root,x<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> x <span style="color: #ff7700;font-weight:bold;">in</span> files <span style="color: #ff7700;font-weight:bold;">if</span> file_regexp.<span style="color: black;">search</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> <span style="color: #008000;">file</span> <span style="color: #ff7700;font-weight:bold;">in</span> f:
        <span style="color: #ff7700;font-weight:bold;">try</span>:
            stats<span style="color: black;">&#91;</span><span style="color: #008000;">file</span><span style="color: black;">&#93;</span> = <span style="color: #dc143c;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">os</span>.<span style="color: #dc143c;">stat</span><span style="color: black;">&#40;</span><span style="color: #008000;">file</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">8</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">except</span>:
            <span style="color: #ff7700;font-weight:bold;">pass</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> stats
&nbsp;
&nbsp;
handles = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> stop_current<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>handles<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span>:
        <span style="color: #ff7700;font-weight:bold;">for</span> h <span style="color: #ff7700;font-weight:bold;">in</span> handles:
            <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Killing %d&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>h.<span style="color: black;">pid</span><span style="color: black;">&#41;</span>
            <span style="color: #dc143c;">os</span>.<span style="color: black;">kill</span><span style="color: black;">&#40;</span>h.<span style="color: black;">pid</span>, <span style="color: #dc143c;">signal</span>.<span style="color: black;">SIGTERM</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">del</span> handles<span style="color: black;">&#91;</span>:<span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> restart<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Files changed. Restarting&quot;</span>
    stop_current<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">for</span> t <span style="color: #ff7700;font-weight:bold;">in</span> tasks:
        p = Popen<span style="color: black;">&#40;</span>t<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Started %s. PID:%d&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot; &quot;</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>t<span style="color: black;">&#41;</span>,p.<span style="color: black;">pid</span><span style="color: black;">&#41;</span>
&nbsp;
        handles.<span style="color: black;">append</span><span style="color: black;">&#40;</span>p<span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
last_stats = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span> 
<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #ff4500;">1</span>:
    current_stats = get_stats<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>files_have_changed<span style="color: black;">&#40;</span>last_stats, current_stats<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:
        last_stats = current_stats
        restart<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #dc143c;">time</span>.<span style="color: black;">sleep</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.everythings-beta.com/?feed=rss2&amp;p=338</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Goals are good + a Cocoa app to help you stay on track</title>
		<link>http://blog.everythings-beta.com/?p=332</link>
		<comments>http://blog.everythings-beta.com/?p=332#comments</comments>
		<pubDate>Tue, 02 Feb 2010 23:50:45 +0000</pubDate>
		<dc:creator>srijak</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[commit]]></category>
		<category><![CDATA[goals]]></category>
		<category><![CDATA[objc]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://blog.everythings-beta.com/?p=332</guid>
		<description><![CDATA[Goals are good; regardless of how they work out, working at them gives you something to show for the time spent. Read the last 13 words again. If you don&#8217;t have something tangible to show, you just wasted your time. So, always try to produce something tangible. With a ~/Code folder full of projects ranging [...]]]></description>
			<content:encoded><![CDATA[<p style="clear: both">Goals are good; regardless of how they work out, working at them gives you something to show for the time spent. Read the last 13 words again. If you don&#8217;t have something tangible to show, you just wasted your time. So, always <s>try to</s> produce something tangible.</p>
<p style="clear: both">With a ~/Code folder full of projects ranging from &#8220;twinkles in my eye&#8221; to &#8220;just need one more day&#8221;, I will be the first to admit I suck at this. I tell myself it&#8217;s because I have overcome the core technical problem and the only thing left to do is polish and release. It&#8217;s really easy to get sucked in by this, especially when you get another idea (and you will). Or, you may get embroiled in feature creep; you add feature after feature after feature. It&#8217;s also easy to say &#8220;I really learnt xyz even if there was no releasable product&#8221; and let it go at that.</p>
<p> However, all these reasons suck. The first gets you in the habit of abandoning projects 80% of the way, the second is tricky balancing act, but the third is merely mental hand waving; <strong> the experience that counts, where you actually learn something, is when you have a working product</strong><strong> *that people can use*</strong>. It doesn&#8217;t matter how close something is to being released. Anyone can make things that kinda work; if it wasn&#8217;t released, you probably haven&#8217;t learnt the most important things or solved the hardest problems.</p>
<p style="clear: both">With this little epiphany that I need to finish projects, I decided to kill 2 birds with 1 stone by writing an application that keeps me on track with projects (no, I didn&#8217;t miscount, that&#8217;s 2 things). I also set a deadline of starting and finishing it in one day so I could beat feature creep.</p>
<p style="clear: both">Consequently, let me introduce <a href="http://blog.everythings-beta.com/wp-content/uploads/2010/02/Commit.zip">Commit</a>, a OSX app based on the wisdom of <a href="http://lifehacker.com/281626/jerry-seinfelds-productivity-secret" target="_blank">Jerry Sienfeld&#8217;s productivity secret</a>. Basically, you set up various goals that you commit to doing everyday. The motivation to keep the chain from breaking pushes you over the humps when you really want to take a break. Instead of thinking &#8220;I will just miss today&#8221; you start thinking &#8220;I can&#8217;t break the chain today&#8221;. If that isn&#8217;t enough, you get *A GOLD STAR* for everyday you live up to your commitment <img src='http://blog.everythings-beta.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>
<p></p>
<p style="clear: both"><a href="http://blog.everythings-beta.com/wp-content/uploads/2010/02/commitMainView.png" class="image-link"><img src="http://blog.everythings-beta.com/wp-content/uploads/2010/02/commitMainView-thumb.png" height="239" width="380" style=" text-align: center; display: block; margin: 0 auto 10px;" /></a></p>
<p></p>
<p style="clear: both"><a href="http://blog.everythings-beta.com/wp-content/uploads/2010/02/manageGoals.png" class="image-link"><img src="http://blog.everythings-beta.com/wp-content/uploads/2010/02/manageGoals-thumb.png" height="292" width="380" style=" text-align: center; display: block; margin: 0 auto 10px;" /></a><br /><a href="http://blog.everythings-beta.com/wp-content/uploads/2010/02/Commit.zip">Commit</a> also generates graphs to help you track your progress:
<ul style="clear: both">
<li>All time graph shows you a graph of all days since you started this goal. The dips are the days you missed !</li>
<li>The weekly graph lets you see what days of the week seem to be problem areas.</li>
<li>The monthly graph, like the weekly graph, lets you determine patterns of when you slip up, but at a higher level.</li>
</ul>
<p style="clear: both"><a href="http://blog.everythings-beta.com/wp-content/uploads/2010/02/goalsGraph.png" class="image-link"><img src="http://blog.everythings-beta.com/wp-content/uploads/2010/02/goalsGraph2-thumb.png" height="318" width="378" style=" text-align: center; display: block; margin: 0 auto 10px;" /></a>So those are some things it currently does. It was hard not to keep on tacking on new features. But, the limit of the one day release really helped, even though I pushed it a bit <img src='http://blog.everythings-beta.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Things I decided to forego for now: optional twitter/facebook updates on milestones, group commits(group of people commit together, it tells you who is lagging), more graphs, better interface.</p>
<p style="clear: both">So <a href="http://blog.everythings-beta.com/wp-content/uploads/2010/02/Commit.zip">download Commit now</a> and start collecting gold stars <img src='http://blog.everythings-beta.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><br class="final-break" style="clear: both" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.everythings-beta.com/?feed=rss2&amp;p=332</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Easy session management</title>
		<link>http://blog.everythings-beta.com/?p=269</link>
		<comments>http://blog.everythings-beta.com/?p=269#comments</comments>
		<pubDate>Sat, 09 Jan 2010 23:46:02 +0000</pubDate>
		<dc:creator>srijak</dc:creator>
				<category><![CDATA[no-code]]></category>
		<category><![CDATA[objc]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[sm]]></category>

		<guid isPermaLink="false">http://blog.everythings-beta.com/?p=269</guid>
		<description><![CDATA[I hardly ever shut my laptop down as I don&#8217;t want to bother opening up all my applications again. So, I just hibernates/wake up instead. The last time I actually rebooted was Sept. 2009. Unfortunately, this hasn&#8217;t had a good effect on my battery. I did a few quick searches but couldn&#8217;t find a simple [...]]]></description>
			<content:encoded><![CDATA[<p>I hardly ever shut my laptop down as I don&#8217;t want to bother opening up all my applications again.<br />
So, I just hibernates/wake up instead. The last time I actually rebooted was Sept. 2009. Unfortunately, this hasn&#8217;t had a good effect on my battery.</p>
<p><img class="aligncenter size-full wp-image-268" title="not good" src="http://blog.everythings-beta.com/wp-content/uploads/2010/01/laptopb.png" alt="not good" width="297" height="162" /></p>
<p>I did a few quick searches but couldn&#8217;t find a simple session management app for OSX.<br />
And since I haven&#8217;t written anything for cosmcoa, I figured this is the perfect excuse to start.<br />
So, let me present the aptly named &#8220;sm&#8221; a simple <strong>s</strong>ession <strong>m</strong>anagement app for OSX.</p>
<p><img class="alignnone size-full wp-image-272" title="smPrefs" src="http://blog.everythings-beta.com/wp-content/uploads/2010/01/smPrefs.png" alt="smPrefs" width="796" height="497" /></p>
<p>Setup sessions as you want. When you launch a session, all apps in that sessions will be started. Restore your workspace with minimum hassle. You can do so as shown below through the status bar menu, or through the &#8220;Manage Sessions&#8221; list (select the app or session you want to launch and press &#8220;Launch&#8221;)</p>
<p><img class="aligncenter size-full wp-image-271" title="smMenuLaunch" src="http://blog.everythings-beta.com/wp-content/uploads/2010/01/smMenuLaunch.png" alt="smMenuLaunch" width="277" height="125" /></p>
<p>Should be good on 10.5+, but I&#8217;ve only used it on Snow Leopard. <a title="Download sm" href="http://blog.everythings-beta.com/wp-content/uploads/2010/01/sm.zip"> Download now.</a></p>
<p>Possible improvements I may add later: ability to provide customer arguments to apps, timed session start-up, strict mode (only apps in the currently running session are allowed to run),  auto-update, auto-start on boot. But, its functional enough for now <img src='http://blog.everythings-beta.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>p.s: this is the first OSX app I have tried to write. If it crashes etcs, don&#8217;t get mad. Instead, send me a bug report and I&#8217;ll fix it <img src='http://blog.everythings-beta.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.everythings-beta.com/?feed=rss2&amp;p=269</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
