Tuesday, September 8, 2009

fstab

fstab is a configuration file that contains information of all the partitions and storage devices in your computer. The file is located under /etc, so the full path to this file is /etc/fstab.

# device name mount point fs-type options dump-freq pass-num
LABEL=/ / ext3 defaults 1 1
/dev/hda6 swap swap defaults 0 0
none /dev/pts devpts gid=5,mode=620 0 0

/etc/inittab

The inittab file describes which processes are started at bootup and during normal operation (e.g. /etc/init.d/boot, /etc/init.d/rc, gettys...). Init(8) distinguishes multiple runlevels, each of which can have its own set of processes that are started. Valid runlevels are 0-6 plus A, B, and C for ondemand entries. An entry in the inittab file has the following format:
id:runlevels:action:process

# inittab for linux
id:1:initdefault:
rc::bootwait:/etc/rc
1:1:respawn:/etc/getty 9600 tty1
2:1:respawn:/etc/getty 9600 tty2
3:1:respawn:/etc/getty 9600 tty3
4:1:respawn:/etc/getty 9600 tty4
This inittab file executes /etc/rc during boot and starts gettys on tty1-tty4.

init: The kernel starts PID 1 (init).
init: The init process reads the /etc/inittab and /etc/default/init and follows the instructions in those files.

what is a runlevel? the point at which the system is entered. Runlevel 1 is the most basic configuration (simple single user access using an text interface), while runlevel 5 is the most advanced (multi-user, networking, and a GUI front end). Runlevels 0 and 6 are used for halting and rebooting the system.
>init 6 This will reboot the system.
/etc/rc.d/rc.local file. This script file is run once, before all other scripts have run but before the logon prompt appears.
When the system is shut down, there is another symlink in the /etc/rc0.d and /etc/rc6.d directories (halt and reboot, respectively) that starts with a K instead of an S, which tells init to shut down the process.

Quick:
When you boot your computer, the first thing that it will do is load the bootloader -- either GRUB or LILO in most cases. The bootloader will then load the Linux kernel -- the core operating system. Next, a process called init starts. This process reads the file /etc/inittab to establish the runlevel to use. The runlevel is the start mode for the computer.
Once init knows the runlevel it will look for the appropriate files or directories as defined in /etc/initab.
Init will then either run the script files defined by /etc/initab, or run the script files in the directories defined by /etc/initab (depending on the set up of your system).
Finally, init will present you with the logon mode that you've selected.

Wednesday, August 19, 2009

Sign = in SQL

In C/java there's difference between = and ==. First one is assignment operrator, and == is equality operator.
In SQL Select query:
select * from table_a where col1 = 'abc';
here = is used to check for equality. that's weird!

for loop vs while loop

Which loop to choose, for or while:
1. If we know that we must loop a max of x no of times, then for loop. for loop takes index of how many times to loop.
2. We can use index with while loop too, but it seems more unnatural. eg i++ needs to go inside statements, but in for loop, it goes in for structure.
3. Moreover if we need to break for loop based on some condition, we need to use break statement; a little unnatural again.

Standad input output in Java vs C

ANSI C library implements a model of text input and output. Standard input and standard output is by default attached to keyboard or file or another program.
eg getchar(void) will get characters fom keyboard; prog < infile will input infile contents in prog program; Using Pipes: otherprog | prog channels otherprog output into prog; putchar(int) to send to output stream; prog > outfile; prog | anotherprog.
Question to myself: Does this look easy and helpful to use; and if it is, why does Java not provide this model?
Java has System.out, System.err, System.in. hummm. So we use a lot of System.out in java; we can similarly use System.err, OK. But System.in? When did I use it, don't remember. My memory is failing me or I have really never seen it used?
But certainly Java does not have < as input redirection, or | as pipe mechanism. Or am I ignorant?

Monday, August 3, 2009

Objective C Part 2

What are Protocols?
For the uninitiated, Protocols can be considered to be similar to Interfaces. Protocols are used for multiple inheritance of specifications.
There are two kinds of protocols: informal and formal.
Informal protocol is list of methods a class CAN implement. The compiler does not know about it. These are optional methods a delegate of a class MIGHT implement. At runtime, the class figures out whether any delegate implements these methods or not.
Formal protocols are set of methods a class declares it WILL implement(eg Interface). The compiler then makes sure that the class implements these methods.

Objectice C suports dynamic typing?
This means that most type checking, eg whether int is really coming in the parameter of a method(?), is done at compile time. So there's more chances of runtime errors. Unit testing becomes more important in dynamic type languages.

