Friday, January 29, 2016

Pretty Print JSON

Sure, online JSON Formatter is nice. Try this one here, for example: https://jsonformatter.curiousconcept.com/. It helps you understand your JSON. However, if your JSON is redicously large you need to make your own beautfier.

Json simple's JSONParser and Google's Gson can help you. First you need to find some jars.

Here is a simple Java program
import java.io.BufferedReader;
import java.io.FileReader;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
 

public class JSONPretty {

 public static void prettyPrint(String jsonString) {
  JsonParser parser = new JsonParser();
  JsonObject json = parser.parse(jsonString).getAsJsonObject();
 
  Gson prettyGson = new GsonBuilder().setPrettyPrinting().create();
  String prettyJson = prettyGson.toJson(json);
  System.out.println(prettyJson);

 }
 public static void main(String[] args) {

  if (args.length!=1) {
   System.out.println("USAGE: java JSONPretty [data.txt]\nwhere data.txt contains lines of JSON\n");
   return;
  }
  
  try {
 
   String fileName = args[0];
   BufferedReader readbuffer = new BufferedReader(new FileReader(fileName));
   String strRead;
   
   while ((strRead=readbuffer.readLine())!=null){
    prettyPrint(strRead);
   }
   readbuffer.close();
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
 

}

Thursday, January 28, 2016

Android: here I come again

Just installed the Android Studio. http://developer.android.com/sdk/index.html.

Now it is off Eclipse. Why? Everyone seems to hate Eclipse saying it slow and crash. NO. Eclipse works for me just fine. I still love it. This IntelliJ based thing is much like Eclipse only people complain less.

Ok, let's see what we got here. It installs... but the emulator won't run. Saying Intel HAXM hardware acceleration thing needed. Tried to install that. It simply won't install. Fortunately there is way to get around... See this stackoverflow link. You can create a non Intel..an ARM emulator thing. Yes it is slow.

When I last worked with Android for fun... It was close to THREE YEARS AGO with version 2.2 Froyo API level 8. Now we are at API level 23 Marshmallow. Yes, a lot to catch up..but I STILL do not have a new app idea yet. (Don't suggest outrageous things like make it mow your lawn). My last app idea was a toy piano that let you play a few notes (no match against gosh excellent piano apps out there).

I can probably modernize my old apps... but I still make absolutely 0 money on them.

Wednesday, January 27, 2016

Google beats Go

I am not surprised. Computer program beats human in the game of Go. See here.

Go is an incredibly complex ancient game with simple rules. I won't even attempt to play this gosh-so-hard game. Everyone ought to try to get a taste of how hard this game is.

Something complex needs a tireless computer to do. But is this program written with the Go Programming Language?

What's the next thing computer wants to beat?

Do you feel threatened that computers will take over the world? Look at this, now robots can cook. See here.

Ok, do not, ever, give robot guns, Ok? Robocop in the movies only please.

Tuesday, January 26, 2016

Most hated programming languages

Came across this article about programming languages that programmers hate.

Yes I agree with much of this article. Those who have not seen PERL do not know the evil of it. C++ is absolutely ridiculously complex. Now now, that public static void main method in Java is just a bit mouthful.

Yes, it can be a bit clumsy especially its wacky Date and Calendar classes... also wacky awkward in all this File Stream stuff... But java has so many good useful libraries. For those who like a cleaner more interesting version of Java should look at groovy.

Yes, VB.NET stinks big time. Why aren't you using C# instead if you are stuck with (or have chosen) the Microsoft platform.

Yes, PHP seem like a toy... and I don't think I will ever need Python when I have java around. Uh hem, the author actually liked Python.

Ok I need to add: Objective C on this list. Even more horrible than C++ and it is superset of C? Ultra wacky syntax. But if you need to program Apple things natively, once upon a time you must use it.

Haven't seen Swift in action yet but it looks much, gosh, much more approachable.

Here is an observation: if something is hard, it will get easier later. Apple programming is one example. So is Windows programming. Windows SDK is hard. MFC is intended to make it easier, still damn hard...until .NET things come along with C# (which just stole from Delphi)

But nowadays javascript is the king... all sorts of javascript libraries out there. Think you know it? It can get incredibly difficult when people go crazy with it. People love...and hate javascript.

Thursday, January 7, 2016

CSS unselectable text

Came across a strange requirement... some text on the webpage should not be selectable, as in some EULA text. Ok this is stupid. Alt-Printscreen? Take out phone and take screenshot? You just can't protect your text. Also view-source too.

But CSS let you do this. Found a stackoverflow link that shows how. Try below:

<style>
.noselect {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
 </style>

Selectable text.

Unselectable text. I have class="noselect"

Wednesday, January 6, 2016

Article about 1 (on January 1)

I saw this quite fascinating article about 1 on January 1. http://www.forbes.com/sites/kevinknudson/2016/01/01/the-ubiquity-and-utility-of-the-number-1/.

Are you convinced yet? 0.9999... (infinitely many 9's) IS 1. Not getting close to, but IS 1.

The ratio sin(θ)/θ tends to 1 as θ goes to 0. The author is avoiding the typographical difficulty of the limit notation... Yes you have seen that in calculus and this thing is quite useful because it helps proving the derivative of sine is cosine...

Yes! I remember the clever trick needed to do the integral of secant x.

People will go to great depth to solve problems such as integrating things. In real life do you need? Probably not. But it is accomplishment to able to integrate that.

One can probably say a ton more about the number 1. Ok let me just add 1 thing. This is only (positive integer) number that is neither prime nor composite!

Tuesday, January 5, 2016

7th row of Periodic Table completed

Look! New elements are found! The 7th row of the Periodic Table is completed! http://www.theguardian.com/science/2016/jan/04/periodic-tables-seventh-row-finally-filled-as-four-new-elements-are-added.

Look at what the Nobel laureate say about this: "To scientists, this is of greater value than an Olympic gold medal”.

Just how do they discover elements? They smash particles together many many times and the new elements last for a fraction of a second. http://www.latimes.com/science/sciencenow/la-sci-sn-new-elements-20160104-story.html

It takes several months to try this smashing experiment roughly 10 quintillion times. And we’re not always successful,” she said. At most, it will work about three times in 10 quintillion tries, she added

All that work... for a fraction of a second of the new big elements... is there use of those? If there is of any use, better use that in that fraction of a second.

This is olympic gold medal for science... but I fail to share the enthusiasm.

I never quite understood the periodic table: why is the periodic table not in a perfect box? Why is there 2 extra rows that needs an asterisk... Electron configuration I guess. Chemistry has always been over my head.

And of course, there are different world within the proton... the quantum world that only your PhD friends have a clue or so.