Archive

Archive for the ‘Hacks’ Category

DevCamp 2010 by ThoughtWorks Inc., Chennai.

July 11th, 2010 No comments

Developer Camp 2010
10th July 2010, Chennai

It was my first attempt to take part in a BarCamp / unconference, which excited me very much after reading about them in Wikipedia.  Through some contacts, I was invited to attend the Developer Camp hosted by ThoughtWorks Inc, at Thiru Vi. Ka. Industrial Estate, Ekkattuthangal, Chennai on 10th July 2010.  I had originally offered to give a couple of talks on Text mining and Design patterns.  Though I had some anxiety about whether topics like Text Mining would sell amongst hard core developers, I was comforted by Balaji Damodaran (organizer) that there should be a lot of people interested in exploring AI.

    I reached ThoughtWorks office at 9:15AM and was surprised to find atleast a couple of dozen developers already come in.  Saturday morning for hard core developers start only after 11AM, but I was happy to be wrong then :) Registered myself as one of the developers and opted to talk about “Text Mining Applications”, “Plagiarism Detection”, “Text Classification using Naive Bayes”, “Design Patterns” for the 9:30AM slot.  The unconference started at around 9:45 with the introduction by Balaji Damodaran.  At that time, atleast 70 developers were there in the hall (cafetaria).  Then I was asked to start the talk by 10AM.  When I went to the hall, it had only 5 people as audience, which kind of killed me as I am always used to having big crowd as my audience (what an EGO I have!?).

   I had asked a couple of the audience boys to go for hunting more audience for the talk.  See I were to advertise and promote my talk, which in fact is critical for everything in the world we live.  One of the volunteers advised to use a microphone and start the talk.  When I started the talk, I was surprised to see that people walked in to fill up the hall.  The talk went on and on with a lot of interesting examples which made everyone introspect about the way we see and assess our neighbourhood.   I am sure my audience have understood now that everything that we see around and solve could be mathematically modeled and be solved using computers.  Hurray, we made it!!

    Followed by that talk, I was asked to talk about Design patterns as a lot of developers had voted for that topic.  Ok, I wanted a coffee break! Went to the cafeteria and made some light south Indian coffee.  I added some pulverized sugar to my coffee and came back to the hall, while I was talking with another developer from LatentView technologies.  To my surprise, the coffee tasted like made with sea water. Then I realized that I had added salt instead of sugar.  I would like to greet the “brahaspathi” who kept the salt bowl near the coffee vending machine. :)

    The talk on Design pattern started in a small room as the number of votes was ~10 (which is still a large number) in unconferences. When we started that talk, one of the volunteer said, he would want to record the talk which is a good idea. The talk started, and we found that lot of people started to come into the room and we had to move to a bigger hall as the number of audience was over 40, which is like “wow”. The talk went on for a while and we interacted about Singleton vs Multiton, Strategy, Factory vs Bridge patterns with lots of examples. Overall, it was a wonderful discussion forum where we learned a lot of insight about software design using design patterns.

    If I were to use one word to describe the audience, I would say “intriguing”.  It was an awesome experience for me to talk about some of my experiences to a wonderful audience that you had brought it.  It is very rare to find a combination of patient, smart, involved, intelligent, experienced audience who crave for knowledge.  Our talks helped us to introspect on to the technology that we have been practicing. The ambiance was very motivating in the sense, lot of natural light and spaciousness.  Overall, I enjoyed every bit of it.  I am little depressed that I could not enjoy the food as I was rushing back to office.  Also, I wanted to take part in the fish bowl about Industry-Academic Co-op, but couldn’t.  I am sure, there is a lot of people who got benefited by this program, in fact I heard that statement from a lot of the audience after the lecture/talk.

Thanks to Shiv Deepak for introducing DevCamp.
Thanks to Balaji Damodaran for inviting me to the DevCamp.
Thanks to Shaswat Nimesh for the photographs.

EFYTimes news article is here.

Powered by ScribeFire.

Thunderbird Battery Charger

June 30th, 2010 No comments

Powered by ScribeFire.

ACE 5.6.7 does not compile with STLport in Win32 environment

June 14th, 2010 No comments