Forwarding in ObjectiveC?
As we know Objective C objects accept messages. And mostly it's up to object to do anything with that message or not. One other thing an object can do is to forward this message to another object. This is supported by forward() kindof method in base Object class. The class must define this method and forward any message it seems fit.

Categories in Objective C?
What if a class is doing a lot of things(has many responsibilities). the methods get intermingled, and it's difficult to see what each method is doing. What if we could group sets of similar responsibility/functionality methods and say, kept them in different file. Then we could add these functionality oiented methods to class at runtime. Clean code. These groupings of methods are called Categories.

Garbage collection in Objective C?
Garbage collector(an optional conservative yet generational garbage collector) was introduced ObjC 2.0. But it's not part of ObjC2.0 for iPhones.

Standard libraries fo Objective C?
GNUstep on linux and Cocoa on Mac.

http://en.wikipedia.org/wiki/Objective-C

Friday, July 31, 2009

Data structure issues

Problem 1: Reverse any message like "A cat goes here" to produce result like "here goes cat a".
Solution1: In First pass, use pointer from end, keep coming backwards and keep writing the characters. This leads to sth like "ereh seog tac A". Second Pass: reverse characters of each word to get result like "here goes cat a".

Problem2: HashMap vs ArrayList performance using Big-O notation.

Problem 3: How many number of bits are in an integer eg 7. Hint: use Bitwise operators of Java.

Problem 4: Given a log file, find which IPAddress appears max no of times in it.

River in South America

GIS Latitude Longitude Navigation Mapping

Convert Spherical Coordinates to Decimal form
Latitude Longitude are usually expressed in Spherical form. eg 29 degress, 41 minutes, 32 seconds North; Sign for degrees is small o on top right of value; sign for minutes is 41', and seconds as 32''. Thease spherical values are based on Round shape of earth, as a sphere.
How to convert these values to be used in mathematical calculations(decimal form):
Decimal form of above will be 29 + 41/60 + 32/3600, which comes to about 29.69222.

Next step, use Haversine formula to calculate distance between two points.

Sunday, July 26, 2009

IPTv

IPTV technology is about sending Video compressed signals over DSL/telephone lines. User scenario: If your house has telephone wire, we can input this wire to SetTopBox(STB), a customer premise equipment. The STB will decompress video signals which you can input in your TV to watch Digital TV and On Demand Movies, listen to Music, and use various applications to enhance User experience.

IPTV middleware product is client server application where Java client runs on STB. The J2EE server runs on UNIX machine and manages subscribers and their permissions, content metadata, billing packages, billing transactions, STB metadata, STB-subscriber allocations and other configurations.

Or,

IPTV product is 3 tier Java application used to broadcast Digital TV and Music, show on demand Video, provide Walled garden Internet access, and other interactive applications.
MX, the Java client application, runs on J2ME platform, the Customer Premise Equipment Set Top Boxes. The client application follows MVC design. The Model is populated with matadata pushed from server over multicast streams or pulled from server using unicast HTTP requests. The View is customized AWT solution which renders based on text layout files enabling separation of rendering procedure and rendered metadata. The Controllers manage various feature sets.
TX server is the J2EE middleware tier which manages subscribers and their permissions, content metadata, billing packages, billing transactions, Customer Premise Equipment metadata and their subscriber allocation, and other configurations.

design is important

what is the biggest challenge with designing a complex system from scratch?
The biggest challenge at this stage is the Design of the Complex system.
At the start of a complex project, we have the least amount of knowledge about the technical challenges we will face as the product gets developed. A wrong design decision here could turn into a monster when it is found later in the product development stage; leading to great cost in terms of time, resources and product stability to fix it.
Hence design should be based on sound computer science principles. The design should be flexible enough to incorporate changes as new issues, challenges and knowledge becomes apparent during the product development cycle.

multi threading

There are two approaches to multi threading I have seen:
a. Avoid multi threading if possible. Multi threaded code is generally complex. In a team with multiple developers of varying capabilities, it's easy to mess up multi threaded code, or fix a bug and create two more. Or do some coding which affects performance. Single threaded model is simpler to develop and maintain. Use the KISS (Keep it Simple Stupid) principle.
b. Use multi threaded with utmost care. If we are faced with performance issues with single threaded model or forced to use multi threaded code by any factors, Be very cautious. Firstly design the multi threaded code correctly, list all improvements expected and how, develop xUnit test cases to thoroughly test your code, and then take the plunge. Be afraid, be very afraid:) and cautious!

