Search is my enemy
by srikanth on 19/01/2013

You get an error message, you paste it into your address bar, muck around a bit in the search results, you instantly find a solution.

Not sure how to do string splitting in Haskell? Well blah, someone on Stack Overflow has already asked that!

Why bother caring to remember which command tells you a list of open network ports on a linux system(Ok, I’ve googled that one so many times that I actually don’t need to Google again – lsof)

Can’t find a function definition? No problem! ctags/Eclipse has it all handled with a few key presses or clicks. So much that I hardly ever remember what file a particular function is in, or even remember the function names for that matter.

For fuck sake, sometimes we hardly ever remember syntax of most languages, because that’s something that’s so easy to look up in Developers’ Guides or tutorials.

The more we rely on search, the less we rely on ourselves, and the lesser we have to grow. Man, I’ve got to stop relying on this shit.

Actually making yourself use Minco
by srikanth on 23/03/2012

Minco is a simple tool to track time that integrates quite well with Things if you use iCal to synchronize all the Next Actions.

A problem with Minco is that I tend to forget to actually log my time on Minco. So, I made a small script that I run with cron to check if I’m actually using Minco. It uses Growl to remind me to actually use it. You also need iCalBuddy which is used to check iCal for current events.


dateFrom=`date -v -2M`
eval /usr/local/bin/icalBuddy -ic Minco eventsFrom:'$dateFrom' to:'$dateTo' > tmp
out="`cat tmp`"

if [ -z "$out" ]; then
/usr/bin/osascript <<-EOF
tell application "System Events"
    set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
end tell

if isRunning then
    tell application id "com.Growl.GrowlHelperApp"
        set the allNotificationsList to ¬
        set the enabledNotificationsList to ¬
        register as application ¬
            "MincoUsage" all notifications allNotificationsList ¬
            default notifications enabledNotificationsList ¬
            icon of application "Script Editor"
        --       Send a Notification...
        notify with name ¬
            "Minco" title ¬
            "Track your time" description ¬
            "Y U NO USE MINCO?" application name "MincoUsage"
    end tell
end if 

rm tmp

I run the script every two minutes but that might be a little too annoying.

Ruby Gems with AWS Elastic MapReduce Streaming
by srikanth on 17/11/2011

I wanted to write a Hadoop streaming program on Amazon’s EMR framework using Ruby. And ofcourse, I needed some libraries. For some reason, the aws-sdk library isn’t installed by default on the mappers and reducers on EMR. So you’ll need to use a bootstrap script to get this to work

#!/bin/bash -x sudo apt-get update
sudo apt-get -y -V install gcc ruby-dev libxml2 libxml2-dev make libxslt1-dev ri
cd rubygems-1.8.11
sudo ruby setup.rb
sudo gem1.8 install aws-sdk -y --no-rdoc

Yup, there’s no gcc by default on those mappers and reducers. So figuring out the errors from gem trying to install stuff was crazy. Hopefully this helps someone out there.

Strict Consistency Models
by srikanth on 11/04/2011

I’ve had some trouble understanding memory consistency models and related terminology. So I thought I’ll write a blog post about whatever I’ve learnt.

Sequential Consistency – This is a very common term. Sequential consistency means that given a program with a bunch of instructions, they will be run in the same order as they are given for that thread/processor. In uniprocessor systems, this is pretty straight-forward and how we naturally think about programs(see Strict Consistency). In multiprocessor systems, we can reason about sequentially consistent programs by considering any interleaving between the two programs. This is under the assumption that each of these instructions is atomic.

To understand this, let’s look at a simplified Dekker’s algorithm. There are two threads P1 and P2 with shared variables x and y.

1] x = 1;
2] r1 = y;

3] y = 1;
4] r2 = x;

Suppose these two threads start around the same time. Then we can think of any interleaving of instructions between these two threads such that the order of execution of instructions of one threads remains the same. In a sequentially consistent environment, there is no possible combination of instruction interleaving that gives r1 = r2 = 0.

One possible interleaving:

P1:                  W(x)1   R(y)1
P2:  W(y)1   R(x)0

Thus the core idea in Sequential Consistency is that there is a Total Order upon the sequence of instructions. The result of the execution should be describable by any total order formed by any interleaving of the instructions.

Legal execution for Sequential Consistency(not linearizable):

P1:  W(x)1
P2:         R(x)0  R(x)1

It can be cool to note that Sequential Consistency is a global property and it’s not composable. The following execution is sequentially valid if we consider the x and y objects separately. But, together the execution becomes inconsistent. So, we can’t take objects that are sequentially consistent and use them together assuming that they will be behave correctly.

Illegal execution for Sequential Consistency(not linearizable, obviously):

P1:  W(x)1       W(y)0       R(x)1
P2:        W(y)1       W(x)0       R(y)1

