Groovy : Invoking One Script From Another

It was like one of those Aha! moments when I finally found how to invoke one script from within another. It is so simple!!

Say you have a script RunScript.groovy which is as follows:

        package com.singhanuvrat.sandbox

        println "Whoa!! ${input}"

Now you want this RunScript.groovy to be called from CallerScript.groovy with different values for the variable input. Our script will be:

        package com.singhanuvrat.sandbox

        GroovyScriptEngine gse = new GroovyScriptEngine("src/com/singhanuvrat/sandbox");
        Binding binding = new Binding();
        binding.setVariable("input", "world");
        gse.run("RunScript.groovy", binding);

Infact, using the binding, we can also extract value of variables from the called script. Now we shall have fun! :)

Popularity: 1% [?]

Unanticipated Delivery Of A Futures Contract

A story as told by John Hull in his book Options, Futures and Other Derivatives.

This story concerns a new employee of the financial institution who had not previously worked in the financial sector. One of the clients of the financial institution regularly entered into a long futures contract on live cattle for hedging purposes and issued instructions to close out the position on the last day of trading. The new employee was given responsibility for handling the account.

When the time came to close out a contract the employee noted that the client was long one contract and instructed a trader at the exchange to buy (not sell) one contract. The result of this mistake was that the financial institution ended up with a long position in two live cattle futures contracts. By the time the mistake was spotted trading in the contract had ceased.

The financial institution (not the client) was responsible for the mistake. As a result, it started to look into the details of the delivery arrangements for the live cattle futures contract – something it had never done before. Under the terms of the contract, cattle could be delivered by the party with the short position to a number of different locations in the United States during the delivery month. Because it was long, the financial institution could do nothing but wait for a party with a short position to issue a notice of intention to deliver to the exchange and for the exchange to assign the notice to the financial institution.

It eventually received a notice from the exchange and found that it would receive live cattle at a location 2000 miles away the following Tuesday. The new employee was sent to the location to handle things. It turned out that the location had a cattle auction every Tuesday. The party with the short position that was making the delivery bought cattle at the auction and then immediately delivered them. Unfortunately the cattle could not be resold until the next cattle auction the following Tuesday. The employee was therefore faced with the problem of making arrangements for the cattle to be housed and fed for a week. This was a great start to a first job in the financial sector!

Popularity: 1% [?]

Ted Talks : Sheena Iyengar on the art of choosing

A rose by any other name looks different, and probably also smells different.

Sheena Iyengar through her studies on culturally and geographically different people tries to discover the effect choice has on people. Its all a matter of perspective she says. She demonstrates this by considering the 3 assumptions of choice:

  • Make your own choice
  • More options -> Better Choices
  • Never say no to choice

Speaking for myself, in the first two points I am the anti-american kind of person. In a group, I leave the choice on the others. I care little about self happiness as long as most of the people in the group are happy. It is perhaps because of how I have been brought up. Dad made all of my educational choices. He told me what to study and mom dictated when I studied. And when we went out on a family outing or we bought anything, being the elder brother, I mostly let my brother choose. So the story of my life has mostly been that of adjusting to the choices made around me.

As for the second assumption, once again I do not believe more options make it easier to choose the best product for yourself. In fact, lots of options scare me. Unless two things are vastly different I cannot choose one from another. If you ask me choose between two varieties of black leather bag that look almost the same, have almost the same number of pockets, etc; I will come up blank. Similarly, if you ask my opinion on which platinum credit card to have, I am sorry but they are all the same to me. INOX and PVR are the same to me as well.

The third one I have not yet formed any opinion. I do not really agree with the study she did to elucidate that point. I do not like the idea of having no choice. After all, I should be able to change things if I get uncomfortable. But yes, at times it becomes easier when someone else makes a choice for you. When I got a rank of 404 in IIT JEE entrance exam, I was pretty happy until dad told me of the tough choice I had to make – Electrical in Madras, or Computer Science in Kharagpur. At that time it was a very tough choice to make. I let dad make the choice for me, trusting his decision, which considered introspectively, was the best decision. He was able to make the correct decision because he knew of my interest in computers.

I think people should always have the right to choice. But they should learn when to exercise the right them self, and when to let others make it for them.

Popularity: 1% [?]

My Code Rules – Code Documentation Check

