Friday, September 16, 2016

Linux / Mac Command Hack

1. Read MANIFEST.MF file of a .jar file
$ unzip -q myarchive.jar META-INF/MANIFEST.MF
2. Show public IP for my laptop
    1) dig
1
2
dig o-o.myaddr.l.google.com txt @ns1.google.com +short
nslookup -type=txt o-o.myaddr.l.google.com ns1.google.com
"10.11.12.13"
OpenDNS:
1
2
dig myip.opendns.com @resolver1.opendns.com +short
nslookup myip.opendns.com resolver1.opendns.com
10.11.12.13
Akamai:
1
2
dig whoami.akamai.net. @ns1-1.akamaitech.net. +short
nslookup whoami.akamai.net. ns1-1.akamaitech.net.
10.11.12.13
other usage
1
2
dig o-o.myaddr.l.google.com txt
nslookup -type=txt o-o.myaddr.l.google.com
returns txt record of DNS request to authoritative source address
edns0-client-subnet if available, showing original DNS request source address
1
2
dig o-o.myaddr.l.google.com txt @8.8.8.8 +short
nslookup -type=txt o-o.myaddr.l.google.com 8.8.8.8
"198.51.100.1"
"edns0-client-subnet 203.0.113.0/24"
    2) curl
curl ifconfig.co 
 

Tuesday, April 19, 2016

Java Spring, JPA Useful materials, problem-solution

1. JPA Tutorial
http://www.java2s.com/Tutorials/Java/JPA/index.htm

2. Spring RestController doesn't set parameter for PUT request
FROM:
http://stackoverflow.com/questions/29017593/spring-4-restcontroller-not-receiving-data-from-put-request
This is a limitation of the Servlet Spec and the inner workings of Spring for populating model attributes.
First, the spec says
3.1.1 When Parameters Are Available
The following are the conditions that must be met before post form data will be populated to the parameter set:
  1. The request is an HTTP or HTTPS request.
  2. The HTTP method is POST.
  3. The content type is application/x-www-form-urlencoded.
  4. The servlet has made an initial call of any of the getParameter family of methods on the request object. If the conditions are not met and the post form data is not included in the parameter set, the post data must still be available to the servlet via the request object's input stream. If the conditions are met, post form data will no longer be available for reading directly from the request object's input stream.
Second, your handler methods' second parameter, the one of type Note, is actually considered a model attribute, as if it was implicitly annotated with @ModelAttribute. As such, it is processed by Spring's ModelAttributeMethodProcessor. This HandlerMethodArgumentResolver uses the getParameter (and its family of methods) for populating the created instance's fields.
Since this is a PUT request, the parameters are not retrievable through getParameter. However, they are still accessible through the request body, but Spring doesn't go there for model attributes.
You can do the conversion yourself. But I suggest you change your request content to JSON or XML for PUT and use @RequestBody annotated parameters.

Thursday, January 7, 2016

Javascript confusions and tricks

1. Console.log output of an array of objects VS an array of primitive value
Console.log output of objects is a pointer, not real value.
For example:
var array = [1,2,3,4,5,6,7,8,9];
console.log("start");
for(var i = 0; i < array.length; i++){
  console.log(i + " = " + array[i]);
  console.log(array);
}
console.log(array);
console.log("end");
array.push(9999);

The result out put is:
start
0 = 1
[1, 2, 3, 4]
1 = 2
[1, 2, 3, 4]
2 = 3
[1, 2, 3, 4]
3 = 4
[1, 2, 3, 4]
[1, 2, 3, 4]
end

But the output of this:

var array = [{value:1},{value:2},{value:3},{value:4}];
console.log("start");
for(var i = 0; i < array.length; i++){
  console.log(i + " = " + array[i]);
  console.log(array);
}
console.log(array);
console.log("end");
array.push({value:9999});
is:
start
0 = [object Object]
[Object, Object, Object, Object]
  ->0: Object1:
  ->1: Object2:
  ->2: Object3:
  ->3: Object4:
  ->4: Object
        value: 9999
         ->__proto__: Object
         length: 5
         ->__proto__: Array[0]
1 = [object Object]
[Object, Object, Object, Object]
2 = [object Object]
[Object, Object, Object, Object]
3 = [object Object]
[Object, Object, Object, Object]
[Object, Object, Object, Object]
end