Miracle of self discipline – audio book notes.

The following are the notes of my listening to the Miracle of Self discipline audio book by Brian Tracy.

Decision of clear thinking
think from all angles
sit for 30-60 mins with the problem
write down all points and think
think abt the assumptions made about the situation or the problem

Continue reading

Hazards of Bengaluru – Mobile theft in BMTC’s Volvo.

I have shifted to Bengaluru in Feb 2011 and have been exposed to completely new environment. This IT city has its pros and cons. While the public infrastructure is way better than Pune. It has its own set of problems.

The most irritating is the total lack of bus-stop sheds throughout the city. There are different type of bus services. But all of them lack the sheds. So catching the bus can become a big task.

The other major problem is the mobile snatchers in the Volvo buses. I got a first hand experience of them with me losing the N8 in the Volvo bus. I could not even imagine that it was possible to steal the mobile from front pocket of a jeans. So for all commuters please be aware of the surroundings and keep track of belongings all the time. Traveling in the Volvo can make one a bit careless, like me.

Lifewerks gets going.

Hi All,

This is the first post of lifewerks@flaminghorns.com. I would be posting about some of the stuff as it happens. Things which are mundane or exciting but have nothing to do with the other topics being blogged@flaminghorns.com. My first post on things to be wary of in Bengaluru is underway and will be completed soon.

All kinds of feedback welcome.

Hello, from codekata.flaminghorns.com!!

Welcome to my own domain of flaminghorns.com.

I have moved from blogger.com and have setup the codekata blog here at flaminghorns.com. The setup is still underway. The awesome theme is not really for coding blogs, so it needs to be tweaked a bit. This will take time, but as the progress has been till now I am assuming that things will be set and I would be back to blogging soon.

CPP Common Knowledge notes!!

[cpp]
class TestCode
{
//This is a test for Syntax highlighter!!!
};
[/cpp]
Item #11 : Compiler puts stuff in classes.
Compiler puts a virtual function table ptr in each class object with virtual functions.
Virtual function table pointer not same across platforms!!
Compiler may not put all these extra constructs in a struct.
Virtual inheritance is required when the diamond inheritance is causing issues.
For example:
[cpp]
class Base
{
public:
virtual void foo();
};

class D1 : public virtual Base
{
public:
void foo2();
};

class D2 : public virtual Base
{
public:
void foo3();
};

class SD : public D1, public D2
{
// We have taken care of the diamond inheritance issue with the virtual keyword
// so compiler is gonna shut up now!!
};
[/cpp]
Item #12 : Assignment & initialization are different.
These two ops not so diff in built-in types like int, char etc.
For user-defined types, it would not be advisable to perform user-defined assignment.
[cpp]