As a fresher at FICO, Rahul and I had developed a java source code analyzer named My Code Rules. The objective was to develop a rule engine which would apply a set of rules to find inconsistencies in a given set of java source files. An API for writing of new rules was also developed. A few sample rules were created by us to show the effectiveness of the rule engine.

Now one of the rules was to check if the methods have been documented or not. One could provide in a config file the type of functions [public, private, protected, all] that needed to be analysed The rule engine would then look up all the filtered methods and display as a table the list of methods that had not been documented.

Configuration of My Code Rules

Output Of My Code Rules

I finally got to use the tool today :) . I needed to check if I had documented the my code. This tool quickly listed all the methods that needed documenting. I searched for the ones I had added and my work was done!

Sadly though, I have never had the time to improve the tool. Both Rahul and I were new to java when we wrote the tool, and our amateurishness shows in our design and the implementation. After Rahul FICO, the old code was beyond repair. I tried a fresh approach, correcting the previous errors, trying to look ahead, but it requires a lot of time and dedication. The project lives in a deserted state.

Popularity: 1% [?]

Bichku is an Abbreviation?

I knew that Udit is nicknamed Bichku. Until yesterday I hadn’t realized that I did not know the origin of the nick. It was revealed to Birinder and me that it has a full form! And what more, his earlier name was Hichku!

Sadly, I still do not know what they stand for. That’s one more thing on the list that I need to find out.

Popularity: 1% [?]

F1 2010 : Disgraceful Act Of Ferrari In German GP

I have been a Ferrari fan for as long as I have watched F1. But I cannot condone the way Ferrari shamelessly asked Massa to give up his lead and let his team mate win. It was so blunt and straightforward message that even a fool would understand it.

Fernando is faster than you. Can you confirm you understood that message?

They did not even try to hide their intention. And since the transmission radio is now open to public, everyone heard it. And our very professional Massa slowed down his car and let Alonso pass.

Good lad. Just stick with it now. Sorry.

Was how the Ferrari pit crew appreciated this cowardly act.

A lot of things happen behind the curtains in F1. Although team orders have been banned after the Michael Schumacher [Ferrari, Australian GP], teams do send out coded messages which reveal such intentions. However, these are usually done towards the end of the season, when only one of the drivers have any chance of winning the championship. Such a decision is understandable. But to enforce such ordering at just the mid season is just wrong.

But I refuse to point the blame at only Ferrari. Everyone, including Alonso and Massa, were guilty of showing us a manufactured race. Just a few laps ago Alonso had tried a passing move on Massa. However, a couple of corners and Massa was able to regain his lead. Alonso’s reaction to this on his radio was

This is ridiculous!

Clearly, Ferrari must have set the driver orders even before the race started, and when Massa overtook Alonso, whereby defying the team order, Alonso was irritated. And if we couple this incident with Luca Montezemolo’s statement just a few days ago saying Ferrari were still aiming to win the championships leaves no doubt that Massa had been made the scapegoat. This does not augur well for a F1 fan.

Alonso might have been quicker than Massa, but that does not mean he has the right to be ahead of him. The highest paid driver should have fought for the position, and given a faster car, if he really had superior skills he could have forced Massa into an error and taken the lead.

I blame Massa for not having the balls to stand up to the order. He has been with Ferrari for so many years, and yet gets treated like a secondary driver. I am no Massa fan. His response to the media saying he is a professional just doing his job, cuts out a sorry figure of a guy who just the last year was made a Ferrari hero. He should have spoken out like Webber did in the last race when the team favored Vettel.

Ferrari is set for a hearing with the WMSC. Whatever the ruling of the committee is I hold Ferrari guilty of fixing a brilliant race. Massa had started the race well, and he did deserve to win the race.

Popularity: 2% [?]

Auto Problem In Bangalore ?

I have not used this system myself, yet.

A friend forwarded me this letter:

You are in a hurry to catch the train. You pack all your stuff and frantically run out in the hope of catching an auto. You come out and see 5 autos standing at the corner. You thank God and ask them – “Majestic chaloge kya??” The Answer is “Rs 200 hoga!!”. “Kya?? It just cost Rs 100 till Majestic”. “Bahut rush hai sir!!”. You move on to the next auto, to try your luck and surprisingly, you have the same conversation “Bahut rush hai sir!!”. Finally you give up and bargain the price to Rs 170 and hope you don’t miss your train.

