Wednesday, November 20, 2013

Solved: Misleading link errors with gcc on linux

Solution Summary: LDFLAGS come in last

Background
I have been monkeying around with an issue of linking my code with xerces-c++ and xalan-c++ library for hours. Wondering what was I doing wrong.

I was issuing the following command for compiling

g++ -o file.out -lxalan-c -lxerces-c program.cpp

I was getting the following errors

program.cpp:(.text+0x75): undefined reference to `xercesc_3_1::XMLUni::fgXercescDefaultLocale'
program.cpp:(.text+0x7a): undefined reference to `xercesc_3_1::XMLPlatformUtils::Initialize(char const*, char const*, xercesc_3_1::PanicHandler*, xercesc_3_1::MemoryManager*)'
program.cpp:(.text+0x7f): undefined reference to `xalanc_1_11::XalanMemMgrs::getDefaultXercesMemMgr()'
program.cpp:(.text+0x87): undefined reference to `xalanc_1_11::XPathEvaluator::initialize(xercesc_3_1::MemoryManager&)'
program.cpp:(.text+0x8c): undefined reference to `xalanc_1_11::XalanMemMgrs::getDefaultXercesMemMgr()'
program.cpp:(.text+0x9e): undefined reference to `xalanc_1_11::XalanSourceTreeInit::XalanSourceTreeInit(xercesc_3_1::MemoryManager&)'
program.cpp:(.text+0xac): undefined reference to `xalanc_1_11::XalanSourceTreeDOMSupport::XalanSourceTreeDOMSupport()'
program.cpp:(.text+0xb1): undefined reference to `xalanc_1_11::XalanMemMgrs::getDefaultXercesMemMgr()'
program.cpp:(.text+0xcd): undefined reference to `xalanc_1_11::XalanSourceTreeParserLiaison::XalanSourceTreeParserLiaison(xalanc_1_11::XalanSourceTreeDOMSupport&, xercesc_3_1::MemoryManager&)'
program.cpp:(.text+0xea): undefined reference to `xalanc_1_11::XalanMemMgrs::getDefaultXercesMemMgr()'
program.cpp:(.text+0x112): undefined reference to `xalanc_1_11::XalanDOMString::XalanDOMString(char const*, xercesc_3_1::MemoryManager&, unsigned int)'
program.cpp:(.text+0x118): undefined reference to `xercesc_3_1::XMLPlatformUtils::fgMemoryManager'



Thanks to this Stackoverflow Discussion. I found out what I was doing wrong. Although the discussion was about compiling in windows but it gave me the clue.

So basically, while it did work on suse, the actual syntax is (LDFLAGS come in last)

g++ -o exectuable <object files> <ld flags>

So I changed my command to the following and got my issue fixed.

g++ -o file.out  program.cpp -lxalan-c -lxerces-c

I am sharing this so the next guy who has similar issues will hopefully find this post and save him some trouble.

Happy coding!

Friday, August 30, 2013

Here is one more thing you can do when you're bored - Thanks to Illinois Tollway

Illinois just gave you a new prank idea. The Illinois Tollway recently published a list of Top Violators who owe big money to Illinois in Toll Violations and are not paying. Somehow they justified this.
Image copyright: http://www.hntb.com

So here is what you can do,

Disclaimer: Always check local state laws of origin and destination states of the call as well as federal law when communicating over the phone. Federal law prohibits anyone from recording a phone conversation without the other party's knowledge and consent. Do not repeat the call to same party if they have told you that they do not wish to receive any call from you.

Step 1  - Click the following link to access the list of violators
Super Scofflaws

Step 2 - Pick one from the list, copy their names, city and state.

Step 3 - Google the name of entry with City and State to find their phone number.

Step 4 - Call them during their regular business hours, tell them you are their wanna-be customer; you just have a very small concern before you give them your business and that is When are they planning on paying off their balance to Illinois Tollway. 

You will likely to hear some funny answers. Good luck!


Friday, May 10, 2013

5 Things I learned about email-marketers