It’s important to note that the time of execution does not matter and is irrelevant. It’s only the relative order of execution and whether the execution behaves as if some total order exists on it. For the above execution, it behaves as if W(x)1 occurred after R(x)0 even though the actual execution in real life may be as given in the diagram. It’s important to separate behavioral idea of sequential consistency from actual implementation and execution.

Strict Consistency – This is the strictest memory model. It’s same as sequential consistency, except that it absolutely guarantees that any read sees the most recent write across all processors.

One way to imagine it is that there is a global clock for Strict consistency. Every operation occurs at some point on this global clock and all writes are immediately accessible to every other processor. In other words, this behaves like sequential consistency on a uniprocessor.

Causal Consistency - Further relaxing Sequential Consistency, we get this one. Here, concurrent writes may appear in different orders in different processors. Only causally related statements need to execute in the same order for all processors. Two statements are causally related if the result of one affects another. So, a write of x is causally related to the next reads of x. Thus, the result of the read should be the same on all processors. But a write of x and a write of y are not causally related. Hence their orders may appear to be interchanged on different processors.

A valid causally consistent execution:

P1:  W(x)1
P2:  W(x)0
P3:        R(x)0  R(x)1
P4:        R(x)1  R(x)0
Since there is no dependency of any sort between the two writes, they may appear to have happened in different orders on different processors.

Not possible under causal consistency:
P1:         R(x)0   W(x)1
P2:  W(x)0
P3:                        R(x)0  R(x)1
P4:                        R(x)1  R(x)0

Here, it can be reasoned that the R(x)0 in P1 is possibly causally related to the W(x)0. Thus the view of the ordering of instructions in P1 and P2 must be consistent in all other threads. Note that it is possible for P3 and P4 to both read R(x)0 and R(x)1 in that order or vice versa.

What processors and languages do

Most programming languages provide Sequential Consistency as long as the program is Data Race Free. Multiple threads protect accesses to shared memory with some kind of synchronization such as mutual exclusion locks thus avoiding data races. Thus multiple threads will access these critical sections separately.

Microprocessors do not provide sequential consistency directly. This is because it’s typically expensive to implement. Compilers generate code that has the same overall behavior by taking advantage of control flow and read/write dependences in the program. Also, typically microprocessors may try to perform a load earlier violating program order, while maintaining dependence order. Numerous other hardware optimizations are performed to churn out as much speed as possible.

Linearizability - This is Sequential Consistency with an added caveat that there is a time stamp associated with each operation and that every thread sees the operations in the order given by time stamps. This is mainly a tool to reason about executions relative to absolute time. Every execution is said to have occured at the assigned time and can see all the writes that have occured in all processes with lesser timestamps.

Non linearizable, but sequentially consistent execution:

P1:  W(x)1  R(x)0
P2:               W(x)0

This particular execution is not valid for linearizability, but it’s sequentially consistent.

Linearizable and sequentially consistent execution:

P1:  W(x)1         R(x)0
P2:         W(x)0

So, Linearizability is stronger than Sequential Consistency because linearizability actually requires the execution order to be preserved. This constraint allows Linearizable objects to be composable. Thus, a bunch of linearizable objects used together will also give linearizable executions.

Serializability - The context of serializability is typically that of databases. In this, a bunch of statements are grouped together and form a transaction. An execution is serializable if it is equivalent to these transactions running in some sequential order. An execution is strictly serializable, if the actual execution order is “correct”. So, linearizability is just the same as strict serializability, but with each transaction consisting of just one operation. These transactions can run in different or same threads.

Disclaimer: I may not be 100% right on everything!

Scrobbleware v1
by srikanth on 5/02/2011

I listen to a lot of online radio. I particularly use a lot. Apart from my iPod. Now, is a great site for suggestions and generally browsing music related items. And I’ve had a problem of not being able to scrobble my iPod tracks reliably because I use linux. And I couldn’t find a scrobbler extension that works for live365. So, I wrote one. Yea, it is kind of strange of have a scrobbler for a radio station, because sometimes songs that you don’t really “listen to” might play. However, the stations I listen to generally play the music I typically listen to anyway. So, it “works” for me.

Download it here.

It just barely works. I’ll be improving it though. It’s not exactly pretty right now! And I’m also thinking of adding support for other online stations like Grooveshark.

Great WordPress plugins
by srikanth on 25/01/2011

I’ve been configuring this wordpress install and I’ve come across a good few plugins

  1. Disqus – Comments system. Integrates across OpenID, Twitter, etc. Slick. Akismet included. Cons: irritating disqus banners everywhere.
  2. W3 Total Cache – Caching system. Page cache, minify, object caching, etc. It’s pretty awesome, and works very well.
  3. Google Analytics for WordPress – Need I say more?
  4. All in One SEO Pack – I haven’t installed this yet, as I don’t really have any content to optimize. This has the usual canonical URLs, page navigation links, META tags, etc.

As a side note, I’m using Pagelines Platform for my theme. Lot of customization to follow, ofcourse.

Hello, World!
by srikanth on 22/01/2011

That’s how you print “Hello, World!” in HQ9+.