Sounds more than familiar??

You stand on the road and keep on asking the passing autos for a ride to your destination – if it’s not your day, the autos will not even bother to stop; if you’re a bit lucky they might actually slow down to hear your destination’s name and think for a second( i always wonder if they are calculating their net profit) and then speed away. However if you are more lucky, the auto guy might actually quote you an exorbitant price and then speed away. But if it’s your extremely lucky hour of the day, you might end up getting an auto which is ready to take you to the destination at meter price.

In my six years of existence in Bengaluru, these experiences have been really instrumental in teaching me great virtues – Patience and Tolerance. But at what price??? exorbitant rates, extremely rude behavior and what not …… After years of feeling used, i set out to find the answer for this misery – was there no government system that could bring these auto guys to justice? As a citizen, how can i express my concern?

This search took me to the Koramangala RTO office (BDA complex) and to my surprise i found that there did exist a government system which i believe 99.99% of Bengaluru is unaware of !!

Note the vehicle number (KA-XX-YY-ZZZZ) and email the details to transcom@kar.nic.in. Based on the prefix XX (for example KA-01), complaint will be sent to one of the ten RTO offices in Bangalore and adjacent taluk areas. Alternatively, one can also call these offices at the number given below based on the vehicle number prefix and directly lodge a complaint.

Vehicle Prefix (KA-XX) Bangalore location Phone number
* KA-01 Koramangala 080-25533525
* KA-02 Rajajinagar 080-23324104
* KA-03 Indiranagar 080-25254310
* KA-04 Yeshwantpur 080-23376039
* KA-05 Jayanagar 080-26630989
* KA-41 Gyanabharthi 080-28602833
* KA-50 Yelahanka 080-28561366
* KA-51 Electronic City 080-25735522
* KA-52 NeelaMangala 08234-285598
* KA-53 KR Puram 080-25617951

Once the complaint is received at the corresponding office, a notice is issued to the address of the vehicle’s registered owner, requiring him/her to turn up at the RTO office within 7 working days. Every RTO has about 10 IMV’s (Inspector of Motor Vehicles) who seize the vehicles which don’t report to the RTO.

The penalty levied from the auto-waalas is rs.100 under section 200.

The various offences among others for which one can lodge a complaint
* Refusal to come to destination (Any destination!!!)
* Demanding excess fare
* Using rough language
* Cheat the public, for e.g. taking longer routes.
* Faulty Meter

There is also a helpline number – 080-22353785 available Monday – Saturday from 10:00 am – 5:30 pm on which one can call to lodge complaints.

Popularity: 2% [?]

Proxy Setting In Google Chrome

For some reason Google have decided to use the network settings of windows. So when you try to configure proxy you are taken to the internet explorer settings. Now in my case, the company has set a default proxy and I am not priviledged to modify or bypass it. And this proxy had blocked web-mail sites like gmail. And since chrome was using the same proxy settings, I was unable to access gmail on chrome as well.

Mozilla had no problem as I could select the “no proxy” option in its network settings and choose not to use the system proxy. I needed something similar for chrome as well. Some googling around and I found the solution.

Simply append

--proxy-server=

to the Target field, which can be accessed by right clicking the chrome icon and selecting the properties option. Now I can happily access my web-mail from within the office.

Popularity: 3% [?]

Chelsea Song – Blue Is The Colour

Popularity: 2% [?]

Testing Code Using Serialized Objects

After having written few new methods to enhance a functionality, I needed to test the code. Now the app requires dataset, binning library and various groovy nodes for initialization.  Also it does a lot of pre-processing. So there were two options for me -

  • Hack the code to insert special test methods at a particular point.
  • Write a test class which does all the initializations and then runs the app

I did not want the run the whole app. All I wanted to test was if my methods were running fine on one iteration or not. I did not want to wait for 10 minutes to wait for the algorithm to complete and then look at the log files to see the impact.

What I did was serialization of all the objects required by my methods. It required me to hack the code and write a few lines serializing the various maps, data structures and stuffs. But with that done, all I now need to do is to deserialize these objects and get whatever I need to test my methods.

Simple! I can now write small, neat methods whose purpose is only to test the particular methods without running the whole algorithm.

Popularity: 2% [?]