Someone I know wrote this

I was Technical Lead of X Product for NAM(North American Market). When I was made lead of this product, I got a product which was not in commercially deployable state, with customers threatening to switch to competitors. The reasons as I understood were: pressure from Project management and QA to fix the issues ASAP, developers hacking code to fix issues without any design considerations, developers not utilizing Object Oriented development mindset, and such bug fixes creating even more spaghetti code.
The things I did were: take full responsibility for this product and communicate this to everyone; create two codelines with all developers doing fixes in development codeline and ONLY me integrating satisfactory fixes in Release codeline; discussing with developers my design thoughts about fixes I did not like and why, which overall led to better quality; negotiating with Project stakeholders to prioritize issues and reduce scope of each release effectively giving developers more time to make better fixes.
We were able to release the first commercial grade software in 3 months with no Priority 1 issues in core features, and in later 3 month cycles we fixed other customer reported issues, show stopper issues on priority, and most Priority 2 issues. We only fixed Priority 3 issues if they were easy to fix or did not impact the design too much.
In short, for the last almost 3 years, my codeline has been the most stable out of all X product codelines, and customers have been most satisfied.
Questions?

Technology work hierarchy

Similar on Maslow's need Hierarchy, this is what I believe is technology work hierarchy:
Lowest level: Survival, do what you are told esp things like bug fixing, need minimum understanding of design and language features.
Next level: Understand language and bit of design, make better software, but still what needs to be done is dictated by others(designers/managers)
3rd Level: Understand language/design in detail; ability to teach others the technical concepts in simple language, Expert. But still work is defined by Others.
4the Level: creativity Level, When one sees new uses of current knowledge, start being creative, stats defining new applications of technology or improvements to technology. Self actualization level.

Friday, July 17, 2009

Palindome

In a language of your choice write a function that takes a string and returns the longest palindrome contained in that string. A palindrome is a symmetrical string – it reads the same from left to right and from right to left. Please make sure your solution really works and provide a few interesting test cases for it. Try to make the code as efficient as you can. For extra credit provide a complexity analysis for your solution.


