Saturday, July 28, 2012

byteman example : enable debug logging

A quick introduction to byteman: Built by the jboss community, it allows you to add code to your existing java program on the fly.

It is very handy in situations like:
  • You want to print a parameter value on the method (better yet, run a getter chain on it)
  • Change return value of the method
  • Know what's going on in code that you don't own
  • ...
This demonstration is to enable debug logging for log4j. Obviously there are other ways to enable debug logging for log4j, but it is useful in situations where you don't have write access to the config file, or you don't know what config file to change.

Here is a typical call to log something in debug - protected by a isDebugEnabled() call.

if (logger.isDebugEnabled())
{
    logger.debug("The parameter value " + param + " is valid");
}

We have to make sure the isDebugEnabled returns true, and then the call to debug goes through overriding the internal log4j check to verify if debug is indeed enabled.

Byteman works with rules, here we are creating two rules to make sure debug log is written.

Rule 1: make sure isDebugEnabled() returns "true"

RULE enable debug logging
    CLASS org.apache.log4j.Category
    METHOD isDebugEnabled()
    AT ENTRY
    IF true
    DO return true
ENDRULE

Rule 2: call the forcedLog() when logger.debug() is called

RULE force debug logging
    CLASS org.apache.log4j.Category
    METHOD debug(java.lang.Object)
    AT ENTRY
    IF true
    DO $0.forcedLog(org.apache.log4j.Category.FQCN, org.apache.log4j.Level.DEBUG, $1, null)
ENDRULE

Attach byteman to your jvm: The following command will deploy byteman agent into your running jvm (pid), and listens at port 6666. More help here

java -jar lib/byteman-install.jar -h localhost -p 6666 --pid--

Deploy the rules file:
java -classpath lib/byteman.jar:lib/byteman-submit.jar \
    org.jboss.byteman.agent.submit.Submit \
    -h localhost -p 6666 -path to script-

Now, debug logging should be enabled for all categories now. If you want to filter only a certain logger, you can modify the rule which returns true on isDebugEnabled as follows

RULE Enable debug logging
    CLASS org.apache.log4j.Category
    METHOD isDebugEnabled()
    AT ENTRY
    BIND constant:string = "NAME OF MY LOGGER"
    IF $0.getName().contains(constant)
    DO return true
ENDRULE

When you are done, remove all the rules

java -classpath lib/byteman.jar:lib/byteman-submit.jar \
    org.jboss.byteman.agent.submit.Submit \
    -h localhost -p 6666 -u

That's it, download Byteman and instrument your code.

Saturday, February 12, 2011

A Train to Catch

One of my not-so-much-of-a-morning-person friends had to catch a train at 6am every Monday. The thought of the merciless train that will leave him behind, scared him enough to make sure he never missed it. That got me thinking - discipline - forced or not, he had it.

Tuesday, September 14, 2010

Only in Rome...

Had to post this picture! Found this advertisement for scooter rental on the streets of Rome! Only in Rome can anything like this can be pulled off!


For those who don't know, the picture here is one of Michael Angelo's famous paintings depicted on the ceiling of the Sistine Chapel in Vatican City.

Wednesday, September 8, 2010

I always thought I don't like ice-cream ..

And then there was Paris. Bidding 'au revoir' to Paris, all I can think of are the ice-creams and sorbets I had. The first spoon of melon sorbet was a melon explosion in my mouth. I had never tasted anything like it other than the fruit itself, and this was much better. The sugar content was just right, and surprisingly, the one thing about cold things I don't like - the coldness - didn't bother me. I was enjoying it so much that Madhu was truly jealous that she chose panna cotta instead. The panna cotta ice-cream she got was good too - light, creamy and just right.

After our first taste, we tried many many others - mango, passion fruit, pistachio, caramel - they were all scrumptiously good.  And, I enjoyed ice-cream as never before!

And we ate, and we ate and we ate...