ACE 5.6.7 does not compile with STLport in Windows environment (I used vc9 on Windows Server 2008) because of the following header in ACE (ACE_wrappers/ace/checked_iterator.h), which wrongly assumes the existence of stdext::checked_array_iterator in the iterator header.  A PRF is already submitted in the ACE mailing list (http://www.archivum.info/comp.soft-sys.ace/2008-07/00026/%5Bace-users%5D-Checked_iterator.h-problem-with-STLport..html)

# if defined (_MSC_VER) && (_MSC_FULL_VER >= 140050000)
// Checked iterators are currently only supported in MSVC++ 8 or better.
#  include <iterator>
# endif  /* _MSC_VER >= 1400 */

# if defined (_MSC_VER) && (_MSC_FULL_VER >= 140050000)
template <typename PTR>
stdext::checked_array_iterator<PTR>
ACE_make_checked_array_iterator (PTR buf, size_t len)
{
return stdext::checked_array_iterator (buf, len);
}
# else
template <typename PTR>
PTR
ACE_make_checked_array_iterator (PTR buf, size_t /* len */)
{
// Checked iterators are unsupported.  Just return the pointer to
// the buffer itself.
return buf;
}
# endif  /* _MSC_VER >= 1400 */

#endif  /* ACE_CHECKED_ITERATOR_H */

I need to develop a solution to it.  The easiest way to find a solution is to use some macro explicitly set by the STLport header, which is not set by any other STL libraries.  I chose to use the _STLP_ITERATOR macro set by “stl/stlport/iterator” header.

#ifndef _STLP_ITERATOR
#define _STLP_ITERATOR

# ifndef _STLP_OUTERMOST_HEADER_ID
#  define _STLP_OUTERMOST_HEADER_ID 0×38
#  include <stl/_prolog.h>
# endif

# ifdef _STLP_PRAGMA_ONCE
#  pragma once
# endif

#if defined (_STLP_IMPORT_VENDOR_STD)
# include _STLP_NATIVE_HEADER(iterator)
#endif /* IMPORT */

# ifndef _STLP_INTERNAL_ITERATOR_H
#  include <stl/_iterator.h>
# endif

# ifndef _STLP_INTERNAL_STREAM_ITERATOR_H
#  include <stl/_stream_iterator.h>
# endif

# if (_STLP_OUTERMOST_HEADER_ID == 0×38)
#  include <stl/_epilog.h>
#  undef _STLP_OUTERMOST_HEADER_ID
# endif

#endif /* _STLP_ITERATOR */

The solution is the following, where I have added the !defined(_STLP_ITERATOR) condition along with the check for Visual Studio compiler version.

# if !defined(_STLP_ITERATOR) && defined (_MSC_VER) && (_MSC_FULL_VER >= 140050000)
// Checked iterators are currently only supported in MSVC++ 8 or better.
#  include <iterator>
# endif  /* _MSC_VER >= 1400 */

# if defined (_MSC_VER) && (_MSC_FULL_VER >= 140050000)
template <typename PTR>
stdext::checked_array_iterator <PTR>
ACE_make_checked_array_iterator (PTR buf, size_t len)
{
return stdext::checked_array_iterator (buf, len);
}
# else
template <typename PTR>
PTR
ACE_make_checked_array_iterator (PTR buf, size_t /* len */)
{
// Checked iterators are unsupported. Just return the pointer to
// the buffer itself.
return buf;
}
#
endif  /* _MSC_VER >= 1400 */

#endif
/* ACE_CHECKED_ITERATOR_H */

BSNL Broadband Connectivity Issue on Noise phone lines

April 10th, 2010 No comments

If you are an exclusive BSNL broadband user, you might not have attached the telephone to the phone line.  I have connected my Netgear modem to the DSL/Phone line splitter and left the other connection floating.  Lately, when I noticed that the Netgear modem was not able to make the connection with BSNL servers, originally I thought the telephone line is dead.  To my surprise the telephone line was fine, but I perceived the lines to be little noisy.  I made a complaint to the BSNL portal and as usual nothing much happened.  Accidently, I had to connect my telephone to the splitter for making a local call.  To surprise, the Netgear modem managed to connect to the server this time.  So, the hypothesis is;

When the telephone line is noisy, attach the telephone to the splitter along with the modem connection to get connected to the BSNL Servers.  Most likely it could be because of the Reactive load offered by the telephone on the phone line ends up conditioning the Phase modulated signals for the Netgear modem to connect to the Servers.

Powered by ScribeFire.

BSNL Broadband Unlimited usage

April 4th, 2010 No comments

Are you a BSNL Broadband user enjoying the 2AM-8AM unlimited access ?  Are you a person who has automated downloads programmed between 2AM – 8AM IST ? Are you seeing higher bill amount despite your carefully planning internet downloads during the unlimited access times ?  You should read this article for sure.

Do you know, you could track your internet usage on daily basis ? If not, register yourself at http://www.data.bsnl.in/. If you send the webmaster an email requesting for user account, you promptly get response within a couple of days with the required credentials.  You could login to the website to check your usage on a daily basis.  Infact, you can see your usage data for the past months also.  It is really very useful.  Alternately you could register your mobile number with BSNL and activate the notification service.   Upon activation, BSNL would send you SMS if your usage crosses the set-limit for your account.  See the following excerpts from BSNL website about this service.

If you are an user of BSNL Broadband and are not on any one of the unlimited plans, then you must keeping tabs on the data usage you have done. But what if you are on the move and not able to access the internet to check the data usage?

Simple, Send an SMS.

Yes, BSNL has now introduced a new feature where in you can now know your broadband usage via SMS.

How to Register for this New Feature?

Just SMS “REG Landline Number” prefixed with your STD code (For Example REG 080 23456789) to the following numbers:

52295: For Bsnl Mobile Customers.

9448077777: For Any Other Mobile Customers other than BSNL.

After Registering your landline number, you will receive a Thank you message and from then onwards, you can check the broadband usage of your account anytime by just sending an SMS.

How to Check the Broadband Usage of My Account?

Just SMS “BBU Landline Number” prefixed with the STD Code (EG BBU 080 23456789) to the following numbers:

52295: For Bsnl Mobile Customers.

9448077777: For Any Other Mobile Customers other than BSNL.

Note: This service is completely free, and you will be charged only for the SMS, based on your operator’s sms charges.

Coming back to the billing issue.  Lately, I noticed that I get very high BSNL broadband usage bills.  I wanted to keep a tab on that and sent a couple of complaint mails to BSNL billing.  But I did not get any response from them.  Following that I registered on the Broadband Usage statistics website mentioned before and was surprised to see that I had indeed used beyond my 2.5Gb limit (I have subscribed to 500C+ plan). 

When I looked the data usage pattern, I could figure out something very interesting about the way BSNL charges.  Consider that I have my automated download scheduled to start at 2:05 AM and stop at 7:55 AM.  I generally keep my machine in Sleep mode and have enabled the Scheduler application to wake up the machine for downloads.  Sometime, I keep the machine on over night.  I figured out that whenever I kept my machine on, I was charged for the usage even for the free-usage timespan.

Consider the case of a machine running over night.  When the machine is running the router to BSNL connection stays in “connected” state.  If the machine was in sleep mode, the connection is “offline” and whenever the machine wakes up, the connection is reestablished.  BSNL has setup the usage measurement exclusion only for the connections started after 2AM. Meaning if a computer was running over night and the connection status is “connected”, one may not get the free usage time-span.  Because the current connection is active and it was started before 2AM and hence the current connection is billable, as per the BSNL usage algorithm. 

The thumbrule here is: “Unlimited usage only for connections start at or after 2AM”.But interestingly, the 8AM connection is correctly handled by BSNL.  If you connection stretches beyond 8AM, the usage is billable for all the bytes transferred from 8AM onwards.

The following are the action points:

  1. Avoid running the computer over night with the connection is “connected state”. Because if the connection stretches beyond 2AM, you would not get the benefit of unlimited usage.
  2. Prefer to put the machine on sleep mode and make the scheduler wake up the machine for running your download tasks.
  3. Make the time of your computer synchronized with a standard time server like in.ntp.pool.org or time.windows.com
  4. Plan to start the download at 2:05 AM and stop at 7:55 AM
  5. Register on http://www.data.bsnl.in and keep a tab on your usage
  6. Register for SMS notification service

Powered by ScribeFire.

Restrict MSN file transfer

November 27th, 2009 No comments

MSN uses port 1863 to transmit messages and for file transfer.

Lot of people have said that the file-transfer using MSN happens via port range 6891-6900.  But when I experimented, I found that MSN is using same 1863 port.  Linux machines are able to identify this port as “msnp”.  I used “tcpdump” to verify this.  Whenever MSN attempts to send a file across the Internet, I creates several smaller packets (typically in the range of 536-1350 bytes) and sends them one after the other.  During the file transfer process, if there are messages (text or IM) to be transmitted, the message data block is piggy-backed on the file-transfer packets and sent across.

I was desperately looking for filtering the MSN based file-transfer for some official purposes and wrote some iptables rules based on the Internet literature that said file transfers happen via 6891-6900 by TCP.  Then, to validate the rules, I used tcpdump again on the gateway machine to monitor the packets that are originated from my machine. 
tcpdump src host dev02 -i eth1 -vvv
To my surprise, the file transfer was still happening also the ports are blocked.  Then I made an “iptables” rule to drop all the packets other than 1863 and repeated the experiment.  Still the file-transfer was happening.  I could see using tcpdump that the packet transfer is happening via port 1863.
tcpdump src host dev02 and dst port 1863 -i eth1 -vvv
So, it became apparant that the file-transfer and the text messaging are all happening via port 1863 instead of the port range 6891-6900.  I then decided to write an iptables rule to filter the packets using the packet size constraint.  A rule was written to drop packets that are more then 600 bytes assuming that the IM packets shall never reach the limit.

iptables -A FORWARD -i eth1 -m length -p tcp –length 600:65535 –dport 1863 -j DROP
iptables -A FORWARD -i eth1 -p tcp –dport 1863 -j ACCEPT
iptables -A FORWARD -i eth1 -p tcp -j DROP

I did see that the packet size is around 1350 bytes when files are transferred and that’s why I chose 600 bytes as the limit.  When I monitoring using the “tcpdump” command as before, I was surprise to see that the protocol adjusted the packet size automatically to 560 bytes to continue the transmission.  It tried with 1350 bytes for 3 times and as the acknowledgments were not received, it’s flow control mechanism reduced the packet size to 560 bytes and finished the transfer.  So, I had to redo the iptables rule:-

iptables -A FORWARD -i eth1 -m length -p tcp –length 600 512:65535 –dport 1863 -j DROP

It worked like charm.

The happiness did not last long.  When people logout and tried logging in, they were not able to login at all.  When I investigated the cause of this problem, I could see that the packets that are exchanged during the login process is more than 512 bytes (typically 1350 bytes).  So, I had to relax the rule for a brief time to let people login to MSN messenger service.  I enabled the file-transfer restriction after everybody logged in by enabling the iptables rule.
NOTE: iptables based filtering shall work only for packets that travel across the network.  If the MSN file-transfer happens inside the LAN, MSN cleverly does the file-transfer using P2P where the gateway is not involved at all.

Although, this is not a very good solution, it is definitely worth knowing about!
Happy firewalling!.

Netgear Router & BSNL Broadband

November 8th, 2009 No comments

During Raining Days, BSNL broadband line gets little noisy. I used to connect only my router and never my land line phone in the phone line as I use the BSNL telephone line only for Internet access. Lately, I noticed that the Netgear router having difficulty in establishing connection with the BSNL server whenever it was raining or the phone line is noisy. The “i” indicator keeps blinking in ORANGE color and never stabilizes into a GREEN color indication. Having the “i” indicator blink made sure that the link exists. When I wanted to check the condition of the link (telephone line connection), I connected the BSNL telephone to the splitter port which splits the telephone line to the router and the telephone. When I lifted the cradle, I could notice that the telephone line is little noisy. When I was wondering when and how to make the complaint to BSNL, surprisingly the Netgear router made a stable connection with BSNL gateway. I have used this hack several times, whenever the router (modem) had difficulty in establishing connection.

One theory behind this could be the “loading” effect of the telephone on the telephone line which is subsiding the noise ripples coming over the telephone line.

Compile 32bit C/C++ Application in 64bit Linux

October 8th, 2009 No comments

To build (cross compilation) 32 bit C/C++ applications on 64 bit linux box, use “-m32″ as a compiler argument.  You would need the following 32bit libraries in place.

  1. Install glibc.i386, glibc-devel.i386
  2. Install libgcc.i386
  3. Install libstdc++.i386

#include <cstdio>
#include <iostream>
main()
{
    std::cout << “C++” << std::endl;
    printf ( “long: %d\n”, sizeof(long) );
    printf ( “long long: %d\n”, sizeof(long long) );
    return 0;
}

To compile in native 64bit:
[sudar@tstsrv12 tmp]$ g++ -m64 -o out64 code.cpp

[sudar@tstsrv12 tmp]$ ./out64
C++
long: 8
long long: 8

[sudar@tstsrv12 tmp]$ ldd out64
        linux-vdso.so.1 =>  (0x00007fffc43fe000)
        libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000003e7be00000)
        libm.so.6 => /lib64/libm.so.6 (0×0000000000601000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000003e79e00000)
        libc.so.6 => /lib64/libc.so.6 (0×0000000000886000)
        /lib64/ld-linux-x86-64.so.2 (0×0000000000110000)

To compile in 32bit:
[sudar@tstsrv12 tmp]$ g++ -m32 -o out32 code.cpp

[sudar@tstsrv12 tmp]$ ./out32
C++
long: 4
long long: 8

[sudar@tstsrv12 tmp]$ ldd out32
        linux-gate.so.1 =>  (0×00130000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0×00133000)
        libm.so.6 => /lib/libm.so.6 (0×00223000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x0024c000)
        libc.so.6 => /lib/libc.so.6 (0x0025a000)
        /lib/ld-linux.so.2 (0×00110000)

கால்கள் மரத்து போனால்..

September 25th, 2009 No comments

கால்கள் மரத்துப் போனால்,
எச்சில் தொட்டு கால் கட்டை விரலில் தடவ,
கால்கள் இயல்பு நிலைக்கு வேகமாக திரும்பும்.

Tags: , ,

தும்மல்

September 25th, 2009 No comments

தும்மல் விலக்க,
நாசி துவாரத்தின் மத்தியில்,
நாசியின் நடுதண்டின் அடியில்,
ஆள்காட்டி விரலால் அழுத்த,
தும்மல் அடங்கும்.

Tags: , ,