An Infinite GC Problem

Recently in work, I encountered an interesting GC (garbage collection) related problem. We have a console like application, when a user logs in, the program loads the corresponding history file so that the user is able to look for “recent commands”. However, when the history file is very large (say, 200 MB), this loading process triggers GC. This sounds right because the file is very large, reading it all into the memory will create a memory shortage and thus triggers the GC.

A Benchmark Flaw

Would declaring a String variable and then using it run faster or just using a String literal run faster? I had this in mind, and made the following test. public static void main(String[] args) { String a = "kNuZbcI4No"; Path path = Paths.get("10000.txt"); long start2 = System.currentTimeMillis(); try (Stream<String> lines = Files.lines(path)) { lines.forEach(s -> s.equalsIgnoreCase("5GxtHQS42y")); } catch (IOException e) { System.out.println(e); } long end2 = System.currentTimeMillis(); long start1 = System.

Convert Plaintext to ANKI Decks

ANKI is a software that uses flash cards to help you memorize stuff, such as improving vocabulary for a foreign languge. I have a vocabulary book in .doc format, and I want to convert it into decks of flash cards that Anki can recongnize. After some massage, I obtained a text file with the following layout: word definition1 definition2 word definition1 word definition1 definition2 definition3 Anki accepts several plaintext formats, the one I used, is:

Numbers in Java

I encountered a problem where I need to put numbers into a set, and later check whether a number is contained in the set. But since we are using Set<Long>, an idea crossed my mind: will 1 equal to 1? – If I create two Long object holding the same value, are they consider equal by Set? Yes. Because the hashcode method is implemeted as follows: return (int)(value ^ (value >>> 32)); So only the value of that Number object matters, as opposed to the “regular” implementation:

JSONP Front & Backend

Single Origin Policy It means the elements in cs.columbia.edu can only request resources in its domain or its sub domains, such as clic.cs.columbia.edu. But sometimes a web page on clic.cs.columbia.edu may need to request resources on cs.mit.edu. There are many ways to deal with this problem, but through out my internship project, I found JSONP is the most convenient way. How to Bypass It? If single origin policy is really the case, why you can see an image in a web page that may be hosted on some other server?