No matter what you taste - from a blueberry muffin to a penne with tomato basil to a raisin cake to a warm apple galette with ice cream - everything tastes special - from a road side hole in the wall to a nice sit down restaurant, the quality and flavor of food is mind-blowing.
The flavors are always spot on. Not too greasy or sugary. And when your waiter says something is spicy, you better believe it. There is also a great variety of food here. As vegetarians, to say we were apprehensive of our chances for good food in Paris is saying it mild. Paris really surprised us, from the libyan galette with zatar to crepes with cheese, eggs or with nutella to falafel, there is great street food at low cost anywhere you go.

Having cash at hand definitely has its advantages, a glass of wine will cost you €3 at the bar when the same might cost you double if you order it from your table! A crepe from a small street side vendor (with a couple of tables) is better taken to go than use their table. If you want a quick picnic, hop into a neighborhood boulangerie for a baguette. Don't forget to get some cheese at the fromagerie next door. Oh, how about those macarons at the patisserie across the street? There you go, doesn't that sound perfect? A cherry on top would be to pick a great spot - the gardens in front of Eiffel tower, along the banks of Seine or just any neighborhood park. You can't go wrong in Paris.

By the way, once you get a table at a restaurant, they don't expect you to leave anytime soon, they don't give you a bill unless you ask for it. You don't really have to leave after you pay your bill! And no tips, service charge is included. We always rounded off the bill, but there is no expectation of that too.

I did not see anyone hurry anywhere except on the subway. Maybe even that was to get the best street-viewing spot at their favorite cafe? I don't know how the French do it, but I am amazed by how much they enjoy the simple pleasures of everyday lunch, always taking time for food, chatting with friends and of course wine with a cigarette alongside.

Saturday, September 4, 2010

Paris and the culture shock!

Have you really planned well? Think again, if you don't speak French, you can easily get lost here. After buying like what seemed to be the train tickets to Paris from an automated machine, we accidentally disabled them by walking in out of the ticket protected area of the station! oh boy! €17 down the drain? The people at the kiosk were kind enough to speak English, we were on our way!

The metro system is really good - but only after you get a hang of it. The tickets that we bought were supposed to take us all the way downtown, but not knowing that we were trying to buy a transfer ticket when a proactive old man saw us blank faced at the ticket counter and set us on the right course before we boarded the subway! The people are very nice too! Thanks mystery old man, you saved us some money and a lot of time.

The noise level is amazing, like New York! People are loud and happy - on the subway, on the street, in the cafe! It really reminds me more of Bangalore atmosphere than anywhere else. The subways and the streets are crowded, with tons of people everywhere. Living in the US, we had forgotten how it feels to be surrounded by so many people. Even though we had read about all of this, experiencing it is a whole different matter altogether.

Smoking is as common as chewing gum! Out of the airport, the smell of smoke is everywhere. Both of us being non-smokers, it was a bit overwhelming. The crowded cafes where the tables are so close that if you are not careful, you can knock a glass on the next table (well, Madhu actually did that :) ), it is hard to ignore the smoke right next to you!

People sit at the restaurants for hours, enjoying each others company, with no sense of urgency whatsoever! This was a nice change from our regular lives where going to a restaurant was really just to eat!

We are really liking Paris so far.

Friday, September 3, 2010

And off we go!

Sept 3rd '10 6pm, finally the much anticipated time has arrived, and we are all packed and ready. Can't wait for the flight crew to start boarding and fly out way to Paris.

Paris, Rome, Venice, Pisa - the names that I had heard so many times in my history lessons, and have seen gazillion pictures over the years - The dream is about to come true, and we will be there in person, watching the magnificence of European history (okay, I really mean food) and contemporary culture.

To soak up as much culture as possible, we have decided against driving in Europe. Taking trains all the way, and traveling in public transport should give us a chance to interact with the people, and force us to eat when we are hungry at the local restaurants.

That does not mean that we did not plan! Oh, believe me, we planned like there was no tomorrow. Walking into a strange country may not all be very romantic if we are stranded on the streets looking for a hotel. We have a few long distance trains booked, all the hotel rooms are ready and not to mention the flight to get us to Paris and back to San Francisco from Vienna. It was a long and hard task, one which should not be taken lightly if you are planning such a trip.

