<?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>Hitesh Sarda &#187; Technology</title>
	<atom:link href="http://hitesh.in/category/technology/feed/" rel="self" type="application/rss+xml" />
	<link>http://hitesh.in</link>
	<description>Thoughts on life, technology, education and entrepreneurship</description>
	<lastBuildDate>Thu, 29 Mar 2012 17:13:06 +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>Stemming transliterated Hindi</title>
		<link>http://hitesh.in/2012/stemming-transliterated-hindi/</link>
		<comments>http://hitesh.in/2012/stemming-transliterated-hindi/#comments</comments>
		<pubDate>Thu, 29 Mar 2012 17:13:06 +0000</pubDate>
		<dc:creator>Hitesh</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[hindi]]></category>
		<category><![CDATA[hinglish]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[stemming]]></category>

		<guid isPermaLink="false">http://hitesh.in/?p=693</guid>
		<description><![CDATA[I needed a library which could stem Hindi words written in roman script (transliterated), but could not find one. My search took me to Lucene&#8217;s HindiStemmer, which in turn led me to the paper by Ananthakrishnan Ramanathan and Durgesh D &#8230; <a href="http://hitesh.in/2012/stemming-transliterated-hindi/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I needed a library which could <a title="stem definition on wikipedia" href="http://en.wikipedia.org/wiki/Word_stem" target="_blank">stem</a> Hindi words written in roman script (<a href="http://en.wikipedia.org/wiki/Transliterate" target="_blank">transliterated</a>), but could not find one.</p>
<p>My search took me to <a href="https://svn.apache.org/repos/asf/lucene/dev/trunk/modules/analysis/common/src/java/org/apache/lucene/analysis/hi/HindiStemmer.java" target="_blank">Lucene&#8217;s HindiStemmer</a>, which in turn led me to the paper by Ananthakrishnan Ramanathan and Durgesh D Rao: <a href="http://computing.open.ac.uk/Sites/EACLSouthAsia/Papers/p6-Ramanathan.pdf" target="_blank">A Lightweight Stemmer for Hindi [PDF]</a>. It was a good initiation to how some simple rules could stem most Hindi words.<br />
<span id="more-693"></span>The problem was, it was for words written in Devanagari script not Roman. So I decided to implement the logic for transliterated Hindi. After some refinement, I ended up a large subset of what the paper does, because I wanted to keep the implementation simple.</p>
<p>At the end of a few hours work over a few days, I ended up with one line of code. <em>(I will be paid almost nothing if I were being paid by KLOC written)</em></p>
<pre><code>re.sub(r'(.{2,}?)([aeiougyn]+$)',r'\1', word)</code></pre>
<p>For people who are regex challenged, the above regex, deletes all vowels along with g,y,n from the end of the word, but leaves at least a 2 character long stem, so that words like &#8216;aayenga&#8217; do not completely vanish.</p>
<p>The above regex will stem the words as below:</p>
<table>
<thead>
<tr>
<th>Input word</th>
<th>Stemmed word</th>
</tr>
</thead>
<tbody>
<tr>
<td>Dost<em>i</em></td>
<td>Dost</td>
</tr>
<tr>
<td>Dost<em>on</em></td>
<td>Dost</td>
</tr>
<tr>
<td>Bol<em>iye</em></td>
<td>Bol</td>
</tr>
<tr>
<td>Bol<em>ungi</em></td>
<td>Bol</td>
</tr>
<tr>
<td>Bol<em>a</em></td>
<td>Bol</td>
</tr>
<tr>
<td>Ja<em>na</em></td>
<td>Ja</td>
</tr>
<tr>
<td>Ja<em>enge</em></td>
<td>Ja</td>
</tr>
</tbody>
</table>
<p>What do you think? How could this be improved? What edge cases are not considered?</p>
]]></content:encoded>
			<wfw:commentRss>http://hitesh.in/2012/stemming-transliterated-hindi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Logistic regression</title>
		<link>http://hitesh.in/2011/logistic-regression/</link>
		<comments>http://hitesh.in/2011/logistic-regression/#comments</comments>
		<pubDate>Fri, 30 Dec 2011 06:00:37 +0000</pubDate>
		<dc:creator>Hitesh</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[ml-class]]></category>

		<guid isPermaLink="false">http://hitesh.in/?p=684</guid>
		<description><![CDATA[Logistic regression is used to classify things into positive case or negative case. It is a special case of linear regression which outputs value between 0 and 1, which denote the probability or the likelihood of the given sample being &#8230; <a href="http://hitesh.in/2011/logistic-regression/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Logistic regression is used to classify things into positive case or negative case. It is a special case of linear regression which outputs value between 0 and 1, which denote the probability or the likelihood of the given sample being positive. For e.g. what is the probability of the given email being a spam?</p>
<p>We can then predict a positive case if the hypothesis outputs a value above a certain threshold, which normally is 0.5 but could be more or less. The ideal threshold can be derived based on the cross validation result. More on this in a later post.</p>
<h3>Hypothesis</h3>
<p>As mentioned above, logistic regression is similar to linear regression, but the hypothesis always returns an output between 0 and 1. This is achieved by passing the hypothesis of the linear regression to a <a href="http://en.wikipedia.org/wiki/Sigmoid_function">Sigmoid function</a>.<br />
Thus the hypothesis is denoted as:</p>
<pre><code>h<sub>θ</sub>(x) = g(θ<sup>T</sup>x) </code></pre>
<p>where g is the sigmoid function defined as:</p>
<p><img src="http://hitesh.in/wp-content/uploads/2011/12/122711_2142_Logisticreg1.gif" alt="g(z)=1/1+e^-z" width="100" height="40" style="background-color: white;" /></p>
<h3>Cost Function</h3>
<p>The cost function for classification problems are a bit more involved due to the fact that simple squared error is not sufficient to work with the small differences here, since the max difference possible is 1, predictive 0% probability for a positive case. Therefore to magnify the differences a log scale is used.<br />
<img src="http://hitesh.in/wp-content/uploads/2011/12/122711_2142_Logisticreg2.png" alt="cost function of logistic regression" /><br />
Vectorized version:</p>
<pre><code>J = sum(-y .* log(hypo) - (1-y).*log(1-hypo)) / -m</code></pre>
<h3>Derivative of cost function (gradient)</h3>
<p>The gradient for hypothesis is the same as that of linear regression:<br />
<img src="http://hitesh.in/wp-content/uploads/2011/12/122711_2142_Logisticreg3.png" alt="Derivative of cost function" /><br />
The hypothesis of course is different as stated above.</p>
<h2>Multiclass Classification</h2>
<p>So far we have only looked at 2 distinct results from the algorithm, either negative (y=0) or positive (y=1). But what if there are more than 2 distinct possibilities? This is covered under multi class or one-vs-all classification.</p>
<p>The basic idea is simple. We train the classifier once per each possible outcome. For e.g. If we need to predict if the given sentence is in English, German or French, we will derive the value of θ for each.</p>
<p>So the θ for English will be able to predict whether the sentence is in English or not, thus changing the problem to a single class (positive/negative) classification. Similarly the θ for German and French are derived.</p>
<p>Then for a given sentence we will calculate the probability of it being English, German or French and return the language having the highest probability.</p>
]]></content:encoded>
			<wfw:commentRss>http://hitesh.in/2011/logistic-regression/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Linear regression</title>
		<link>http://hitesh.in/2011/linear-regression/</link>
		<comments>http://hitesh.in/2011/linear-regression/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 18:59:46 +0000</pubDate>
		<dc:creator>Hitesh</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[ml-class]]></category>

		<guid isPermaLink="false">http://hitesh.in/?p=649</guid>
		<description><![CDATA[Linear regression is a fancy name to a simple technique. This algorithm (model) predicts the most likely result (y) given the input features (x). To be able to predict, the model needs (lots of) historical data with the correct output &#8230; <a href="http://hitesh.in/2011/linear-regression/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Linear regression is a fancy name to a simple technique. This algorithm (model) predicts the most likely result (<strong>y</strong>) given the input features (<strong>x</strong>). To be able to predict, the model needs (lots of) historical data with the correct output (thus it is supervised learning).</p>
<p>This model finds weights (<strong>θ</strong>) to be assigned to each feature, such that sum of the weighted features is closest to the given answer <strong>y</strong>.<br />
<span id="more-649"></span></p>
<h3>Hypothesis</h3>
<p>So given there are n features x<sub>0</sub> to x<sub>n</sub> and the related weights θ<sub>0</sub> to θ<sub>n</sub>; the hypothesis is given as:</p>
<pre><code>h<sub>θ</sub>(x) = θ<sub>0</sub>x<sub>0</sub> + θ<sub>1</sub>x<sub>1</sub> + ... + θ<sub>n</sub>x<sub>n</sub></code></pre>
<p>If θ and x are stored as matrices, then the above can be represented as matrix multiplication and is called <em>vectorized implementation</em>. Vectorisation really speeds up the processing and was one of the big lessons on the entire ML class. The vectorized version of the above hypothesis is:</p>
<pre><code>h<sub>θ</sub>(x) = θ<sup>T</sup>x</code></pre>
<h3>Cost function</h3>
<p>So what remains is to find values of θ those results in the hypothesis predicting values that are <em>close</em> to the correct value given.</p>
<p>There could be several definition of <em>close</em>, but the most accepted definition is <em>average squared error.</em> In other words it is the sum of the square of the difference between the actual value and the predicted value, divided by 2m where m is the total number of samples.</p>
<p>Vectorized version:</p>
<pre><code>sumsq(θ<sup>T</sup>x-y) / (2*m)</code></pre>
<h3>Optimisation Algorithms</h3>
<p>So far so good and here comes the difficult part. Now we are left with finding the values of theta which minimizes the above cost function. We could do this with trial and error, and maybe come up with an answer in a few years. Thankfully there are several algorithms developed by people much smarter than me and I could use their work to get the results. There were few approaches discussed in the class.</p>
<ul>
<li>Normal Equation</li>
<li>Gradient Descent</li>
<li> Advanced algorithms
<ul>
<li>Conjugate gradient (fminunc &amp; fmincg)</li>
<li>BFGS, L-BFGS (just mentioned)</li>
</ul>
</li>
</ul>
<p>We mostly used gradient descent and fminunc / fmincg in the class, and both expect a cost function that returns the cost and the gradient.</p>
<h3>Derivative of cost function (gradient)</h3>
<p>The cost was defined above and the gradient for linear regression hypothesis is given as:</p>
<p><img src="http://hitesh.in/wp-content/uploads/2011/12/122511_1902_Linearregre1.png" alt="" /></p>
<p>(for j = 0 to n)</p>
<p>Vectorized version:</p>
<pre><code>X' * (X * theta - y) / m</code></pre>
<h3>Implementation notes</h3>
<p>Details will be covered in another post.</p>
<ul>
<li>Apply feature scaling</li>
<li>Apply mean normalisation</li>
<li>Add a new feature (x<sub>0</sub>) which is all ones</li>
<li>It helps to visualize the data</li>
<li>It helps plot the cost after each iteration</li>
<li>There are several other practical tips given throughout the class, and I hope to blog about it as well.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://hitesh.in/2011/linear-regression/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Machine Learning: My notes.</title>
		<link>http://hitesh.in/2011/machine-learning-my-notes/</link>
		<comments>http://hitesh.in/2011/machine-learning-my-notes/#comments</comments>
		<pubDate>Sat, 24 Dec 2011 15:00:44 +0000</pubDate>
		<dc:creator>Hitesh</dc:creator>
				<category><![CDATA[Education]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[ml-class]]></category>

		<guid isPermaLink="false">http://hitesh.in/?p=641</guid>
		<description><![CDATA[I recently finished the machine learning class offered online by Stanford. It was a great experience. Since I would not be using ML any time soon, I plan to make a few blog posts to capture my learning while they &#8230; <a href="http://hitesh.in/2011/machine-learning-my-notes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently finished the <a href="http://www.ml-class.org/">machine learning class</a> offered online by Stanford. It was a great experience. Since I would not be using ML any time soon, I plan to make a few blog posts to capture my learning while they are still current. This should help me recollect the concepts on a later date. If someone finds these notes useful, that is an added benefit.</p>
<h2>Machine learning</h2>
<p>Arthur Samuel (1959): Field of study that gives computers the ability to learn without being explicitly programmed.</p>
<p><span id="more-641"></span>Machine learning algorithms (covered in the class):</p>
<ul>
<li>­Supervised learning
<ul>
<li><a title="Linear regression" href="http://hitesh.in/2011/linear-regression/">Linear Regression</a></li>
<li>Logistic Regression (Classification)</li>
<li>Neural Networks</li>
<li>Support Vector Machine</li>
</ul>
</li>
</ul>
<ul>
<li>­Unsupervised learning
<ul>
<li>k-Means clustering</li>
<li>Principal Component Analysis</li>
</ul>
</li>
</ul>
<h3>My understanding of machine learning:</h3>
<p>Given a set of examples with certain features; the ability of  a computer to approach, and surpass, the ability of a human expert at analysing and extracting meaning out of the given data.</p>
<h3>Important points about ML:</h3>
<ol>
<li value="1">If a human expert does not find the data sufficient to come up with a conclusion, then the computer is unlikely to perform any better.</li>
<li value="2">All machine learning algorithms are based on mathematics, and thus expect all data to be numbers.</li>
<li value="3">Usually more data is better, but not if the data is redundant. That is, duplicate examples or features.</li>
</ol>
<p>More to come in future posts.</p>
]]></content:encoded>
			<wfw:commentRss>http://hitesh.in/2011/machine-learning-my-notes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Evaluating in-house frameworks</title>
		<link>http://hitesh.in/2011/evaluating-in-house-frameworks/</link>
		<comments>http://hitesh.in/2011/evaluating-in-house-frameworks/#comments</comments>
		<pubDate>Sun, 11 Dec 2011 08:14:39 +0000</pubDate>
		<dc:creator>Hitesh</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[@work]]></category>

		<guid isPermaLink="false">http://hitesh.in/2011/evaluating-in-house-frameworks/</guid>
		<description><![CDATA[In-house frameworks The very mention of this word brings out different memories and emotions for different people. More so if is a framework for be used within a large company, by a completely different team than the one writing it. &#8230; <a href="http://hitesh.in/2011/evaluating-in-house-frameworks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h3>In-house frameworks</h3>
<p>The very mention of this word brings out different memories and emotions for different people. More so if is a framework for be used within a large company, by a completely different team than the one writing it.</p>
<p>To make sure that the next time you hear this word, you have positive memories; use the evaluation sheet below, before adopting the framework. If you are the one writing the framework, make sure you have good answers to these.</p>
<h2>Why in-house frameworks?</h2>
<p>Before we begin, let&#8217;s recap why we need in-house frameworks in the first place.</p>
<p><span id="more-631"></span>Each company, more so is it is an &#8216;enterprise&#8217; has a certain set of internal standards and a &#8216;way to do things&#8217;. Be those be related to security, encryption, authentication, authorisation or be it about data retention, traceability, logging or monitoring. The foremost benefit of an in-house framework is out-of-the-box support for these standards and hence any solution built on them is preapproved by the standards committee, while saving the developers from reinventing the wheel for these.</p>
<p>These frameworks also know the company&#8217;s domain and can provide a lot of helper functions at the least to a full blown DSL on the other extreme. Thus an in-house framework is a <em>good thing to have</em> if it can pass the evaluation criteria.</p>
<h2>How to evaluate an in-house framework?</h2>
<p>Well, it is no different from evaluating a external framework, be it commercial or an open-source one.</p>
<ul>
<li>What is the origin of the framework?
<ul>
<li>Was it created from a blank slate, based on past project learning? If so, has it been battle-tested? You don&#8217;t want to be the guinea pig.</li>
<li>Was it extracted out of software delivered? Is it still tightly coupled to the environment the original software ran in?</li>
</ul>
</li>
<li>What is the team&#8217;s motivation to maintain this framework?
<ul>
<li>Is the framework their primary task or is it a distraction? This is especially the case when the framework is either extracted from a project or was primarily written for a specific project.</li>
</ul>
</li>
<li>What is the development model?
<ul>
<li>Does it mimic a commercial vendor? What is the governance model around support and enhancement request?</li>
<li>Or does it mimic open-source model? What is the governance model around roadmap, vision and acceptance of patches?</li>
<li>Does the framework team have a consistent vision to avoid the framework from acquiring feature-bloat, and at the same time is it extensible enough for a team using it?</li>
</ul>
</li>
<li>What is the learning curve? How well documented it the framework?
<ul>
<li>This is the single most important question to ask. For external frameworks, you have the internet to help you out, but for internal ones, the documentation is normally the only hope. In addition, you can hire people with skills in external framework, but will need to train every new hire on the internal framework, so it better have a short learning curve.</li>
</ul>
</li>
<li>What is the release and support model?
<ul>
<li>You don&#8217;t want to be using a framework which does not have a specific release cadence and a know support model for older versions. Neither should the support model allow proliferation of versions in <em>the</em><br />
<em>wild</em>, nor should it force and upgrade every 3 months.</li>
</ul>
</li>
<li>Finally, will it last?
<ul>
<li>Is there organisational and budget support for the framework team?</li>
<li>Will the framework continue to live after the lead developers have left?</li>
</ul>
</li>
</ul>
<div>If you have other criterion, please leave a comment below.</div>
]]></content:encoded>
			<wfw:commentRss>http://hitesh.in/2011/evaluating-in-house-frameworks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running a bottle.py app on Dreamhost</title>
		<link>http://hitesh.in/2011/running-a-bottle-py-app-on-dreamhost/</link>
		<comments>http://hitesh.in/2011/running-a-bottle-py-app-on-dreamhost/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 15:36:00 +0000</pubDate>
		<dc:creator>Hitesh</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[bottle]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://hitesh.in/2011/running-a-bottle-py-app-on-dreamhost/</guid>
		<description><![CDATA[I wrote the Stack Monthly site on the one file Bottle framework, since my needs were really bare bones. But when I tried to get it running on Dreamhost, I had to struggle quite a lot, because there was no &#8230; <a href="http://hitesh.in/2011/running-a-bottle-py-app-on-dreamhost/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I wrote the <a href="http://stackmonthly.com/">Stack Monthly</a> site on the one file <a href="http://bottlepy.org/">Bottle framework</a>, since my needs were really bare bones. But when I tried to get it running on Dreamhost, I had to struggle quite a lot, because there was no documentation to show how to do it.</p>
<p>Only past midnight, did it dawn on me that there is no documentation, because it is so darn simple! So as a note to self, and to save someone an hour or two, here&#8217;s how to run a Bottle app on Dreamhost.</p>
<blockquote><p><strong>In a rush? Get the <a href="https://gist.github.com/1023027">code at github</a>.</strong></p></blockquote>
<h2><span id="more-623"></span>Setup a domain</h2>
<p>Follow the steps listed in the wiki, to setup <a href="http://wiki.dreamhost.com/Passenger">Python/Passenger support for a domain</a>.</p>
<p><img src="http://hitesh.in/wp-content/uploads/2011/06/061311_1539_Runningabot1.png" alt="" /></p>
<h2>Create a passenger_wsgi.py</h2>
<p>This is where the Apache Passenger module hooks into our application. There are 4 steps needed to create this file.</p>
<h3>Set the path</h3>
<p>All dreamhost documentation on python advises that you setup a virtual environment. Since bottle has no dependencies this is not needed. Instead just add the current directory, where bottle.py resides, into the system path.</p>
<pre><code>import os, sys </code><code>cmd_folder = os.path.dirname(os.path.abspath(__file__)) </code><code>if cmd_folder not in sys.path: </code><code> sys.path.insert(0, cmd_folder) </code></pre>
<h3>Passenger hook method</h3>
<pre><code>def application(environ, start_response): </code><code> return bottle.default_app().wsgi(environ,start_response) </code></pre>
<h3>Write a main method</h3>
<p>This will be used to run a development server, in debug mode and auto reload.</p>
<pre><code>if __name__ == "__main__": </code><code> bottle.debug(True) </code><code> run(reloader=True) </code></pre>
<h3>Write your application</h3>
<p>Well, you will need to write your own application <img src='http://hitesh.in/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre><code>@route('/') </code><code>def index(): </code><code>  return "it works!" </code></pre>
<p>That&#8217;s it, save it as passenger_wsgi.py.</p>
<p>For local development, run it as</p>
<pre>python passenger_wsgi.py</pre>
<p>on dreamhost, stuff will just happen.</p>
<h2>Additional notes</h2>
<h3>Create restart.txt</h3>
<p>To restart your application on dreamhost, run this command:</p>
<pre>touch tmp/restart.txt</pre>
<p>in the base folder, i.e. the parent of the public folder defined in the &#8220;Web directory&#8221; of the dreamhost domain setup.</p>
<h3>Server static files directly</h3>
<p>It is better to let apache/passenger take care of serving static files. Any file found in the public directory will be served directly and bottle routing will not be called.</p>
<p>For local development, define routes to server static files out of public directory.</p>
<pre><code>@route('/css/:file') </code><code>def css_file(file): </code><code> send_file(file, root='public/css') </code></pre>
<p>Full code <a href="https://gist.github.com/1023027">listing on github</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://hitesh.in/2011/running-a-bottle-py-app-on-dreamhost/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Technical Heaven</title>
		<link>http://hitesh.in/2010/technical-heaven/</link>
		<comments>http://hitesh.in/2010/technical-heaven/#comments</comments>
		<pubDate>Sun, 24 Oct 2010 07:26:12 +0000</pubDate>
		<dc:creator>Hitesh</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[history]]></category>
		<category><![CDATA[museum]]></category>

		<guid isPermaLink="false">http://hitesh.in/2010/technical-heaven/</guid>
		<description><![CDATA[where dead technologies go Some photos taken at the Technology Museum in Munich. The ENIGMA One of the first crypto machine. An Enigma machine is any of a family of related electro-mechanical rotor machines used for the encryption and decryption &#8230; <a href="http://hitesh.in/2010/technical-heaven/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h4><em>where dead technologies go</em></h4>
<p>Some photos taken at the Technology Museum in Munich.</p>
<h3>The ENIGMA</h3>
<p>One of the first crypto machine.</p>
<p><a href="http://hitesh.in/wp-content/uploads/2010/TechnicalHeaven_845E/IMG_0287.jpg"><img style="display: inline; border-width: 0px;" title="IMG_0287" src="http://hitesh.in/wp-content/uploads/2010/TechnicalHeaven_845E/IMG_0287_thumb.jpg" alt="IMG_0287" width="580" height="772" border="0" /></a></p>
<blockquote><p>An Enigma machine is any of a family of related electro-mechanical rotor machines used for the encryption and decryption of secret messages. The first Enigma was invented by German engineer Arthur Scherbius at the end of World War I. This model and its variants were used commercially from the early 1920s, and adopted by military and government services of several countries &#8211; most notably by Nazi Germany before and during World War II.</p>
<p>- <a href="http://en.wikipedia.org/wiki/ENIGMA">http://en.wikipedia.org/wiki/ENIGMA</a></p></blockquote>
<h3><span id="more-616"></span>Random set of Keyboards</h3>
<p><a href="http://hitesh.in/wp-content/uploads/2010/TechnicalHeaven_845E/IMG_0288.jpg"><img style="display: inline; border-width: 0px;" title="IMG_0288" src="http://hitesh.in/wp-content/uploads/2010/TechnicalHeaven_845E/IMG_0288_thumb.jpg" alt="IMG_0288" width="644" height="484" border="0" /></a></p>
<h3>Mechanical Calculators (Arithmometer)</h3>
<p><a href="http://hitesh.in/wp-content/uploads/2010/TechnicalHeaven_845E/IMG_0289.jpg"><img style="display: inline; border-width: 0px;" title="IMG_0289" src="http://hitesh.in/wp-content/uploads/2010/TechnicalHeaven_845E/IMG_0289_thumb.jpg" alt="IMG_0289" width="644" height="484" border="0" /></a></p>
<blockquote><p>An Arithmometer or Arithmomtre was a mechanical calculator that could add and subtract directly and could perform long multiplications and divisions effectively by using a movable accumulator for the result. Patented in France by Thomas de Colmar in 1820 and manufactured from 1851 to 1915, it became the first commercially successful mechanical calculator. Its sturdy design gave it a strong reputation of reliability and accuracy and made it a key player in the move from human computers to calculating machines that took place during the second half of the 19th century.</p>
<p>- <a href="http://en.wikipedia.org/wiki/Arithmometer">http://en.wikipedia.org/wiki/Arithmometer</a></p></blockquote>
<h3>IBM System 360 (Mainframe)</h3>
<p><a href="http://hitesh.in/wp-content/uploads/2010/TechnicalHeaven_845E/IMG_0290.jpg"><img style="display: inline; border-width: 0px;" title="IMG_0290" src="http://hitesh.in/wp-content/uploads/2010/TechnicalHeaven_845E/IMG_0290_thumb.jpg" alt="IMG_0290" width="644" height="484" border="0" /></a></p>
<blockquote><p>The IBM System/360 (S/360) was a mainframe computer system family first announced by IBM on April 7, 1964, and sold between 1964 and 1978. It was the first family of computers designed to cover the complete range of applications, from small to large, both commercial and scientific. The design made a clear distinction between architecture and implementation, allowing IBM to release a suite of compatible designs at different prices. All but the most expensive systems used microcode to implement the instruction set, which featured 8-bit byte addressing and binary, decimal and floating-point calculations.</p>
<p>- <a href="http://en.wikipedia.org/wiki/IBM_System/360">http://en.wikipedia.org/wiki/IBM_System/360</a></p></blockquote>
<h2>IBM 2560</h2>
<p><a href="http://hitesh.in/wp-content/uploads/2010/TechnicalHeaven_845E/IMG_0291.jpg"><img style="display: inline; border-width: 0px;" title="IMG_0291" src="http://hitesh.in/wp-content/uploads/2010/TechnicalHeaven_845E/IMG_0291_thumb.jpg" alt="IMG_0291" width="644" height="484" border="0" /></a></p>
<p>Multifunction card machine (reader/punch/interpreter/multi-hopper)</p>
<h3>Siemens 2002</h3>
<p><a href="http://hitesh.in/wp-content/uploads/2010/TechnicalHeaven_845E/IMG_0292.jpg"><img style="display: inline; border-width: 0px;" title="IMG_0292" src="http://hitesh.in/wp-content/uploads/2010/TechnicalHeaven_845E/IMG_0292_thumb.jpg" alt="IMG_0292" width="644" height="484" border="0" /></a></p>
<p><strong>The Siemens 2002</strong> was a transistor computers manufactured by Siemens &amp; Halske.</p>
<p>In 1954 its development began. The first prototype was fisnished in 1956 and distrubutions started in 1959. The Siemens 2002 was manufactured until 1966.</p>
<p>The system used magnetic core memories as memory had as extension, a drum storage. Different peripheral devices could be attached such as paper tape devices, page printers, card equipment, magnetic tapes and high speed printers.</p>
<h3>Japanese Keyboard</h3>
<p><a href="http://hitesh.in/wp-content/uploads/2010/TechnicalHeaven_845E/IMG_0294.jpg"><img style="display: inline; border-width: 0px;" title="IMG_0294" src="http://hitesh.in/wp-content/uploads/2010/TechnicalHeaven_845E/IMG_0294_thumb.jpg" alt="IMG_0294" width="644" height="484" border="0" /></a></p>
<h3>IBM 729 V &#8211; magnetic Tape Storage</h3>
<p><a href="http://hitesh.in/wp-content/uploads/2010/TechnicalHeaven_845E/IMG_0298.jpg"><img style="display: inline; border-width: 0px;" title="IMG_0298" src="http://hitesh.in/wp-content/uploads/2010/TechnicalHeaven_845E/IMG_0298_thumb.jpg" alt="IMG_0298" width="580" height="772" border="0" /></a></p>
<blockquote><p>The IBM 729 Magnetic Tape Unit was IBM&#8217;s iconic tape mass storage system from the late 1950s through the mid 1960s. Part of the IBM 7 track family of tape units, it was used on late 700, most 7000 and many 1400 series computers.</p>
<p>- <a href="http://en.wikipedia.org/wiki/IBM_729">http://en.wikipedia.org/wiki/IBM_729</a></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://hitesh.in/2010/technical-heaven/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dumping thread stack trace in Java &amp; .NET</title>
		<link>http://hitesh.in/2010/dumping-thread-stack-trace-in-java-net/</link>
		<comments>http://hitesh.in/2010/dumping-thread-stack-trace-in-java-net/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 06:26:35 +0000</pubDate>
		<dc:creator>Hitesh</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[@work]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://hitesh.in/?p=609</guid>
		<description><![CDATA[Multi-threaded Java practitioners know about the indispensible ways to taking thread dumps to see a snapshot of what&#8217;s happening in the JVM, and resolve &#8216;hang&#8217; issues. There are plethora of options, ranging from simple command line tools and utilities to &#8230; <a href="http://hitesh.in/2010/dumping-thread-stack-trace-in-java-net/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Multi-threaded Java practitioners know about the indispensible ways to taking thread dumps to see a snapshot of what&#8217;s happening in the JVM, and resolve &#8216;hang&#8217; issues. There are plethora of options, ranging from simple command line tools and utilities to nice GUI applications to writing some code in your application. A sampling of such options:</p>
<h3>Stack trace in Java</h3>
<h4>Command Line</h4>
<p>If the application is running as a console application, you can try one of these:</p>
<p><strong>Sending a signal to the Java Virtual Machine</strong></p>
<p>On UNIX platforms you can send a signal to a program by using the kill command. This is the quit signal, which is handled by the JVM. For example, on Solaris you can use the command <code>kill -QUIT process_id</code>, where process_id is the process number of your Java program.</p>
<p><span id="more-609"></span>Alternatively you can enter the key sequence <code>&lt;ctrl&gt;\</code> in the window where the Java program was started. Sending this signal instructs a signal handler in the JVM, to recursively print out all the information on the threads and monitors inside the JVM.</p>
<p>To generate a stack trace on Windows, enter the key sequence <code>&lt;ctrl&gt;&lt;break&gt;</code> in the window where the Java program is running, or click the Close button on the window.<br />
(Excerpt from <a href="http://java.sun.com/developer/technicalArticles/Programming/Stacktrace/">http://java.sun.com/developer/technicalArticles/Programming/Stacktrace/</a>)</p>
<p>If the application is not running in a console, you can use the <a href="http://download.oracle.com/javase/1.5.0/docs/tooldocs/share/jstack.html">jstack</a> tool that ships with J2EE since 1.5</p>
<pre><strong>jstack</strong> [ option ] pid
<strong>jstack</strong> [ option ] executable core
<strong>jstack</strong> [ option ] [server-id@]remote-hostname-or-IP</pre>
<h4>GUI Tools</h4>
<p>Since the JVM provides APIs to hook in and get the thread state and other information, there are several tools in the market that allows you to see the state of the running application including the thread stack trace. One such freely available option is <a href="http://download-llnw.oracle.com/javase/6/docs/technotes/guides/visualvm/index.html">VisualVM</a>. In fact it ships with JDK these days. Although VisualVM is pretty self explanatory, here are some instructions to get you started. <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/visualvm/threads.html">http://docs.oracle.com/javase/6/docs/technotes/guides/visualvm/threads.html</a></p>
<p><img title="screenshot of thread dump (stack trace) in thread dump sub-tab" src="http://docs.oracle.com/javase/6/docs/technotes/guides/visualvm/images/thread-dump-screen.png" alt="screenshot of timeline in Threads tab" /></p>
<p>You could also use jConsole for similar purpose, but I prefer VisualVM. Check this for more information: <a href="http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html#DeadlockDetection">http://java.sun.com/developer/technicalArticles/J2SE/jconsole.html#DeadlockDetection</a></p>
<p><img src="http://java.sun.com/developer/technicalArticles/J2SE/jconsole/FindDeadlock-IDs.jpg" alt="Figure 11: Find Deadlocked Threads" width="675" height="530" border="0" /></p>
<h4>Programmatically capturing the stack trace</h4>
<p>from within an appilcation, you can call : <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#getStackTrace()" target="_blank">Thread.getAllStackTraces()</a>. But if you want to do the same from a different application, <a href="http://download.oracle.com/javase/6/docs/api/java/lang/management/ThreadMXBean.html" target="_blank">ThreadMXBean</a> exposes the needed data, which can be retrieved by using the <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/lang/management/ManagementFactory.html" target="_blank">JMX interface</a>.</p>
<h3>Dumping thread Stack trace in .NET</h3>
<p>.NET does not seem to have the variety of options like Java. The only reasonable option I have seen so far is the <a href="http://www.codeplex.com/wikipage?ProjectName=MSE" target="_blank">Managed Stack Explorer</a>. This can be run from the command line as</p>
<pre>mse /s /p &lt;pid&gt;</pre>
<p>or as a GUI application:</p>
<p><a href="http://hitesh.in/wp-content/uploads/2010/DumpingthreadstacktraceinJava.NET_76CB/image.png"><img style="display: inline; border: 0px;" title="image" src="http://hitesh.in/wp-content/uploads/2010/DumpingthreadstacktraceinJava.NET_76CB/image_thumb.png" alt="image" width="586" height="454" border="0" /></a></p>
<p>Since it is an open source (MSPL) project, I took a peek into its source to check the API used. It depends on some sample code released by the CLR Team called <a href="http://www.microsoft.com/downloads/details.aspx?familyid=38449a42-6b7a-4e28-80ce-c55645ab1310&amp;displaylang=en" target="_blank">mdbg</a>. This in turn is a managed layer on the unmanaged <a href="http://msdn.microsoft.com/en-us/library/bb397953.aspx" target="_blank">CLR Debugging Services API</a>.</p>
<p>From what I see there seems to be no direct way to get a stack trace in .NET, apart from either using the debugger API, or rolling your own on top of the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stacktrace.aspx" target="_blank">StackTrace</a> class. Check <a href="http://stackoverflow.com/questions/51768/print-stack-trace-information-from-c" target="_blank">this question on StackOverflow</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://hitesh.in/2010/dumping-thread-stack-trace-in-java-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Beware of the clone</title>
		<link>http://hitesh.in/2010/beware-of-the-clone/</link>
		<comments>http://hitesh.in/2010/beware-of-the-clone/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 07:12:02 +0000</pubDate>
		<dc:creator>Hitesh</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[@work]]></category>

		<guid isPermaLink="false">http://hitesh.in/?p=605</guid>
		<description><![CDATA[Why Clone In this world of concurrent, multi-threaded programming, functional style of programming makes more sense. And one of the key tenets of functional programming is immutability. Even in OO languages, a few benefits of FP can be derived if &#8230; <a href="http://hitesh.in/2010/beware-of-the-clone/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<h2>Why Clone</h2>
<p>In this world of concurrent, multi-threaded programming, functional style of programming makes more sense. And one of the key tenets of functional programming is immutability. Even in OO languages, a few benefits of FP can be derived if the objects are made immutable.</p>
<h2>Clone gone wrong</h2>
<p>We follow a similar approach in our application. But this is not always possible, especially the mutable by default approach of Java. To overcome this, we pass around clones of instances, instead of the instance itself. This works in most cases, but we experienced a very subtle bug last week, where one thread was changing the values on a clone held by another thread, in spite of having no reference to it.</p>
<h2><span id="more-605"></span>The cause</h2>
<p>After lot of disbelief and head scratching, the reason was there, right in front. We were calling the instance.clone() to create a clone. The clone function defined in the Object class (more or less) takes each variable and makes a copy if it and assigns it to the variable of the new instance. This works great for stack variable, but the for the ones on the heap, only the reference is copied, in effect both the clones have reference to the same instance of the member variable. In other words, it does a shallow copy and you might actually need a deep copy sometimes.</p>
<p><strong>Before Clone</strong></p>
<p><img src="http://hitesh.in/wp-content/uploads/2010/07/072410_0712_Bewareofthe1.png" alt="" /></p>
<p><strong>After Clone</strong></p>
<p><img src="http://hitesh.in/wp-content/uploads/2010/07/072410_0712_Bewareofthe2.png" alt="" /></p>
<h2>The effect</h2>
<p>Thus any change made to MyClassInstance.OtherClass after MyClassClone was created also changes the MyClassClone.OtherClass, leading to confusing side effects.</p>
<h2>The solution</h2>
<p>Once the problem is understood, the solution is obvious. Just override the clone method and clone any reference classes in it.</p>
<p>Check <a href="http://stackoverflow.com/questions/2890340/question-about-cloning-in-java">http://stackoverflow.com/questions/2890340/question-about-cloning-in-java</a> for more.</p>
]]></content:encoded>
			<wfw:commentRss>http://hitesh.in/2010/beware-of-the-clone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft LifeCam VX-1000 on Ubuntu + Skype</title>
		<link>http://hitesh.in/2010/microsoft-lifecam-vx-1000-on-ubuntu-skype/</link>
		<comments>http://hitesh.in/2010/microsoft-lifecam-vx-1000-on-ubuntu-skype/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 18:23:19 +0000</pubDate>
		<dc:creator>Hitesh</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[lifecam]]></category>
		<category><![CDATA[skype]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://hitesh.in/?p=582</guid>
		<description><![CDATA[Quick note to self, to save some searching next time. Microsoft LifeCam VX-1000 does not quite work on Ubuntu and even worse with Skype. To get video working on Skype, start it as : env LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype And to get &#8230; <a href="http://hitesh.in/2010/microsoft-lifecam-vx-1000-on-ubuntu-skype/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p class="note">Quick note to self, to save some searching next time.</p>
<p>Microsoft LifeCam VX-1000 does not quite work on Ubuntu and even worse with Skype.<br />
To get video working on Skype, start it as :<br />
<code>env LD_PRELOAD=/usr/lib/libv4l/v4l1compat.so skype</code></p>
<p>And to get the microphone working, run this in a terminal<br />
<code>sudo rmmod gspca_sonixj<br />
sudo modprobe gspca_sonixj</code></p>
]]></content:encoded>
			<wfw:commentRss>http://hitesh.in/2010/microsoft-lifecam-vx-1000-on-ubuntu-skype/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

