Friday, June 29, 2007

महावितरण and the art of वितरण!!

महा in english means mega or big, and वितरण means distribution. Thus in short this is the name of the electricity distribution company that distributes electricity to the most industrialized state in India, महाराष्ट्र (maharaashtra), and I live in पुणे (pune) one of the top 10 metros in India. The availability of electricity is a random function. Not to mention, the fluctuations in the voltages, which take their vicitims every now and then. The voltage levels are not so random they range between 160 to 300 with mean being 230ish.

So here are few examples of one's experience with the art of वितरण.
- You read a nice blog by a friend, when you are about to write a comment and just at that moment, the laptop cribs "power disconnected!" and then you are like "O fuck!", and then you wait for a couple of minutes, 'cos you know the electricity is going to come back anytime, its just like waiting for a RockStar at a big concert, he can arrive anytime, next minute in a few minutes but certainly "today"...

- whenever clouds gather in the sky, you can bet all your wealth that the electricity is going to go anytime soon.. Infact a couple of times I have been "disappointed", when, inspite or heavy showers the electricity was intact for good twelve minutes..

- sometimes there is nothing happening in the sky, but lights go off and on a few times in a span of 20 minutes, I believe the guys out there are "testing", that they can indeed turn the electricity off at will, just in case...

- Then there is official loadshading, which is somewhat a random function as well, the only certain thing about it is, "It will happen!"

- If you ever visit, rural parts, its a fun indeed, there you'd find something called "आकडा" hanging on a wire, whereupon a lot of villagers solve the problem of "distribution" by "pulling" the electricity, of course, they can do so only for a couple of hours in a day... thats महावितरण's way of settling the scores..

PS : This blog post was written un-interruped, oh well almost!

Monday, June 25, 2007

A very interesting blog post..

Here is a link from the post, called bono I read on the blog by Marc Andreessen, yeah the famous netscape guy, whose welcome message most of us have seen when we installed our Netscape Communicator (which was the best mail reader then...). When I first read the title, I thought marc is going to take us through yet another web platform or something, but this is about the "evils of development aid to africa from the western countries.." I believe there is a lesson for India out there to be learnt too.. A really great post..

Offtopic: I have heard about this book "Everybody loves a good draught", I think I should pick this up from Crossword this weekend.Though, I doubt whether they'd have it...

interesting facts about my birthday

One of my friends happens to have a birthday on 21st june. It happens to be the longest day in the northern hemisphere. In marathi it is called "कर्कदिन", I was looking for a name in english, it eluded me somehow. I couldn't find.

Wikipedia is a great place, it has got a page for all the days in a year, so out of curiosity, I happened to check the facts about my birthday.

Some interesting facts that I learnt..

I share my birthday with Charles Chaplin and Lara dutta..


3000 years before I was born, Odyssus returned to Ithaca after the "Trojan War"

34 years before I was born, the psychedelic effects of LSD were discovered on my birthday. Not bad on that one! :-)

Unfortunately, this is the day on which virginia tech massacres took place in 2007. Bad :-((

Interestingly the term "Cold War" was coined by Bernand Baruch thirty years before I was born! :-) awesome!!

There are some other facts as well : like "Launch of Apollo 16", "Chicago bulls" record breaking 70th victory, "syria gained independence"

Wikipedia does not mention one thing though "Abhijit Gadgil" was born on this day !!! Too Baddd...

Quite an eventfull day so to speak! :-)

Monday, June 18, 2007

RA-captcha - An idea for ajax based captcha for rails applications.

While working on a new feature for paahijen-Scratchpad, we needed a captcha mechanism to keep the spam-bots out of the door! Since some of our users may not be quite comfortable with typing convoluted roman alphabets, we needed a different system. Honestly, I was too lazy to try out all the Rimage giri to get something useful and somehow wanted a mechanism, which is lightweight, easy to implement (lesser code, no new learning.. ;-) ). Somewhere, I had read about "arithmetic" captcha, and we decided to use it. We just hit upon an interesting idea... to use Ajax for captcha.. Hence the name RA-captcha (rails ajax captcha)..

The idea is fairly simple.. What it basically does is uses link_to_remote to update the contents of a "div" in the form dynamically with a text for a simple arithmetic equation. The equations is so simple that a 5th grade average student can do them without troubles.. eg. the equation will be something like "8 + 2 = " and then an input text box is provided to enter the value.. Though this technique uses "link_to_remote", it is not too hard to use other ajax methods for the rails as the need be!

Here is a simple code that explains the idea... The code is not perfect and I am not a rails expert, Also it doesn't do any validations than minimum.

Create an application "ajax-test" using rails ajax-test

We are going to add a controller called "main" controller and corresponding views. For this example we don't need any ActiveRecord models.

script/generate controller main



We are going to create the view for this controller and action "index". No layouts..
So create a directory called main inside app/controllers and edit the file
app/views/main/index.rhtml with following contents.




<%= javascript_include_tag "prototype", "effects" %>


<h4>
<%= link_to_remote ( "Click to open form!" , { :before => "Element.show('test-form');",
:url => { :action => "getequ" },
:update => "equdiv" }) %>

</h4>

<div id="test-form">
<%= start_form_tag({:action => "submit_test"}, {:id => "t_form"}) %>

<%= text_area_tag "userinput", nil, :size => "20x10" %>

