web analytics


Aug 29 2010

Sunday Math: Math is not that easy to go wrong!

Category: Mathematicsjagadeeshm @ 11:33 PM

Have you ever tried Math Equations where you have a problem statement and prove that your LHS [Left Hand Side] is equal to your RHS [Right Hand Side]?

Let us try something interesting, or something foolish!

How about proving 1 = 2 ?

How about another one?  Lemme see if I can try to prove 2 = 3!

They seem to be interesting about are big blunders of mathematical equations. Can you think about the fallacy behind these equations?

Equation 1: Prove 1 = 2

The fallacy is that numbers can not be divided by 0. So diving the equation by (X-Y) on both sides is almost impossible.

Equation 2: Prove 2=3

The fallacy behind this equation is that negative numbers can not simple square roots, i.e. square root of [2-(5/2)] doesn’t actually have any meaning!

That finally concludes that Math is not that easy to go wrong!

Tags:


Aug 22 2010

Sunday Math Trick: Mutiplication with 11

Category: Mathematicsjagadeeshm @ 11:56 PM

I believe most of you know the childhood trick of multiplying a number by 10! Yes, simply add 0 to the end of the number and that will be your answer.

But I am pretty sure most of you don’t know the trick with number 11, especially when multiplying 11 with 2 digit numbers.

Here is the trick –

Take the original number and imagine a space between the two digits and then add up the two numbers and put them in the middle.

For example, let us say you wanted to multiple 44 with 11, i.e. 44 X 11 = ?

Here is how you do it -

4_4

Now you need to add the two numbers and put them in the middle:

4_(4+4)_4

which is

484.

That is it! That is your answer.

Let us try another number – 35 times 11, i.e. 35 X 11 = ?

3_5

3_(3+5)_5

385

That is it! That is your answer.

But what  if the middle number adds up to a 2 digit number ?

Try, 79 times 11, i.e. 79 X 11 = ?

7_9

7_(7+9)_9

??

The above trick doesn’t work now…but you can add a clause to it. When this happens, simply insert the second number in the middle and add 1 to the first

so 7_(7+9)_9 becomes

7_(18)_9

(7+1)_8_9

which is

889. This is your answer

Wanna try another number?  How about 97 times 11, i.e 97 X 11 =?

9_(9+7)_7

9_(16)_7

(9+1)_6_7

1067.

That is it. That is your answer!

Again, remember that this trick only works when you multiply 11 with any two digit number only.

Tags:


Jul 07 2010

How to use ThreadFactory in Java

Category: Javajagadeeshm @ 8:09 PM

The factory pattern is an object oriented design pattern (a creational design pattern, to be more specific) used in software development to encapsulate the processes involved in the creation of objects.

I sometimes feel that Java Docs are really incomplete in terms of showing how certain things can be used. ThreadFactory is no exception.

Straight from Java Doc -

An object that creates new threads on demand. Using thread factories removes hardwiring of calls to new Thread, enabling applications to use special thread subclasses, priorities, etc.

Although, the basic idea is to create new threads on demand, ThreadFactory can be used for other purposes such as – debugging and exception handling.

Exception Handling

In multi-threaded applications we normally notice that some threads die due to uncaught exceptions. Now lets say you want to log all these exception. ThreadFactory solves this problem.

ExecutorService executor = Executors.newSingleThreadExecutor(new LoggerThreadFactory ());

executor.submit(new Runnable() {
 @Override
 public void run() {
 someObject.methodThatThrowsRuntimeException();
 }
});

Now LoggerThreadFactory can be implemented as follows -

public class LoggerThreadFactory  implements ThreadFactory {

 @Override
 public Thread newThread(Runnable r) {
   Thread t = new Thread(r);
   t.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler(){
      @Override
      public void uncaughtException(Thread t, Throwable e) {
        LoggerFactory.getLogger(t.getName()).error(e.getMessage(), e);
      }
   });
 return t;
 }
}

Debugging

ThreadFactory can be used for debugging by setting thread names. Here is an example

public WorkerThreadFactory implements ThreadFactory {

 private int counter = 0;
 private String prefix = "";

 public WorkerThreadFactory(String prefix) {
   this.prefix = prefix;
 }

 public Thread newThread(Runnable r) {
   return new Thread(r, prefix + "-" + count++);
 }
}

And other uses of ThreadFactory are to set thread priorities and to create demon threads.

Have you used ThreadFactory for a complete different purpose? Let me know.

Tags:


Apr 24 2010

Secret Google Search Engine for Hackers!

Category: Googlejagadeeshm @ 12:29 PM

Ever wondered where Hackers and Online Gaming geeks do their daily searches on Internet! Looks like Google did

satisfy them by providing a Hackers Search Engine as well.

What you are seeing below is probably one of Google’s Easter Egg and I bet mostly of us haven’t see this secret page

of Google yet!

Everything on this page in written in Leet, a language used to describe formidable prowess or accomplishment in the

field of gaming and computer hacking.

Hope there are many out there who are using it.

I am wondering how many such Google Easter Eggs are out there….

Tags:


Apr 22 2010

Top 5 Open Source Directories

Category: Uncategorizedjagadeeshm @ 11:03 PM

Resuability is good but re-inventing the wheel is not a good idea when you have so many open source directories
around. Although open source software have their own pros and cons, they generally evolve to answer developer
needs if not for end user.

Developers should consider becoming involved in an open source project to improve their skills and gain experience.

1. SourceForge

This is my favorite one. Projects are grouped by language and platform making it easy to search. Covers wide category
of open source software projects

Statistics

33 Million monthly unique visitors

103 Million page views per month

44 Million Monthly Visits

2.8 Million downloads each day

2.6 Million Registered Users

230K Source code repositories

2. GitHub

GitHub is more than just a place to share code. It’s a place to keep tabs on your favorite developers and projects,
easily contribute fixes and new features, and visualize what’s going on inside your codebase!

Statistics

235K Registered users

793K Unique repositories

3. Google Code

Who needs introduction to Google Code ?

Statistics

250K+ projects [wikipedia]

4. FreshMeat

This is definitely the place for Linux users hunting the software for work and play.

Statistics

1 Million monthly unique visitors

2 Million page views per month

Registered Users: 240K

Repositories: 790K

5. Ohloh:Root

Ohloh provides more visibility into software development by being one of the largest, maintaining more accurate and up-to-date
software directories available.

Statistics

1.6 Million monthly unique visitors

3 Million page views per month

Around 430K source code repositories

I have downloaded at least couple of projects from each of these directories. How about you?