I hear the metro system is one of the best in Paris, and we are somehow fairly confident that we can find our way around in France and Italy. We know a few phrases, and we have read about a few gotchas. I completely understand it when people say that French people are easily offended when you start speaking to them in English. It is fair for them to expect foreigners to attempt speak in their native language first, before switching to English. So, I know I have to politely ask if they speak English before I blabber along my question about where the train station is! "Je parle peu le français, parlez-vous anglais?" (Don't quote me on this, my confidence level is as good as translate.google.com)

Seriously, why don't they board already? Signing off!

Wednesday, August 25, 2010

Estimating and deciphering your Amazon Web Services bills

We started using amazon web services at SpikeSource, and a large machine running in one of the zones just went unnoticed until our monthly bill!

The monthly bill told me that I had run a large machine on the west zone for 110 hours - didn't tell me when! There are no controls on amazon to setup alerts to check if "I have left the lights on"

The usage reports that amazon lets you download have cryptic codes that is not easily understood by just staring at the csv (or xml) - Example below.


Now, it would have been nice if amazon provided me with a better idea on when and where my money went! Something like the graph below would be fantastic!

Amazon does not do that, but we do! These are some screen-shots from our SpikeSource's awswatch service. This service is completely free, and gives you a overall picture of your spendings by the hour, for as long as amazon provides you the usage report for.

You can also monitor your images for cpu, memory, data transfer and disk usage.

If you need a simple cost estimate, we have the simplest calculator you can find to give you a ball-park figure for your

Head on over to http://awswatch.spikesource.com/ and try our service, let us know what you think - It is FREE!

Thursday, May 27, 2010

TestGen4Web: A million downloads and counting

Today, my TestGen4Web moved past a million download mark on our developer website. It has come a long way since the original idea of just automating your actions on the browser.

To mark the occasion, Calvin got me ten '100 Grand' chocolate bars :)

A quick word about what the tool does: TestGen4Web is essentially a recorder of your actions on the firefox browser, and can play it back (you know, like your DVR). The extension also comes with a editor where you can create loops, add conditions, parameterize data and load datasets - essentially creating a functional-test. The test can also be run on the command line using a companion tool which I call htmlunit-interpreter and run them without a browser.

The first time I thought of this was at my first job, at which, reproducing a bug would take at least 10 clicks and 5 text box entries. I realized that it really was not an effective use of time (duh!).

Those were the glory days of Internet Explorer, and I wrote a vbscript to open the browser and control the elements in it. The first version was a set of library functions to "click the 3rd link", "enter text in 5th textbox" and so on. Writing such tests was still manual.

When Firefox came out, it brought with it the concept of wrting browser plugins. I realized that these were exactly the carrier I was looking for all along. Running with the same permissions as the browser was exciting, and a similar automation use case came up prompting me to write the first version of 'testgen4web' (short for Test Generator for Web applications).

Now at version 1.1.0 (download here) with more than a million downloads over all the versions, its come a long way. Thanks to SpikeSource for providing me the platform, and thanks to users for .. well, using it.

Here is Keisuke's schematic rendering of the project summary. Published on our developer site.

Thursday, February 18, 2010

thunderbird-3 hack: fix number of addresses shown before the "more" link

If you use thunderbird 3, you may have noticed an annoying link labeled 'more' on every address category (to, cc) after just 1 address is listed.

Friday, February 12, 2010

My simple python driver for my touch screen input

The story begins when I got a laptop (netbook I should say) with a touch screen from a company named "MosArt"

A version of 64-bit windows 7 came pre-installed on it, and the touch screen worked pretty well - it had its moments, but worked.

I installed ubuntu on another partition, and expected the touch screen to work out of the box. But doesn't look like anybody has heard about the company yet (could not find any references to them by regular searches). It was time to write my own driver.

Wednesday, February 10, 2010

Simple HTML Tabs

Ever wondered how those tabs are created in html? You can create tabs very easily using html list elements

Here is a screenshot of simple html tabs

All you really need here is to create a unordered list (UL) with class attribute set to "nav" and the list element (LI) with class attribute set to "selected" for the tab you need selected.

<style>
    ul.nav { border-bottom:1px solid gray; }

    ul.nav li {
        display:inline;
        position:relative;
        padding:5px 5px 5px 5px;
        top:-5px;
        border:1px solid gray;
        background-color:lightgray;
        margin-left:5px;
    }
    ul.nav li.selected {
        background-color:white;
        border-bottom:none;
        top:-4px;
    }