<p><b>Humans? Please do some simple Math!
<div id="equdiv"> </div><input type="text" name="capval" size="2" />
</b>
</p>
<%= submit_tag "Go!" %>
<%= end_form_tag %>
</div>

<script>
Element.hide("test-form");
</script>



The controller code looks like this.....


class MainController < ApplicationController

def index
end

def getequ
numbers = (0..9).to_a

@equ = ''
num1 = numbers[rand(numbers.length - 1)]
num2 = numbers[rand(numbers.length - 1)]

session[:capsum] = num1 + num2

@equ << num1.to_s + " + " + num2.to_s + " = "
render(:inline => @equ, :layout => false)
end

def submit_test
if request.post?
if params[:capval].to_i == session[:capsum]
@userdata = params[:userinput]
flash[:notice] = "your input is accepted!!"
else
flash[:notice] = "Sorry you got the math wrong! can't accept your input!"
end
end
# reset the sum so one cannot simply press 'back' buttton and re-use it!!
session[:capsum] = -100

end

end


There is an additional view defined for submit_post. Which looks like this...


<% if flash[:notice] %>
<%= "<><b> #{flash[:notice]} </b> </p>" %>
<% end %>
<% if @userdata %>
<%= "You just entered -- #{@userdata}" %>
<p> <%= link_to "again", :action => "index" %>



<% else %>
No input data click <%= link_to "try again", :action => "index" %> to start.
<% end %>



How this works is fairly simple. Basically, whenever the first link is clicked an action in the controller called getequ is called, which generates the equation string for us and stores the value for the equation in the session[:capsum] variable. When the form is subimtted, the value of the text field is checked agains the value stored in the session[:capsum] variable. If the values match, the input is allowed, if they don't match the input is not allowed and the view for submit_test is rendered accordingly..

Since, the value the user has to input is only available upon loading the page and updating div, this value simply will never be known to spam-bot to be used without actually loading the page..

---------

The idea looked so simple to me and pilot to be overlooked for so loong. May be there is a catch which I am not getting yet!! Hopefully someone will point out....


PS: Editing html on blogger is a big pain!! eg. it gets rendered. One way out is to change the "<" of each html tag with "&lt;" and then blogger doesn't try to render it.....

Thursday, June 07, 2007

The cost of inefficiencies

This has been my favourite pass-time to look around and find out inefficiencies that are out there and no one takes a notice of that and usually like to play with numbers how by getting rid of small inefficiencies we can make a lot of difference.

First and foremost one of the most common thing that you'd observe that the roads are not laid footpath to footpath (ie. where the footpaths exist), now what happens as a result of this is about 20 and sometimes as high as 30 percent of the road is not usable. Moreover, that also makes it possible for the hawkers to occupy the unused space and further agrravating the problem, if you lay the road footpath to footpath, you create a natural entry barrier for encroachment, because the vehicles start using that part of the road. Furthermore, one may really look at the size of a footpath. There is no real need to have a footpath three and a half feet wide, that only makes it obvious choice for a tapari. Instead if we just have a footpath which is just a little more than a couple of feets, it allows those two extra feets to be used by the vehicles. There is another advantage of laying roads end-to-end, the chances of developing potholes is reduced substantially, because, the rain water flows freely, leaving lesser chances for erosion. Just a small thing can make a substantial difference.

Next is the inefficiency a lot of us indulge in - eg. when we are standing at a signal ie. if we are standing at a signal, and if we know that our turn is going to take something more than thirty seconds, it might be prudent to switch off the engines. This saves a lot of petrol, consider a vehicle, which while idling consumes a litre of petrol every hour. which means 1000ml every 3600 seconds which means 1ml every 4seconds. so assuming you switch off the engine for 40 seconds you've saved 10mls worth of petrol, re-ignition might consume another half ml of it. But even then 5 ml is a lot of saving. Because if 10million vehicles save on an average 20ml per day, it is equivalent to 20000 litres of fuel saved everyday that is a lot. Again, a simple thing that can make a huge difference.

There may be 100s such examples. Actually, I always say this if the efficiency in the world is improved by 50%, we'd have to get rid of 95% jobs in the world. Perhaps, its human society's way of making sure that most of us are employed. :-)

Sunday, June 03, 2007

Officially Jobless!!!

So finally the time has arrived. I always maintained that those who don't get a KT in engineering and those who are not "officially jobless" for atleast a month, can't do much in life. Thanks to my निकम्मापन, I didn't manage the first thing and the second thing eluded me for some real good time. But, they say late is better than never and here I am finally, officially jobless!!

Before, some may have doubts about my employer, let me assert firmly that PANTA is doing really well and my being jobless has nothing to do with company's state, on the contrary I believe PANTA to do a touch better now, since the official पनवती is out! :-)

It was a tough decision to quit PANTA, since I was associated with PANTA India from the day 1 (rather it won't be inappropriate to call from the day 0). and it is kind of hard to accept that tomorrow I am not going to be going to the office and I am no longer part of the "grad school" named PANTA. But when the time comes, the time comes.

Being jobless does not mean that I am going to be workless, on the contrary, I have a fear that I might just get overwhelmed by the fact that I have so much to do and so much of time, so time management is going to be extremely crucial going forward.

Besides that I think I can dedicate all of my time to paahijen now, and we have a bunch of interesting things happening already and there will is going to be a lot more out there.

Looking forward to coming days, and I believe that these are going to be one of the most crucial few days.....