1. Last chance is never a last chance.
This one time I searched my Gmail folder where I kept all the marketing emails I got for “Last chance” or “You must upgrade by midnight”, I was surprised to see repeating emails. So never take those emails seriously, in fact this attitude shows that they are missing their monthly or quarterly sale target. So you could call their customer support and get a good bargain.

2. N% off is most likely N% more the price you can get elsewhere.
Whenever you see the price for something that says that it is after some percentage off, they are not basing their information on the right List price of that product. They are making up a “List price”. Always search for the same product through either the part-number or short-description on other websites and search engines.

3. Unsubscribe sometimes results into more emails from different vendors.
I have always wondered why I am getting emails from a company who want to sell me the prescription medicines for cheap, who gave them my email address. Until I read in a PCMag article that many small businesses; when they learn that you are cutting them loose, they still keep a list of people like you including your email address, name and other information and sell them out. The article suggested to “block” future emails from that business than unsubscribe. Unsubscribing actually lets them know that your email is a legit email which is checked frequently.

4. Offer that is only for you is sometimes not true.
Sometimes those small business owners who are desperately trying to reach their sales goals without having to invest money on billboards and TV ads. They not only lower the price, but to make it sound even better, they tell you that this offer is only for you and everybody else is having to pay the actual price.

5. Never fall for Message from CEO
Do you think a legitimate business’ CEO would have nothing better to do than emailing you to sell a thirty-dollar membership ? To have some fun, call that business and tell them you are replying CEO’s email through phone and you need to speak with him about membership. Tell them you cannot speak with anybody else.


I would love to hear your comments in the comment box below.

Saturday, May 4, 2013

Diomede Islands, a practically possible time-travel scenario?

For those who don't know what and where Diomede Islands are. They are small Islands, located on the Bering sea. One called Little Diomede Island fall in Alaska, USA and other one called Big Diomede Island falls in Siberia, Russia. The shortest distance between those two are roughly two miles


Picture taken from North of the islands, On the left is Little Island which is in USA and right is the big island in Russia.


Here is a small fun fact
On the west edge of Little Diomede Island in Alaska, there is a small town called Diomede, AK which has a population of about 125. In winter time, the Bering waters around that area get frozen, and some residents of Diomede, AK like to take a short walk on the frozen sea waters to Russia. Off course, Russia does not like it, but they know that the island in Siberia is remote and no one lives there so people walking into Russia to feel good about themselves is not a concern for Russian authorities.


Here is the actual fun part
The Big Diomede Island is 23 hours ahead of Little Diomede Island. Which means whatever time it is right now in Little Diomede Island in Alaska, its about the same time next day in Big Diomede Island in Siberia, Russia. So right now as of me writing this post, its 10:30 PM in Diomede, AK Saturday. It is 9:30 PM Sunday in Big Island.

Can travelling from Big island to Little island be considered as a "Back to the future" travel?

Monday, April 8, 2013

Programming Tip: Parameters vs Arguments

In this post I would like to share what my teacher once taught me about why Parameters are not same as Arguments. Consider a simple example of a paper-form where you have to write things to submit a certain request. Each form-field is a parameter and what you write in that field is an argument.

So Parameter a placeholder to hold some value in order to process the method call and Argument is the value that is passed by the caller of your method.

If you have further information on this subject or what you know is different, please drop a line in the comments section.

Monday, March 25, 2013

Performance Counters Testing Tool

Writing high performance applications, specially that does batch processing is always fun. But most of the time you are unaware of whats going on under the hood.

You can use Performance Counter in Windows to find out how many threads your process has spawned, whats the current CPU and/or memory usage. But what if you want to know whats going on in your logic and with what frequency ?

For that you need to "Post" performance data out to windows operating system. So you could watch/log the data in order to generate nice and fancy reports for the superiors.

This post is all about sharing Performance Data Testing Tool that I built and would like to share. If you want to learn more about Windows Performance Counters, Check this Microsoft Article.

To learn the basics about how to code in .NET to post performance data to windows system, check this guy's  Blog Post Part 1 and Part 2.


Go to the Google Code project page to download binary or source code for the Tool.