</style>
<ul class="nav">
    <li class="selected">Tab 12
<li>
    <li>Tab 2<li>
    <li>Tab 3<li>
    <li>Tab 4<li>
</ul>

The above html was generated using vim - for those who are interested, vim can generate html with syntax highlighting with a simple command


:runtime! syntax/2html.vim

Tuesday, January 26, 2010

Remaking a classic? My advice? Stop, think

When I was a kid, the only television channel was doordarshan. In 1988, there was a national integration video produced called Mile sur mera tumhara.

The national integration video was intended to instill a sense of pride and promote unity amongst Indians, highlighting the different linguistic communities and societies that live in India -- India's unity in diversity, so to speak.



This video was really done well, and in my perspective, it did achieve some of its goals, and if not anything, it still feels good to hear the sound.

Now, someone tried to make a sequel of this, and it has gone horribly horribly bad. Here is the link for part 1 - 8 mins, yes there is another part - totaling 16 minutes. Not all 16 minutes are a total waste of time, but the overall production quality sucks big time.

Could not understand many things:
1. Salman Khan in his undershirt
2. Deepika Padukone in skimpy clothes
3. Really bad music at a lot of places
.. and the list goes on.



Why remake a classic? You know you can't beat it. Have you run out of ideas? JUST PLAIN STUPID.

Tuesday, January 12, 2010

Weave - best plugin firefox ever had

Almost everyone I know have a work computer, and a home use computer or a laptop, and the problem of synchronization is too well known.

You are looking up something at work, go home, and can't remember the url? The bookmark on your work computer is not available on your laptop at home?


Mozilla Weave solves the problem for us. It can synchronize and merge your bookmarks, browsing history, passwords, preferences and more across one or more of your profiles on the same computer or across computers. All you need is a weave-account and the extension installed on all the profiles that you want synchronized.

It has simplified my browsing life more than I could imagine. Try it out for yourself. 

https://mozillalabs.com/weave/

Mozilla Weave enables you to have incredibly rich, personalized experiences across the web.

As the Web continues to evolve and more of our lives move online, we believe that Web browsers like Firefox can and should do more to broker rich experiences while increasing user control over their data and personal information. Weave is a Firefox add-on that is aimed at exploring this opportunity.
Some of the key functionality enabled by the Weave add-on includes:
  • Synchronization engine - securely transports your browsing experience across all your devices
  • Cryptographic engine - provides default client side encryption for all your data
  • Weave server - a secure storage location for all your encrypted data
  • APIs - extension interfaces for 3rd party developers
The initial release will provide extensive support for your browser meta-data (bookmarks, stored passwords, history, tabs, preferences, add-ons, personas).
Future releases will support other types of data and functionality.

Thursday, October 22, 2009

Non believers and believers, can't we all just get along?

Just my perspective, debates welcome.

A believer has not many questions to think answers for, they have one black hole - God - that they can throw the question at it gets sucked into the mysterious nowhere, and they breath in relief.

A non-believer on the other hand, has a lot to think about. Just for starters, a way to prove to the believers that there might not be a God at all. This is a bit strange because the way I know it, unless shown something does not exist, and its be believer's responsibility to do so - like the bigfoot - most of the world does not believe in it, but the believers try and keep the news alive with a sighting, with a foot mark, with a long range blurry picture.

Wednesday, October 21, 2009

You see what I see? Search war?

Microsoft today struck a search deal with twitter and facebook -
.. Microsoft has reached collaboration agreements with Twitter and Facebook to get their members' public status updates and messages indexed and presented in useful ways on the Bing search engine...
Read more here: http://www.pcworld.com/businesscenter/article/174061/microsoft_strikes_search_deals_with_twitter_facebook.html


And Google posted this on their offical blog
... we are very excited to announce that we have reached an agreement with Twitter to include their updates in our search results....
http://googleblog.blogspot.com/2009/10/rt-google-tweets-and-updates-and-search.html

Seems to me that twitter integrated with both search engines, and not the other way around :) Oh! well, what do I know!

