MongoDB

October 8, 2010 Leave a comment

I have been using MongoDB for a new project which is coming out soon. So far I am impressed with it. The development focus really shits towards user requirements rather than endlessly playing with SQL, prepared statements, ORM and on and on.

The one problem I have noticed is not really a problem with Mongo but is rather because it is still new to the industry. The hosting providers have not adopted it yet. So if you want to use Mongo and want to host it on and don’t want to host it yourself then the cheap hosting plans won’t work.

This is because the php driver mongo.so needs to be deployed and enabled in php.ini. Hosting providers don’t give you that ability in their base plans which cost $5/month. It’s not an issue if you get dedicated hosting or rent a virtual machine.

Categories: Uncategorized

Coming back…

September 14, 2010 Leave a comment

Haven’t put up a new post in a while. Been looking for jobs, finding one and starting it… Well TrophyHound.com is up for anyone to use!

A amazing collection of lecture videos that my dad sent me. 100 Lectures

Categories: Uncategorized

LabelTop For Food now available!

You can find it here: http://www.beforemotion.com/food

Enter any specific food’s name or just a generic food and see the results. Examples are:
Big Mac
Butter
Chicken
Campbells
and so on…

Categories: Reviews

What’s GMail doing?

May 24, 2010 1 comment

See the screenshot below and do you know if my gmail session is secure or not?

Categories: Uncategorized

Google Calendar Bug on Mac OS X

This was really surprising that Google missed this. Apple always surprises me when it doesn’t provide basic computer features and when it does do so then it is hailed as ‘magic’ or some other kind of break through. Meanwhile, other operating systems have been providing that feature for decades. Some examples are:

- Spaces on OS X, well having multiple screens has been provided by solaris and linux for years and years
- Multithreading on iphone. This is such an old concept and is a highly studied and solved problem. It was introduced first with the earliest preemptive kernels. Why is it so new on iphone? Maybe someone in the marketing department knows.

Anyway, I digressed. The bug is that Google Calendar relied on local OS to see what time it is. Normally this would be fine. But when travelling across timelines it caused a problem. I went from the East coast to the West and while I do have internet here, OS X did not bother to update the clock by subtracting 3 hours (though Windows XP would have, I have not used Win7 but I imagine it does too). Now my google calendar events started alerting me to events based on my computer clock which is 3 hours ahead of what it should be. And for a few seconds I entered panic mode that missed my events for last 3 hours till I noticed the issue :).

Google Calendar should go to a time server for current time when an internet connection is available. They don’t even have to maintain one, just use the one provided by US Navy which is the official one anyway. If there is no internet connection available then it is a harder problem. But at least solve the the former of the two use cases.

I have updated my OS X clock manually and things are in order once again. Thanks for reading.
* I know you can set the clock to update automatically but why isn’t it checked to true by default. Who wants an inaccurate clock. Plus, the bug is not in OS X it is in Google Calendar.

Bubble sort in Java

Bubblesort is one of the simplest sorting methods. It also very inefficient. Though in the best case when the elements are already sorted, then its run time is O(n). Otherwise it is O(n^2).

package com.labeltop.sort;

public class BubbleSort {
	public void sort(Comparable[] comparables) {

		int size = comparables.length;

		// loop till swaps are being done
		while (true) {
			// reset it
			boolean foundSwap = false;

			// loop over values
			int i = 0;
			while (i < size) {
				// don't care about last value
				if (i == size - 1)
					break;

				// check for swap i.e. c1 > c2
				if (comparables[i].compareTo(comparables[i + 1]) > 0) {
					Comparable temp = comparables[i];
					comparables[i] = comparables[i + 1];
					comparables[i + 1] = temp;
					foundSwap = true;
				}

				// keep on...
				i++;
			}

			// check if there were any swaps
			if (!foundSwap)
				break;
		}
	}
}
Categories: Java, Java Misc, Java Sorting

Quicksort in Java

QuickSort is one of best sorting algorithms. While the worst case scenario is O(n^2), the average case is O(nlgn). Additionally, it is possible to implement in highly optimized way as well do several of its parts in parallel.

package com.labeltop.sort;

public class QuickSort {

	public void sort(Comparable[] c) {
		quicksort(c, 0, c.length-1);
	}

	private void quicksort(Comparable[] comparables, int start, int end) {

		// get a pivot point
		int pivot = start + ((int) (Math.random() * (end - start)));
		Comparable cPivot = comparables[pivot];

		// where to start on either side of pivot
		int left = start;
		int right = end;

		// loop till they overlap
		while (left <= right) {
			// find first on left that is bigger than pivot
			while (cPivot.compareTo(comparables[left]) > 0) {
				// more towards pivot
				left++;
			}

			// find first on right that is less than pivot
			while (cPivot.compareTo(comparables[right]) < 0) {
				// more towards pivot
				right--;
			}

			// exchange them
			if (left <= right) {
				Comparable temp = comparables[left];
				comparables[left] = comparables[right];
				comparables[right] = temp;
				//go to next ones towards the pivot
				left++;
				right--;
			}			
		}
		
		//recurse on left
		if (right > start) {
			quicksort(comparables, start, right);
		}
		//recurse on right
		if (left < end) {
			quicksort(comparables, left, end);
		}
	}

}
Categories: Java, Java Misc, Java Sorting
Follow

Get every new post delivered to your Inbox.