Monday, November 19, 2012

PrettyTime and Joda playing nice

PrettyTime is a library for printing elapsed times such as "2 hours ago". Joda is the library to replace JDK's ancient and problematic java.util.date package.

Unfortunately, PrettyTime uses JDK's date class only, and doesn't welcome Joda classes such as LocalDateTime to be passed in directly. Also, it does not support time zones yet (apparently that's low priority).

Because of its great i18n support (lots of translations) I live with this handicap, and convert:

    LocalDateTime now = LocalDateTime.now(DateTimeZone.UTC);

    //store this instant to db:
    long time = now.toDate().getTime();

    //then load it from db again:
    LocalDateTime nowAgain = new LocalDateTime(time);
    assert now.equals(nowAgain);

    //wrong: printing this is off by the local time zone difference to UTC:
    System.out.println(new PrettyTime().format(nowAgain.toDate()));

    //correctly adjusted:
    Date javaUtilDate = nowAgain.toDateTime(DateTimeZone.UTC).toDate();
    System.out.println(new PrettyTime().format(javaUtilDate));
This prints "moments ago". Phew! Time for beer.

Friday, November 16, 2012

Play framework: develop with custom domain and port

What it's about

This howto shows you how to use a custom host name and port number when developing with the play framework v2.

Why would you do that? 

In my case it's because I want the development environment to be as close to the final production environment as it can be.

Assumptions

You have play v2 installed, you start it command line, and you're developing with remote debugging in IntelliJ or Eclipse or whatever.
Your desired host name is example.com with port 80.

Steps

If your host name is not in the dns then add a hosts entry. It must point to your local ip address (such as 192.168.1.1), not to the loopback address 127.0.0.1.


By default, Skype listens on port 80 for incoming connections. Either shut down Skype completely for the time of development, or configure it to NOT listen on port 80. Just shutting it down for the moment of starting the embedded play server (Netty) isn't enough, because after a while Skype gets a hold if the port again.









In the console, type "play debug" as usual. But this time run with "run 80 -Dhttp.address=example.com".

Test it in the browser.

Final notes

There is no configuration within play for the port or host. If you deploy your app then you probably have that kind of config in Tomcat or so.

More info:
http://www.playframework.org/documentation/2.0.4/ProductionConfiguration
http://www.playframework.org/documentation/2.0.4/HTTPServer

As of now (version 2.0.4) running on a certain port (such as run 80) does not complain when another application or service is occupying that port already.

Monday, November 5, 2012

How important is the domain name today?

Even though domain names have become less important in the past decade, we can still find the old patterns in those of successful websites.

Why domain names were so important

For those of you who weren't there in the mid 90s, here's a bit of history. Don't laugh.
When the www became popular, domain names were a new thing. Not every business had a website. New internet businesses were founded with the domain name as company name.

An advertisement for a business such as amazon in the mass media (think television, or newspaper (in paper form)) had to make it clear that you can go and type that into the browser's address bar. Thus it needed to tell you the web address ... and that meant the full web address. Yes, including the top level extension .com. And yes, with the www, because that was the ultimate "web" indicator. And, not joking, including http://, because browsers required you to tell them what protocol you want. It could have been ftp, or gopher, how could it guess.

The older generation (my mother) was going bananas on all these strange characters... http//:? //http?  www.http? http@www? www.com@amazon?

Email was new too. My mother's email address was www.eleonor1948.com@hotmail... or so.

To not add to the confusion, you'd better stick to the .com extension like everyone else.

If you mistyped the address in the browser, all you got was an error message. Sorry. You could then goo... no wait, you could search for it on Altavista. If you had a bookmark or knew the address by heart. It was http://www.altavista.digital.com. (Yeah, the www in there is useless, but it probably wouldn't load the site without ...). Autocomplete wasn't invented yet.

Years later, because http became the most popular protocol, and "the internet" meant the web, browsers started to add the http:// prefix automatically if omitted.

Then, even more artificial intelligence was built in: converting a word such as amazon into http://www.amazon.com. What a salvation!

OK, it wasn't real AI, but it helped. And because everyone important used .com, it worked well. Everyone? well, mostly. The white house is on a .gov address. And because the .com belonged to someone showing pictures of naked women (safe for work), browser programmers went back to work to come up with even more magic: exception rules.

And today? 

Having .com in the business name isn't important anymore. Everyone's online. (Online? Yes, online/offline you know, modems...)

Amazon 2004
Amazon 2012




People don't type addresses anymore. The address bar is just to copy/paste, or for auto-complete, or to google the name because it's quicker, or to spell-check a word.

Users will find your site based on the name, no matter what address you have.

Patterns in domain names of the top visited sites

Here's what I've found when looking over Alexa's top ranked sites list, mostly the top 100.

They're all .com

And if they are not, then
  • Either they redirect .com to the primary domain (#6 wikipedia.org, #43 craigslist.org, #146 mozilla.org, #160 sourceforge.net)
  • Or it's a country specific domain (16x Google such as google.de)
  • Legal issues (#69 thepiratebay.se)
  • Domain hack  #80 adf.ly

2 syllables

Practically all internet brands have a 2-syllables, 1-2 word domain name, without hyphen, ending in .com. Goo-gle, face-book, you-tube, bai-du, twit-ter, ama-zon, linked-in (argument), blog-spot, tao-bao, si-na, yan-dex, word-press, e-bay, ...)
Exceptions are wikipedia (known as "wi-ki"), 1-syllable domains (live, bing), and abbreviations (qq, msn, vk).

Number domains

There are some number domains: #107 360.cn, #117 4shared.com, #157 56.com, #223 58.com

No hyphen

There are practically no domains with a hyphen. The first real website with a dash is #334 t-online.de, and that's because it's their business name. In case you're bored you can also take a look at #342 sergey-mavrodi.com and his Wikipedia page. The first site that went with a domain name with a minus in it is #442 over-blog.com, but apparently only until they got enough cash to buy the real one, and are redirecting now to overblog.com (#6177). So there really isn't any worth mentioning. A hyphen is a no-no.

Domain hacks

Domain hacks are becoming more popular. The well known del.icio.us #523 is now at delicious.com. Google uses #962 goo.gl for its url shortening service. (I surely missed some important ones, please comment.)

Typo domains, missing schwa

A new trend is domain names with a spelling mistake. Simply because every possible name you could come up with isn't available as dot com. It's often the schwa in the last syllable that's omitted. Examples are #36 tumblr.com, #201 scribd.com. Twitter #8 initially launched as twttr.com. #717 disqus.com is more than a typo, but falls into that category. (I surely missed some important ones, please comment.)

Conclusion about today's domain selections

When choosing a domain name for a new global site (the next twitter killer), people go for
  • a relatively short (not 3 or 4 words),
  • possibly with a typo (because nothing else is available)
  • never hyphenated
  • dot-com domain.
  • Or they invent a new word (that's hard to remember).
  • Or alternatively a very short domain hack.

And the future?

Next year, in 2013, up to 2000 new top level domains will become active. Even though we have lots of global tld's already (not cctld's, those are fine), no one important uses them. Will this mess make .com even more important, or will lots of domain hacks appear? What's your opinion?

What do you do when you're in need of a new, attractive name? Do you try to buy one? Even though most domain names are inactive, the owners usually have a different opinion about their value. Do you misspell, hyphenate, choosealongname, invent a new word, go .net or .org, or look for a domain hack?




WWW or not?

Up until today the web still hasn't found consensus about whether addresses should use the www or not. It's a useless leftover from the past. Most websites still use it, including the tops (google, facebook, yahoo, amazon, ebay, bing, msn, paypal ...), newer ones (twitter, wordpress, stripe) don't.  

What's important is that both addresses are functional, and that one redirects to the other.
Example rewrite rule for Apache to redirect to non-www:
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
It has become common practice to not use www with 3rd level domains, but to optionally make it a redirect. Example: de.wikipedia.org, with a forwarding from www.de.wikipedia.org



Thursday, November 1, 2012

Google: from Innovator to Average Quality Copycat?

Even though Google keeps shutting down products that did not take off or that don't pay off, they still pursue way too many new businesses and new products to become great at any one of them. Well, some are great. A few. But more and more are becoming just average.

Why is that?

Apparently Google has reached a critical size, and maintaining the existing stack demands huge resources. For developing new products, such as Google Drive, there just aren't enough a-list candidates available. And there is competition on the job market. While 10 years ago any candidate would choose Google over Microsoft, there are far more attractive players on the market now. Plus: starting your own business has never been cheaper.

At the same time other, agile players appear on the market, focusing on just one product.

Why do I use Google products even though there are viable alternatives?

  • Almost 100% uptime.
  • It's usually above average in functionality. 
  • The free version is not crippled beyond usefulness.
  • It's integrated with all the other products, same login, 1 click away.
  • "Don't be evil" motto. They don't run out of money and need to find new sources of income.
  • I don't want to learn a new product every 2 years. A new player might disappear quickly when running out of fundings. 

3 product categories

Products, not just for software, can be grouped into 3 categories:
  1. Those that make you freak out from time to time.
  2. Those that just work as they should.
  3. Those that, besides working, have some awesome things that you wouldn't even think of, but once you see them, instantly understand and love.
Microsoft products used to be in group 1. Your MS Word crashed and you didn't have the document stored? Windows blue screen?

Google was a breeze. Google products kept coming out with those category 3 features. Lots of innovation. Page rank. Text ads. Chrome is full of them. The software update process for example. Or how chrome opens tabs next to the current one instead of at the end. It took one instant, one click, and my thought was "Omg, why did no one think of this before!".

Enters Google Drive

Recently, Google products dropped to category 2. And the reason for this blog post is Google Drive, which is a clear category 1 product, and should be labeled Beta at most. But the Windows app "about" message gives it a stable version 1.5, and Wikipedia labels it as "stable". It only came out 5 months ago, but because Google entered that profitable market late, they apparently can't afford to label an "online backup service" as beta at this time.

Google Docs was good. My experience with the Google Drive Windows tool is bad so far. On the first day, after installation, and copying 2GB of data into the folder, it could not synchronize all files (had to re-try several times), gave useless error messages "an unknown issue occurred", crashed twice.
Now, a couple weeks later, I added a new folder with a 50MB file in it. Then I wanted to rename that folder, and Windows Explorer told me I can't because the file is locked (that must have been Google Drive). So instead (I did not wait) I created a new folder, and just moved the file itself (that worked). Job done, I thought. The next day, after waking Windows up from sleep mode, Google Drive tells me it crashed. It doesn't restart automatically. So I better check if my files are synchronized. As I drill down the folders I notice that they all have the green checkmark icon (synchronized). Arriving at the leaf, surprise surprise, the file is not synchronized.

Only now I realize that the web is full of articles about how Google Drive sucks, of people claiming that they lost files. A 26% hate rate is devastating (whereas Dropbox reaches almost 100% love rate from 600k people).

My experience with Dropbox

Way better. I've been using it for almost 2 years. Transfer rates are much slower, but that's not an important criteria for me. While using it almost daily, it never crashed, and I experienced the following 2 issues:
  1. Sometimes, when opening an MS Excel document (yes I still have some of those), Dropbox updates the change timestamp. This sucks, I don't want an entry in the changelog.
  2. One time, after waking up another device that was not synchronized in weeks, Dropbox thought that some files were conflicting, even though no one touched them in the meantime, and their content was identical too. What Dropbox did was keeping both "versions", one with a different file name (conflict and timestamp). Annoying, but no data lost.

My conclusion: Don't use Google Drive as a backup solution, have another backup somewhere. Or best, don't use Google Drive except for the Google Docs online documents.

A word to Google 

Please focus on the important products, innovate, and don't shut down the ones I'm using. And keep working on the robot car, I can't wait, the world will be a better place.

A word to Google Skeptics

This is good news for those who were concerned that Google would grow too big, take over the world, and know all about you. Nah. Remember the talks about breaking up Microsoft because it was too powerful, 12 years ago?