Here is a snapshot

"Play with existing" part lets you change the values for current number of current counters that are being posted.

"Create/Delete" lets you create your own category and add counters to them. Once you've created new category with at least one counter, you can type the category name and counter name on the above section and click the Top Grab button then you can use Increment/Decrement button to up and down the values.

To watch those values in a graph, use Windows Performance Monitor.

You are free to use my code, modify it and/or redistribute it.

Happy coding

Monday, March 18, 2013

iOS app development for C/C++/C# Developers : Defining default constructor in Objective-C

In this post I am going to share how we do whats called "constructors" in C++ or C# and for my C-only fellows, object initializers or <insert some term here>.

As I mentioned in my previous blog post that Objective-C has no such thing as constructors. We use the native non-instance method or what we call "static" method to allocate a new instance. That method is called alloc.


 MyClass* myObj = [MyClass alloc]

The above code just creates an object in a fashion similar to having no constructors defined in our C++ or C# class.

But consider the following code in C++.


 class Circle
  {
    private int m_radius;
    public Circle()
     {
       m_radius = 10; // C++ folks can also use the "initializer list" for this assignment
     }
  }

If we want to implement the same logic in Objective-C, we are going to have to define something what most Obj-C developers call "initializers"

Initializers are nothing but methods that may take arguments and meant to be called right after allocation of a new object. So we could do the following in Objective-C. Lets do a "default constructor" in this post. I will make another post for parameter-ized constructor


Circle.h file
 #import <foundation/foundation.h>

@interface Circle : NSObject {
  NSInteger m_radius;
}

 - (id) init;
@end

Circle.m file
 @implementation Circle
  - (id) init
  {
    self = [super init]; // calling base class's init in this case NSObject's init

    if (self) { // checking to see if an object has been returned by NSObject's init
            self.m_radius = 10; // set the default value to 10
      }
   return self; // In order for it to act like a constructor, it should return the object
  }
 @end

And this is how we create an object using the initializer defined above
 Circle* circleObj = [[Circle alloc] init];

By the way, 'super' is a Java term for base class too. Somebody gets a title of 'copy-cat' here.

That's all folks for this post. Please let me know your comments in the comment box below if you have any.

Google Drive outage made my presentation go the wrong way

Update: Drive is back up but too late.

Had embarrassing and frustrating moments when I had to screen a presentation off my Google Drive account and I saw the ridiculous error message with picture of a broken monkey with a wrench
"502, Thats an error The server encountered a temporary error and could not complete your request.. Please try again in 30 seconds, Thats all we know"


And their Apps Dashboard showing the following message, which scared my audience away from idea of using Google stuff for our business.


And a lot of people blowing off their steams at the wrong place,  Google Drive Forum

Lets see how this drama ends, but I am sure missing the deadline because of this outage. I wish I had downloaded updated copies of all my docs from the drive every night as a backup to my local drive.

Please be mindful of these imminent issues when choosing such kind of services for your business.

Tuesday, March 12, 2013

A few Objective-C kick start tips for C++ Developers

Here are a few things I as a C++ developer had to learn the hard way.


Basic Language Constructs

+ sign for static methods - sign for methods that require objects

For instance in C++ we do the following
public:
static void SomeMethod();

The objective-C equivalent would be

+(void) SomeMethod;

Similarly for non-static methods just change the + sign to -. They are called Instance Methods.

-(void) SomeNonStaticMethod;


You may also have noticed that the return type is enclosed in () parenthesis which was weird to me.

No private methods

Thats right, no method is private. You can have member variables or attributes private by using @private but methods cannot be private.

Method calling

In C++ we have, when we have to call a method; we do

myObj.MethodName();

In Objective-C, its totally changed. 

[myObj MethodName];

Tada! No Constructor

Yes, there is no such thing as constructor. All you do is call a native/built-in method alloc to create an object with default properties.

[MyClass alloc]; //Here is the object being created

But Objective-C developers have come up with something called initializers, so immediately after the object is created, an init method is called. Keep in mind that init is something developer has to create as a method that does some initialization work.