public class Palindome {

public static void main(String [] args){
Palindome palindome = new Palindome();
if (args.length > 0){
System.out.println("The first argument will be tested if it's palin!");
palindome.findIt(args[0]);
}else{
System.out.println("The first argument will be tested if it's palin!");
}
}

int testStringLength = 0;
String successString = null;

/*
* the main method of the algorithm, Find the length of SubStrings to be tested, starting from lagest to smallest
*/
public String findIt(String testString){
/* String testString1 = "papa I Never even get to do any things";
*/ testStringLength = testString.length();

boolean palinFound = false;
for(int i =0; i System.out.println("testString length = "+ testStringLength);
palinFound = isThereAnyPalinOfThisLength(testString, testString.length());
if(palinFound){
System.out.println("palinFound!! String successString = "+ successString);
return successString;
}
}
return successString;
}

/*
* Find all SubStrings possible of specified length.
*
*/
public boolean isThereAnyPalinOfThisLength(String testString, int testLength){
boolean b = false;
System.out.println("testString length = "+ testStringLength);
for(int i = 0; i < (testStringLength); i++){
String str = testString.substring(i, testLength);
System.out.println("Current String To Be tested : "+ str);
b = isThisPalin(str);
if(b){
successString = str;
return b;
}
}
return b;
}

/*
* This method checks whether "this exact" String is palindome or not?
*/
public boolean isThisPalin(String s){
int startPointer = 0;
int endPointer = s.length()-1;
boolean noMatch = true;
System.out.println("Is this palin = "+ s);
while(startPointer < endPointer ){
if(s.charAt(startPointer) != s.charAt(endPointer)){
noMatch = false;
break;
}
startPointer++;
endPointer--;
}
return noMatch;
}


/*
* We need to find the Largest Palindome String, We don't care if smaller Palindomes are present or not.
* Step1: Recursively find the largest to smallest strings that can be made out of the test string.
* 1a. Check whether thye whole string is palindome or not.
* 1b. If not, Check whether all Strings possible of (length-1) are palindome or not.
* 1c. If not, Check whether all Strings possible of (length-2) are palindome or not.
* 1d. continue till the time When EVEN "at least 2 characters Strings" are not Palindome:(
* Step2:
* Create all possible SubStrings of length l, and check each of them.
* Step3: check each SubString if it is palindome!
*
*
* ToDo:
* 1. Remove all special characters from the String to be tested eg All ,; $ etc. ONLY characters should remain.
* 2. When checking for character equality in isThisPalin(String s), must make sure that capital Letters and small letters are matched too!
* 3. The String should be sent from Junit test case.
*
Complexity analysis:
String length: n
Worst Case:
No of strings compared: 1(one string of length n)+2 (2 stings of length n-1)+3+.. +n
No of character comparisons: n/2; (n-1)/2...
Total char compared: n/2 + (n-1) + (n-2)....
Order of: n squared

Best Case:
No of Strings compared: 1 (The whole String is a Palindrome)
No of characters comparisons: n/2
Order of : n

Average case:
No of Strings compared: 1+2+3+ ...+ n/2
No of character comparisons: n/2; (n-1)/2...+ (n/2 -1)/2
Total char compared: n/2 + (n-1) + (n-2)....+ ((n/2-1)/2)*(n/2)
Order of: (n squared)/8



Monday, July 13, 2009

Objective C part 1

What is ObjectiveC:
Objective-C is a reflective, object-oriented programming language, which adds Smalltalk-style messaging to the C programming language.
ObjectiveC is subset of C?
No. Objective-C is a very thin layer on top of C, and moreover is a strict superset of C. That is, it is possible to compile any C program with an Objective-C compiler, and to freely include C code within an Objective-C class.
What does it mean by "Smalltalk-style messaging" in ObjectiveC?
Objective-C derives its object syntax from Smalltalk. All of the syntax for non-object-oriented operations (including primitive variables, preprocessing, expressions, function declarations, and function calls) is identical to that of C, while the syntax for object-oriented features is an implementation of Smalltalk-style messaging.
Explain Messages in ObjectiveC?
Messages are central concept in ObjectiveC. The Objective-C model of object-oriented programming is based on sending messages to object instances.
In Objective-C one does not call a method; one sends a message. There is no concept of called method being executed. In ObjectiveC, the message sent to an object is executed! In fact, the calling object just sends method NAME to the called object. The called object received the method NAME at runtime, then figures out what to do (at runtime).
This means there is no type checking(the signatures of called method should match the call from calling object) at compile time.
And there is no guarantee that the receiving object will respond to any message sent to it; it may just ignore it(and send back null as response).
Explain Message syntax:
[obj message:parameter];
message is being sent with parameter(s) to the obj(receiving object).
Any quick advantage/disadvantage with messages:
Advantage: ObjectiveC allows messages to go unimplemented - for example, a collection of objects may all be sent a message, of which the programmer knows only some will respond, without fear of producing runtime errors. eg. The Cocoa platform takes advantage of this, as all objects in a Cocoa application are sent the awakeFromNib: message as the application launches, to which objects may respond by executing any initialisation required at launch.
Disadvantage:
Due to the overhead of interpreting the messages, an Objective-C message takes at best over three times as long as a C++ virtual method call. What comparing times with C++ virtual method call: because just like messages need not have implementation in ObjC, C++ virtual methods need not have implementation(if it is called, it needs implementation; but one can only declare virtual method, never implement it and never call it).

Let's talk interface, implementation, instantiation:

Inteface:
@interface classname : superclassname {
// instance variables
}
+classMethod1;
+(return_type)classMethod2;
+(return_type)classMethod3:(param1_type)parameter_varName;

-(return_type)instanceMethod1:(param1_type)param1_varName :(param2_type)param2_varName;
-(return_type)instanceMethod2WithParameter:(param1_type)param1_varName andOtherParameter:(param2_type)param2_varName;
@end

Plus signs denote class methods(aka static), minus signs denote instance methods. Class methods have no access to instance variables.
Note that instanceMethod2WithParameter demonstrates Objective C's named parameter capability for which there is no direct equivalent in C/C++. Todo: explain this.
Return types can be any standard C type, a pointer to a generic Objective-C object, or a pointer to a specific type of object such as NSArray *, NSImage *, or NSString *. The default return type is the generic Objective-C type id.
Todo: explain this.

Method arguments begin with a colon followed by the expected argument type in parentheses followed by the argument name. In some cases (e.g. when writing system APIs) it is useful to add descriptive text before each parameter.

-(void) setRange:(int)start :(int)end;
-(void) importDocumentWithName:(NSString *)name withSpecifiedPreferences:(Preferences *)prefs beforePage:(int)insertPage;

http://en.wikipedia.org/wiki/Objective-C