My way of sending files is very odd.
Thursday, April 29, 2010
Simple application to Send and Receive Files
Tuesday, April 13, 2010
Wednesday, March 17, 2010
Tuesday, March 16, 2010
At first it’s simple, then it gets complicated and simple again
When you start looking at a problem and it seems really simple, you don’t really understand the complexity of the problem.
Then you get into the problem, and you see that it’s really complicated, and you come up with all these convoluted solutions. That’s sort of the middle, and that’s where most people stop…
But the really great person will keep on going and find the key, the underlying principle of the problem – and come up with an elegant, really beautiful solution that works. That’s what we wanted to do with Mac.
Steve Jobs, 1984, taken from Peter Merholz’ book “Subject to Change”
Since it is great quote, I entirely copied and pasted the text from the following link.
http://mortenjust.com/2009/07/20/at-first-its-simple-then-it-gets-complicated-and-simple-again/
Sunday, March 07, 2010
Idea to develop a smart phone applcation (Useful for India like couctr)
Thursday, February 11, 2010
Chrome Browser pinned tab tip.
Monday, February 08, 2010
Get Latitude and Longitude values from Google Maps
Friday, March 06, 2009
Pupil detection in a video [C# and Java]
The project is about finding the eye pupil detection. We did it for both image and also for the video[webcam].
Here is the video output of the project.
-- Anil
Thursday, September 18, 2008
Recursion
I found it very useful to explain the recursion. I read it at everything2.com.
who couldn't sleep, so the frog's mother told her a story about a little bear,
who couldn't sleep, so the bear's mother told her a story about a little weasel...
who fell asleep.
...and the little bear fell asleep;
...and the little frog fell asleep;
...and the child fell asleep.
This is the best explanation of recursion I've heard. It could probably
be recast to be less cutesy, but it really gets to what's going on with recursion in a very nice way: Stuff happens on the way in, you hit an endpoint, and other stuff happens in reverse order on the way back out as it all unwinds. For somebody who doesn't "get" recursion yet, this is not a bad map to start with.
Wednesday, August 27, 2008
Tricky Java Code
Java class without main method:
class Main
{
static
{
System.out.println("This java program have run without the run method");
System.exit(0);
}
}
Java syntax quirk:
public class Oddity
{
public static void main(String[] args)
{
http://amadamala.blogger.com
System.out.println("Why is the URL allowed above?");
}
}
Ans:
----http://amadamala.blogger.com == lable : // comment here
| |
| |
v v
http: //amadamala.blogger.com
References:
[1] http://www.java-tips.org/
[2] http://www.javapuzzlers.com/
Monday, July 07, 2008
FifteenPuzzle Game :: SourceCode
I'm posting the code of a game that I wrote recently. Game name is FifteenPuzzle or N-Puzzle.
You can download the file here.
File Name: FifteenPuzzle.java
import java.awt.*; |
Comments and suggestions will be great.
-Anil Madamala
Tuesday, April 22, 2008
Loop Unrolling
Topic : Loop Unrollingsource of the topic : Code Complete2
Loop Unrolling, is a technique for optimizing parts of computer programs. The goal of loop unrolling is to reduce the amount of loop housekeeping.
Note: Loop unrolling undesirable if you are concerned about readability of the code.
| // Example of normal loop i=0 while ( i < count ) { a[ i ] = i; i++; } |
Use this technique only when you desire for code optimization. It will severely hurts program readability
| // Loop unrolled once i = 0; while ( i < count -1 ) { a[ i ] = i; a[ i + 1 ] = i + 1; // Unrolling once i = i + 2; } if ( i == count) { // These lines pick up the case a[ i - 1 ] = i - 1;// that might fall through the } // cracks if the loop went by // twos instead of by ones |
The technique replaced the original a[ i ] = i line with two lines, and i is incremented by 2 rather than by 1. The extra code after the while loop is needed when count is odd and the loop has one iteration left after the loop terminates.
We can see a gain of 43% in performance with loop unrolling once.
| // Loop unrolled twice i = 0; while ( i < count - 2 ) { a[ i ] = i; a[ i + 1 ] = i+1; a[ i + 2 ] = i+2; i = i + 3; } if ( i <= count - 1 ) { a[ count - 1 ] = count - 1; } if ( i == count - 2 ) { a[ count -2 ] = count - 2; } |
We can see a gain of 43% in performance with loop unrolling once.
The results indicate that further loop unrolling can result in further time savings, but not necessarily so, as the Java measurement shows.
Friday, April 18, 2008
Tips on Using loop statement in Java
Source of Topic: Effective Java, Programming Language Guide, by Joshua Bloch.
"The most powerful technique for minimizing the scope of a local variable is to declare it
where it is first used."
Prefer for loop over to while loop.
Reason: for loop has a chance of initializing the loop variables, limiting the scope to exact region where they're needed.
For example, here is the preferred way of iterating over a collection:
| for ( Iterator i = c.iterator(); i.hasNext(); i++ ) { doSomething ( i.next() ) ; } |
code fragment
| Iterator i = c.iterator(); while (i.hasNext()) { doSomething(i.next()); } ... Iterator i2 = c2.iterator(); while (i.hasNext()) { // BUG! doSomethingElse(i2.next()); } |
Above error is resulted with the habit of cut-and-paste the code: It initializes a new loop variable, i2, but uses the old one,
i, which unfortunately is still in scope. Above code doesn't give any compile error or doesn't throw any exception. Runs silently.
Instead of iterating over c2, the second loop terminates immediately, giving the false impression that c2 is empty. Because the
program errs silently, the error can remain undetected for a long time.
If the analogous cut-and-paste error were made in conjunction with the preferred for loop
idiom, the resulting code wouldn't even compile. The loop variable from the first loop would
not be in scope at the point where the second loop occurred:
| for (Iterator i = c.iterator(); i.hasNext(); ) { doSomething(i.next()); } ... // Compile-time error - the symbol i cannot be resolved for (Iterator i2 = c2.iterator(); i.hasNext(); ) { doSomething(i2.next()); } |
Moreover, if you use the for loop idiom, it's much less likely that you'll make the cut-and-
paste error, as there's no incentive to use a different variable name in the two loops. The loops
are completely independent, so there's no harm in reusing the loop variable name. In fact, it's
stylish to do so.
Iterating over random access list: ( examples of random access lists: ArrayList, Vector etc. )
| //Common Practice for (int i = 0; i < list.size(); i++) { doSomething(list.get(i)); } // High-performance idiom for iterating over random access lists for (int i = 0, list.size(); i < n; i++) { doSomething(list.get(i)); } |
This idiom is useful for random access List implementations such as ArrayList and Vector
because it is likely to run faster than the “preferred idiom” above for such lists. The important
thing to notice about this idiom is that it has two loop variables, i and n, both of which have
exactly the right scope. The use of the second variable is essential to the performance of the
idiom. Without it, the loop would have to call the size method once per iteration, which
would negate the performance advantage of the idiom. Using this idiom is acceptable when
you're sure the list really does provide random access; otherwise, it displays quadratic
performance.
Printing the arrays in Java programming language
| // Common practice of printing the array in Java for( int i = 0; i < array.length; i++) { System.out.println(array[i]); } // Best way of printing the array in Java System.out.println( Arrays.asList(array) ) ; |
Loop over an Array in java:
| // Loop through an Array using for each for( int intVal : array ) { doSomething(intVal); } |
Tuesday, April 01, 2008
Divide and Conquer algorithms, trick
Take Binary search as an example:
in each step we need to calculate "mid".
//Common practice of doing this:
// Broke - if (start + end) > Integer.MAX_VALUE
// Mid value will be assigned with -ve value.
mid = (start + end) / 2;
// Better way to avoid the problem
mid = start + (end - start)/2 ;
checking the oddity of a integer number in java
// Worng way to check the oddity
public boolean isOdd(int num){
return (num % 2 == 1) // Broken- for all -ve odd numbers
}
// Right Solution
public boolean isOdd(int num){
return (num % 2 != 0)
}
// Much better and Faster
public boolean isOdd(int num){
return (num & 1)
}
Wednesday, March 12, 2008
Binary Search in java by Joshua Bloch
The bug is in this line: int mid =(low + high) / 2;
1: public static int binarySearch(int[] a, int key) {
2: int low = 0;
3: int high = a.length - 1;
4:
5: while (low <= high) {
6: int mid = (low + high) / 2;
7: int midVal = a[mid];
8:
9: if (midVal < key)
10: low = mid + 1
11: else if (midVal > key)
12: high = mid - 1;
13: else
14: return mid; // key found
15: }
16: return -(low + 1); // key not found.
17: }
It
fails for large values of the int variables low and high. Specifically,
it fails if the sum of low and high is greater than the maximum
positive int value (pow(2 , 31) - 1). The sum overflows to a negative
value, and the value stays negative when divided by two. In C this
causes an array index out of bounds with unpredictable results. In
Java, it throws ArrayIndexOutOfBoundsException.
So what's the best way to fix the bug? Here's one way:
int mid = low + ((high - low) / 2);
Probably faster, and arguably as clear is:
int mid = (low + high) >>> 1;
Friday, February 29, 2008
How to design a good API and Why it matters
Wednesday, December 05, 2007
The Eight Fallacies of Distributed Computing
2. Latency is zero
3. Bandwidth is infinite
4. The network is secure
5. Topology doesn't change
6. There is one administrator
7. Transport cost is zero
8. The network is homogeneous
Monday, July 16, 2007
Quotationary
Never, never waste a minute on regret. It's a waste of time."