[ [MyClass alloc] init];

Weird asterisk * that reminds you of pointer will get on your nerve

Yes, that asterisk is for pointers. Every object reference is stored in pointers. 

So in C++ we create objects by simply writing the following code

MyClass MyObj = MyClass();

In Objective-C, you will have to write the following code
MyClass *MyObj = [ [ MyClass alloc ] init];

Project files

Objective-C has similar to .h/.cpp structure for class declaration and definition but its most often called .h/.m or .h/.mm (for Objective-C++)

Keyword interface is not what you think

interface keyword in Objective-C is used for class declarations.

C++ code
class MyClass

{

 public:

MyClass();

};

Objective-C will require you to write the following code for the above

@interface MyClass {

// non-static variables go here

}

- (MyClass*) init;

@end


Class definition or .m file

.m file or .cpp file counterpart in Objective-C would look something like this

@implementation MyClass { // Yes 'class' keyword is never seen

-(MyClass*) init  {

 if (self) {

// initialize self here

 }

return self;

}

@end



Thats all folks! There is more information on the topic which I intend to write in future blog posts. If you are a C++ developer and thinking about taking a nosedive into Objective-C, above mentioned things should be enough for you to brace for.

I would love to hear your comments. They help me understand how useful my postings are.

Sunday, March 10, 2013

WPF - How to run XPath count() in XmlDataProvider binding

Hi,
Welcome to my very first (not really) blogging entry. I was monkeying around with an issue on internet and could not find any solution, however, I did find quite a few people looking for the same thing I was looking for. I tried something that worked, thought I would share that with the world.

So the issue is, You have the following Xml to bind to in your WPF application

 <MyData>  
  <Book Name="WPF Basics" Author="John Doe">  
   <Publishers>  
    <Publisher>  
     <Name>Wrox </Name>  
     <Name>Microsoft Press</Name>  
    </Publisher>  
   </Publishers>  
  </Book>  
  <Book Name="Thinking in WPF" Author="Johny Cage">  
   <Publishers>  
    <Publisher>  
     <Name>Wrox </Name>  
    </Publisher>  
   </Publishers>  
  </Book>  
 </MyData>  

Now you have a Listview that displays Book name in one column and number of Publishers in other column.

If WPF XmlDataProvider supported XPath functions you could do something like this for 2nd column

{Binding XPath=count(Publishers/Publisher)}

But XmlProvider binding uses SelectNodes() of XmlNode in System.Xml which does not take XPath functions.

Another way I was able to think of was to use converters and do something like this

{Binding XPath=Publishers/Publisher, Converter=myOwnNodeListToCountConverter}

But XmlDataProvider calls the .ToString() before passing it on to your converter. Which means, your converter won't get an XmlNodeList object, but just an empty string.


So lastly, I tried this which finally worked, Not an elegant way but it works. :)

The basic idea is to render all the items you want to count in an invisible (Visibility=Collapsed) ItemsControl and Bind a TextBlock to the Items.Count of that ItemsControl. Here is a little snippet to show the concept.


<ListView IsSynchronizedWithCurrentItem="True" Margin="8,8,0,0" ItemsSource="{Binding Source={StaticResource xmlFmlDataSource}, XPath=//Programs/Program, Mode=OneWay}">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Book name" Width="200" DisplayMemberBinding="{Binding XPath=@Name}"  >
           
                    </GridViewColumn>
                    <GridViewColumn Header="Params" Width="50" >
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel>
                                <ItemsControl x:Name="dummyItemsControl" ItemsSource="{Binding XPath=Publishers/Publisher}" Visibility="Collapsed">
                                    <ItemsControl.ItemTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="" />
                                        </DataTemplate>
                                    </ItemsControl.ItemTemplate>
                                </ItemsControl>
                                <TextBlock Text="{Binding ElementName=dummyItemsControl, Path=Items.Count}" />
                                </StackPanel>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>



This is not my dream solution that I feel ecstatic about, but this works and won't probably a big deal if the data volume is not too large. I would love to read your comments.