Sunday, October 23, 2011

External MergeSort Sample Code

Today I practiced external merge sort just for fun. Here is the java code, for merge-sorting 5 sorted files, each of which contains a list of sorted integers. The input are out0.txt, out1.txt, out2.txt, out3.txt, out4.txt, output is sorted.txt.

import java.io.FileWriter;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class ExternalMergeSort
{
public static void main(String[] args) throws Exception
{
// initialize n buffers for merge sort
List bufferList = new ArrayList();
for (int i = 0; i < 5; i++)
{
bufferList.add(new MergeSortBuffer("out" + i + ".txt"));
}

// output stream
PrintWriter out = new PrintWriter(new FileWriter("sorted.txt"));

// store merge sort result into output buffer
int[] outputBuf = new int[1000];

// merge until only one mergebuffer left
while (bufferList.size() > 1)
{
int min = -1;
int minPtr = -1;
for (int i = 0; i < bufferList.size(); i++)
{
if (minPtr < 0 || bufferList.get(i).pokeNext() < min)
{
min = bufferList.get(i).pokeNext(); minPtr = i;
}
}

// now we got minPtr buffer, write it out
out.println(bufferList.get(minPtr).getNext());

// remove the maxPtr buffer if it doesn't have elements anymore
if (!bufferList.get(minPtr).hasNext())
{
bufferList.remove(minPtr);
}
}

// output last buffer
MergeSortBuffer buf = bufferList.get(0);
while(buf.hasNext())
{
out.println(buf.getNext());
}

out.close();
}
}

--------------------------------------------------

import java.io.BufferedReader;
import java.io.FileReader;

public class MergeSortBuffer
{
private BufferedReader reader;
private int[] buf = new int[1000];
private int bufSize;
private int start;

public MergeSortBuffer(String fileName) throws Exception
{
reader = new BufferedReader(new FileReader(fileName));
refillBuf();
}

public boolean hasNext() throws Exception
{
return bufSize > 0;
}

public int pokeNext() throws Exception
{
return buf[start];
}

public int getNext() throws Exception
{
int next = buf[start];
start++;
if (start >= bufSize)
{
refillBuf();
}
return next;
}

private void refillBuf() throws Exception
{
int i = -1;
while (true)
{
String line = reader.readLine();
if (line == null || line.equals(""))
{
break;
}
i++; buf[i] = Integer.parseInt(line);
if (i + 1 == buf.length)
{
break;
}
}

start = 0;
bufSize = i + 1;
}
}

Sunday, October 16, 2011

来美国父母老人探亲医疗保险问题

最近根据网上的讨论仔细攒了一篇超强的美国父母探亲保险文章.很多人的父母都有心脏病或者心脏有问题。这种病有时候确实不能耽误。大概的情况就是,即使没有保险也可以去看急诊并且不付或者少付款。 但操作中有些细节的东西, 详情请看USA Visiting Parents Insurance Coverage

Tuesday, October 11, 2011

FindTheBest.com Alternatives Everyone?

I was searching for comparison engine related topics on the web and came across FindTheBest.com. It is a startup that is trying to do this be-all-end-all type of work, to compare any and all services, products etc.

But, when I visited the site, I have to say, it is not very impressive. The site seems a bit cluttered and search loads slowly, also, the search box slides far to the right hand side. It is a surprise that the search result is powered by Google custom search.

I couldn't believe FindTheBest.com secured a lot of VC funding. A one-man shop like JiansNet.com has good search result, and the best part is that it is not powered by some type of custom search.

The bottom line is that, it is always interesting to see this and other startups popping up from time to time, but only to see that they are still perfecting their technology/websites.

Tuesday, March 29, 2011

Skechers Promos and Coupons

I buy and wear skecher shoes. They are the best, light weight and good quality. Other than Skechers, I also have new balance, Nike etc. But to me, fashion-wise, Skecher shoes are more chic/elegant.http://www.blogger.com/img/blank.gif

Just checked our site, we have some pages that are related to Skechers here:
Skechers Promotions and Sales

In the future, if Skecher has any sales, we will post more, just love it...

Friday, July 9, 2010

free site search engines

For a decent website with couple hundred pages or more and keeps growing, you need a on-site search engine for your website. This is important so that your visitors could find pages easily.

Below are some free or cheap site search engines you could consider.

http://www.freefind.com
Free search engine for your website. FreeFind.com lets your visitors search your website. Add a search engine to your website today, for free, in less than ten minutes. This is the fastest and easiest way to add professional level searching to a website.

http://www.atomz.com
Atomz Site Search: The premier free search tool for your website.

http://www.picosearch.com
Add a free site search engine to search your web site - no software, easy to install, free! Powerful options, large maximum pages, more professional search features for business site search.

http://www.bravenet.com/webtools/search2/
Site search and free site search by bravenet.com. Let visitors search your site.

http://www.jrank.org
Are your visitors getting lost on your website? Put a search engine on your web site to help your visitors find the content they're looking for. Completely free, lightning fast, and super-easy to use.

Other than that, JiansNet.com is also a search engine for useful information for overseas Chinese in USA.

Sunday, July 4, 2010

Integration of Product Reviews on Google

Google is entering more into the semantic web by just brute force. Lately it has integrated product ratings and reviews from sources like:

--Amazon.com
--Overstock.com
--ePinions.com

Besides these large eCommerce sites, Google has also integrated reviews from different vendors through review engines such as Bazaarvoice.

So, when you do a search on Google product search, you will see full-length reviews, here is a sample link:
http://www.google.com/products?q=toy

Searching on Google.com will show snippet of a vendor's review content and linking back to the vendor's site.

In this regard, Google is definitely beefing up shopping related searches and compete with Microsoft Bing in terms of shopping search.

I think some day, eCommerce sites might be able to submit reviews directly to Google.

Monday, June 28, 2010

Ten Tips for a Successful Internet Startup

Below are the 10 rules for creating a successful internet startup.

1. Don't wait for a revolutionary idea. It will never happen. Just focus on a simple, exciting, empty space and execute as fast as possible

2. Share your idea. The more you share, the more you get advice and the more you learn. Meet and talk to your competitors.

3. Build a community. Use blogging and social software to make sure people hear about you.

4. Listen to your community. Answer questions and build your product with their feedback.

5. Gather a great team. Select those with very different skills from you. Look for people who are better than you.

6. Be the first to recognize a problem. Everyone makes mistakes. Address the issue in public, learn about and correct it.

7. Don't spend time on market research. Launch test versions as early as possible. Keep improving the product in the open.

8. Don't obsess over spreadsheet business plans. They are not going to turn out as you predict, in any case.

9. Don't plan a big marketing effort. It's much more important and powerful that your community loves the product.

10. Don't focus on getting rich. Focus on your users. Money is a consequence of success, not a goal.