Tuesday, December 16, 2014

Java: formatting text

Nowadays everybody says learn PHP, Python as first language. I beg to disagree. Don't forget C and Java! I even heard people write forget C and go C++ first. This guy is completely cluless.

C's printf is so useful in text-based things, and it is still needed today... to insert your variables in text. Sure, just add them and it works just fine. Then some guy will say dude Java String is immutable please append with use StringBuffer, and then another guy will say dude, use StringBuilder. Yes, this has to do synchronized or not, like that classic interview question that make some even seasoned java developer wet their pant during interview: Vector vs ArrayList. But it is still clumsy... and printf is nicer, especially if your text to display is some constant. The original Java did NOT have printf... but it got added later a long while ago. And there is this MessageFormat thing that works similarly too.

import java.text.MessageFormat;

public class Test {

 public static void main(String[] arg) {
  int a = 10;
  String name = "John";

  Object[] testArgs = { new Integer(a), name };

  MessageFormat form = new MessageFormat(
    "1. My brother {1} is {0} years old.");

  System.out.println(form.format(testArgs));

  String result = String.format("2. My brother %s is %d years old.",
    name, a);
  System.out.println(result);

  System.out.printf("3. My brother %s is %d years old.\n", name, a);

 }

}

Tuesday, December 9, 2014

My Third Android Phone: Moto G

My first Android phone was a gosh low end very basic one on Froyo with small screen. My first Android programs was developed there. It is crappy in a lot of ways but good for its time.

My second Android phone was a Nexus 4, for about $400. Stylish and cool and good developers' phone that keeps API updated. Shiny stylish. It's got Lollipop (not that it is a super ground breaking update except the long needed flashlight) Alas I cracked the back (but no big deal). Alas that power chord choked the tab so I can't USB (that's still ok cause I can get pics from cloud), although can't code anymore. Alas then part of the screen won't receive clicks! That's the region I use the 9 dot pattern the most. This means: the screen can get worn out. That's... still ok after I changed pattern. but it is now hard to tab on my voice mail's password. and then sometimes it will scroll and tap crazily. Gosh I need a new phone. It has been 2 years.

Shopping for new phone is unfun. The Nexus 5 and 6 are never available on Google Play. The 5 is reasonably priced. But I am sorry, it is matte not glossy? The 6 is very expensive even if it is available. Nexus has curious naming. Originally Nexus 7 and 10 means the inch size. Now that your phone size has bump into each other what is the next one going to be called? Buy it on Amazon? everything I see is International Version No Warranty.

The other one that has great review is the Moto X. Ooh you customize everything! At checkout it is whooping $549.

Get a contract one you will just eventually pay the same price.

The Moto G you can customize too but with exactly 2 options: white or black. Oh but at under $200. it is supposed to be well worth it.

Ok so I got one. first, the 2 metal bars in top and bottom are completely useless. They are not buttons that wake your phone up. It isn't a very light phone like the new IPhone 6 (that's ok). It comes with a "Launcher" that gives you 4x4 icons. Argh! I have been seeing 5x5 for 2 years since Nexus 4. Completely cannot stand it. It is like running Windows 3.1 when the rest of world running Windows NT... and this is not customizable until I downloaded the Apex Launcher. A huge let down by google. It should come out of box give you options to tweak your home screen and apps display.

I did not need to download such thing for Nexus 4.

When I migrated to Nexus 4... I think all my apps got installed. Hey Google Play knows what I downloaded. Nope. In new phone I got to download each one.

And the Moto G did not even come with a charger that you can break into USB? Even a freaking feature phone has that so it can be charged on a computer! No headphones not even an extremely cheap one.

Bright side: the colors are vivid. Camera is fairly decent. Nice and Loud. Better than not able to click on certain regions.

Soon I may be ready to come back to Android Development.

Wednesday, December 3, 2014

Sophomore's dream

So I came across this interesting named equation in this faboulous book Mathematics Devotion.(in its Appendix). This is the Sophomore's Dream:

Oh you can turn any definite integral into a summation like that? (no, just happens for those cases listed above).

Its proof is gloriously documented in here: http://en.wikipedia.org/wiki/Sophomore%27s_dream

It is kinda unfortunate I actually don't know/recall all of its proofs ingredients... I think I've seen it all. But that proof is way cool.

As the wiki says, oh there is the Freshman's Dream that erroneously says (x + y)n = xn + yn.... for poor freshmen who don't know the binomial theorem. High school freshman should know about the binomial theorem.

But I am not so sure if there are too many (college) sophomore know all the ingredients for the Sophomore's Dream...

The Mathematics Devotional book is fabulously written with great math quotes (but without the hardcore equations) and great looking "eye-candies" of computer generated pictures of fractals and other things.

This is for those who truly enjoys mathematics.

There are too many bullies out there portraying math as nerdy geeky with ugly kids wearing broken glasses taped together. Those who know and enjoy math do not look like that. Hollywood needs to treat science and math with respect. I need to see those math themed movies portraying mathematicians as protagonist.

是可忍、孰不可忍

The Chief Executive of Hong Kong is not able to take this Occupy Movement (Umbrella Revolution) anymore!

News link: https://hk.news.yahoo.com/cy-是可忍孰不可忍-222013941.html

You may or may not like him, but he is able to quote Confucious here.

See its origin: http://www.confucius.org/lunyu/ed0301.htm.

This means: he is not going to take this anymore. Now the police runs out of patience and there is now more police violence against the protestors, and some may be fighting back. Hong Kong is getting increasingly chaotic, but still better than tanks running over.

As I predicted now they are going on hunger strike and they are simply just hurting themselves. My new prediction these young people will simply give in to food and the whole thing will end with nothing changed.

So the 2 month standoff only created chaos and little will ever change, so we just have to BEG the people in power to be a bit more caring for people who don't have a future... Come on, housing is too expensive! But is choosing your own government head and occupying the streets going to get prices cheaper?

So I feel sad for Hong Kong.