class X
{
char* buf;
mutable bool modified;
Y obj;
public:X()
{
buf = new char[100];
for(int i = 0;i<100;i++)
modified = false;
if( < 98)
return;
buf[index] = c;
modified = true;
}

void printdata()
{
cout << "Data is "<<;
ptr =static_cast(::operator new(sizeof(X)+100));// X::buf is not init!!
ptr->setData(0,’c’);
}
[/cpp]
Item #13 : Copy operations.
Copy construction and copy assignment are different operations.
[cpp]
class Hoo
{
char* buf;
int size;
public:
//copy CTor
Hoo()
{
buf = 0x00;
size = 0x00;
}

~Hoo()
{
if(buf)
{
delete[] buf;
buf = NULL;
}
size = 0x00;
}

void setData(char* data, int asize)
{
size = asize;
buf = new char[size + 1];
memset(buf, 0x00, size+1);
strncpy(buf, data, size);
}

Hoo(Hoo const &amp; hoo)
{
setData(hoo.getBuf(), hoo.getSize());
}

Hoo& operator= (Hoo const &hoo)
{
if(this != &hoo)
{
if(buf)
{
delete[] buf;
buf = NULL;
}
size = 0x00;
setData(hoo.getBuf(), hoo.getSize());
}
return *this;
}

char* getBuf() const
{
return buf;
}

int getSize() const { return size;}

};

void copy_ctor_assgn()
{
Hoo data;
data.setData("Hello",5);
Hoo dat2(data);
//copy ctor invoked here
Hoo dat3;
dat3 = dat2;// assgn operator invoked here
}
[/cpp]
Item #14 :Function Pointers.
Legal to point to inline functions, but the resultant call will not be inline.The compiler will not be able to determine at compile time what function is being called.
Can also point to an overloaded function. The particular function called will depend on the match between the function ptr type and the overloaded functions.

Notes….

[cpp]
8/25/2010
———
>>POM#1
Read 10 pages of Modern C++ design.
Realised that it needs more knowledge about templates.
Started with reading the book : C++ Templates, The Complete Guide 2002.chm

>>POM#2
Function templates
function template syntax:
template <typename a1,….>
funnction declaration or definition using T
‘typename’ introduces type parameter
historical alternative to typename is ‘class’.
templates are generated once for each type for which it is used
process of replacing template types with concrete types is called instantiation.
use of function template triggers the ‘instatiation’.
templates are compiled twice:
1. once for checking the syntax of the template.
2. second time to check the operations mentioned are valid for
the type used for template instantiation.

template parameters are determined by the arguments passed at the call time.
no automatic type conversion is allowed.

>>POM#3
Function templates have two kinds of parameters
1. template params – declared in angle brackets, N no. of them can be declared,
no default template arguments can be specified.
e.g.: template <typename T> // T is template param
2. call params – declared in parenthese after function template name
foo(T p1, T p2) //p1,p2 are call params
call params deduced from template params, so they are related.
function template argument deduction
when template return type cannot be deduced from template and
call params then needs to be explicitly mentioned.
template argument deduction does not try to determine the return type
another method to just declare one type and then let the compiler deduce the rest.
template <typename RT, typename T1, typename T2>
inline RT max (T1 const& a, T2 const& b);
// OK: return type is double, T1 is deduced as int and T2 is deduced as double.
max<double>(4,4.2)
overloading function templates->overloading resolution revisited
not part of every function call
— calls to functions thru function ptrs
— calls to member functions thru ptr to member functions
not subjected to resolution as they are determined at runtime.

function like macros cannot be overloaded and hence not subjected to reso

8/26/2010
———
Task for today:
1. chk the tower of hanoi problem
2. chk two design patterns and make notes abt them
[/cpp]

Mobical.net : Remote sync, worked for me!!!

I just moved to SE P1i from N91. The moving was a bit tricky for me. As I was moving for the first time to a Non-Nokia device. I tried moving my contacts and events using Oxygen phone manager and Mobiledit! , but both did not work for me. Ovi was not an option due to the Nokia only support. So after a bit of search I found mobilecal.net.

I was able to move the contacts within 15 mins of finding the website and setting up an account. I would really rate that as fast. Well I could not move my messages, but I can live with that, as the 200+ contacts were moved quite easily.

I would strongly recommend it ,especially if you are the frequently shifting from one device to another.

Data structures to Algorithm analysis to discrete mathematics & calculus.

I started reading “Data Structures & Algorithms with Object-oriented Design patterns in C++” only to realize that I was totally lost in the mathematics. Maths has been greek to me and I have been avoiding it as much as possible. To put it simply, am bad at numbers. So now to understand the algorithm analysis part along with the O notation I need to first quickly grasp Discrete mathematics and some calculus as well.

I will update again once am done with Discrete mathematics,so Grimaldi here I come.

Steps to debug Webkit using Eclipse.

Here are the steps to debug Webkit in Linux using Eclipse. This has been reproduced here verbatim from
here
.I am currently verifying these steps.



Debug Native C++ Code:
To get meaningful debug info, you do need to build WebCore with -O0. It is simple. Add the following to your buildspec.mk and rebuild webcore and xml2.
If you don’t have buildspec.mk under the root directory yet, please copy build/buildspec.mk.default to the root (android/)

[cpp]
DEBUG_MODULE_libwebcore:=true
DEBUG_MODULE_libxml2:=true
TARGET_CUSTOM_DEBUG_CFLAGS:=-O0 -mlong-calls
[/cpp]

Add
[cpp]
"ADDITIONAL_BUILD_PROPERTIES += debug.db.uid=100000"
[/cpp]

so that it will wait for you to connect gdb when crashed.

Use
[cpp]
rm out/target/product/dream/system/build.prop
[/cpp]
to make sure it takes effect.
To rebuild webcore and xml2:
[cpp]
make clean-libwebcore clean-libxml2 && make <br>
[/cpp]

Note: If you get system image is too large, you can manually change vendor/htc/dream/BoardConfig.mk, and set BOARD_SYSTEMIMAGE_MAX_SIZE to a bigger number, e.g., 94371840
(sapphire’s cap).
Debugging native code on emulator is much better now.
Start emulator and activate browser.
In a different shell, do
[cpp]
"gdbclient app_process :5039 browser"
[/cpp]
It should connect to emulator now, and you should see following
(the first three lines) in gdb. Type “c” for continue.
[cpp]
__futex_wait () at system/bionic/arch-arm/bionic/atomics_arm.S:121
121 ldmia sp!, {r4, r7}
Current language: auto; currently asm
(gdb) c
Continuing.
[/cpp]
If you want to use Eclipse, it will be easier if you have Eclipse 3.3 instead of 3.2 (on Mac). Here is how to set up debug configuration.

Run -> Debug…, select C/C++ Local Application, then click New. Give a name to your configuration, like release_native, select android project, and
[cpp]
android/out/target/product/dream/symbols/system/bin/app_process
[/cpp]
for the application.
In Debugger tab, select GDB Server for the debugger.
Under Debugger Options choose Main tab first, enter
[cpp]
android/prebuilt/darwin-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gdb
[/cpp]
as GDB debugger.
Choose TCP for connection and use 5039 as port.
Then under Shared Libraries, add
[cpp]
android/out/target/product/dream/symbols/system/lib.
[/cpp]
Davidc: Not sure if the is the same for everyone, but I had to reduce the length of the paths to avoid GDB timing out. To do this, remove the paths set in the Source tab, and add the path to
the files you are debugging.
To debug an application with Eclipse, you need to gdbserver on the target (emulator or hw) and forward the port.
In a shell, do
[/cpp]
“adb forward tcp:5039 tcp:5039”.
[/cpp]
In the shell, do
[cpp]
"adb shell gdbserver :5039 –attach `pid browser`".
[/cpp]
Start the debugger in Eclipse
If you have trouble to use Eclipse to debug native on Linux, you can use gdb. To use gdb, you need to create a ~/.gdbinit with following content:
[cpp]
file ./out/target/product/dream/symbols/system/bin/app_process
set solib-search-path ./out/target/product/dream/symbols/system/lib
target remote localhost:5039
[/cpp]
It does exact the same thing as Eclipse setup. Then you can start gdb from android/ directory:
[cpp]
./prebuilt/linux-x86/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gdb
[/cpp]
To debug native code before the browser has fully started:
Open DevTools application, select Development Settings.Select Debug App at the top, and pick the browser from the list (com.android.Browser)
Click ‘Wait for debugger’
Go back to home and launch the browser
Follow from step #2 in the steps described above under “Debugging native code on emulator is much better now.”
At this point, GDB is attached but the browser is still waiting for the Java debugger
Attach the Java debugger and the browser will automatically continue.

07th July : Update : We are getting an error with system/bin/linker.Need to fix it to load the symbols properly.