Tuesday, September 15, 2009

Call me crazy, but I jumped

Jumped off a 40 foot cliff at the southern most point of the United States! Risky, might not do it again, but could not resist the temptation at that time! Madhu took the pictures.

Full size pictures here:
http://picasaweb.google.com/vinayms/MyCliffJump

Friday, February 20, 2009

Pronounce Linux as Linux

I have heard a lot of pronunciations for "Linux", anything from Lienux, Lienex to Linux - I always wondered who was right, until I heard it from the creator - Linus Torvalds

http://www.paul.sladen.org/pronunciation/
Listen for yourself: http://www.paul.sladen.org/pronunciation/torvalds-says-linux.wav

Monday, February 2, 2009

Sorry, you are not my [blood] type!

A conversation in a Japan's night club, could go something like this:
Boy: Hey there, what's your [blood] type?
Girl: I am a A, and you?
Boy: Sorry, you are not my type [literally]

Japan, as advanced as it is - is apparently obsessed with blood types of people

Ref: http://www.physorg.com/news152723712.html
In the year just ended, four of Japan's top 10 best-sellers were about how blood type determines personality, according to Japan's largest book distributor, Tohan Co. The books' publisher, Bungeisha, says the series - one each for types B, O, A, and AB - has combined sales of well over 5 million copies.

Some employers are discriminating on assignments to employees based on the blood type! Even children at schools are reportedly grouped based on blood type!

I used to laugh at Linda Goodman's Joke books, still do! But this Japan obsession is no joking matter at all, this is really at the core racism. On second thoughts, we need another word for it - because the color of blood is really the same.

Monday, September 29, 2008

[link] Renting Makes More Financial Sense Than Homeownership ?

While in the back of our head we are still contemplating the idea of buying a home, I came across this article explaining why Jack wants to rent until a foreseeable future instead of owning a home.

Following is his summary, but the article is a good read. He does answer common questions that people might have like "home owners get a tax break.", "why throw money down the drain", "I just made a tonne of money selling my home, you are wrong!".

Shares right now cost 16 times earnings and over long time periods return 7% a year after inflation. Houses right now cost 19 times their "earnings" and over long time periods return zero after inflation. And they look likely to return less than that for a while.

Read on:
http://realestate.yahoo.com/promo/renting-makes-more-financial-sense-than-homeownership.htmlLink

Wednesday, January 9, 2008

[link] Why we eat the way we do

The found this article through a reference -

The author Ruth N. Davidar is a nutritionist and a food writer. Explains how vegetarian indian cooking compensates for the nutrition the body needs as compared to meat based cooking.

http://www.hinduonnet.com/folio/fo0004/00040260.htm

Some excerpts from the article:

Experts will also tell you to watch your intake of iron and calcium in vegetarian diets. Here again, typically Indian food combinations help with the absorption of these minerals. True, the availability of iron from vegetable sources is never very satisfactory, but vitamin C, for instance, helps to overcome this problem by assisting in the conversion of iron to the form that is readily absorbed. In aloo aur palak ki bhaaji the iron that is trapped in spinach is released by the vitamin C found in potatoes. Likewise, substances like oxalates prevent the absorption of calcium (and magnesium) abundant in green leafy vegetables. A traditional Indian recipe like palak paneer circumvents this obstacle. While the calcium in the greens remains in the bound form, the calcium in paneer is readily and easily absorbed.

Interestingly, curds is used extensively in Indian cooking. It could be assumed that milk was allowed to ferment to make it more palatable because of the lack of refrigeration in the old days. However, it has significant nutritional benefits too. When milk sugar or lactose is allowed to ferment naturally, lactic acid is formed by the activity of certain bacteria. This lactic acid promotes the absorption of calcium especially when phosphorus and protein are also available in the same food. Milk that is converted into curds has all these factors - another reason why getting sufficient calcium from a typically Indian diet is not a cause for concern. Further, curds used as a marinade does not just flavour and tenderise foods like meat. It is now known that lactic acid (as found in curds) is an effective antiseptic when heated (as in cooking). Therefore, meat marinated in curds and then cooked would have fewer micro-organisms.