Wednesday, April 25, 2012

SVG 101

Recently, start to look at SVG (Scalable Vector Graphics), which is a language for describing two-dimensional vector graphics in XML. SVG has many advantages including open standard, scalable images etc. I quickly went through www3school online tutorial, and wrote some notes about SVG language.

Keywords: Shapes, Filter, Gradient, Canvas, WebGL

SVG 1.1 Second Edition, which includes all the errata and clarifications, but no new features to the original SVG 1.1 was released on August 16, 2011.

SVG Basics
Creating SVG Files - Inkscape
Viewing SVG Files - Adobe SVG Viewer
SVG In HTML Pages - <embed>, <object>, <iframe> or inline, Link to an SVG File (standalone, *.svg)

SVG has some predefined shape elements
    * Rectangle <rect>
    * Circle <circle>
    * Ellipse <ellipse>
    * Line <line>
    * Polyline <polyline>
    * Polygon <polygon>
    * Path <path>

SVG Filters are used to add special effects to SVG graphics.

A gradient is a smooth transition from one color to another. In addition, several color transitions can be applied to the same element.
There are two main types of gradients in SVG:
    * Linear
    * Radial

For multimedia/animation, refer to SMIL (Synchronized Multimedia Integration Language).

There are many discussion among SVG, Canvas, WebGL One javascript 3D library called three.js is to create a lightweight 3D library with a very low level of complexity — in other words, for dummies. The library provides <canvas>, <svg> and WebGL renderers.

Inline SVG to HTML
drawSVG = function(svgStr) {
    var parser = new DOMParser();
    var dom = parser.parseFromString(svgStr, "text/xml");
    document.getElementById('svg').appendChild(dom.documentElement);
}
Embed SVG to HTML
In case you use jQuery you need to wait for $(window).load, because the embedded SVG document might not be yet loaded at $(document).ready
$(window).load(function () {
    var a = document.getElementById("alphasvg");
    var svgDoc = a.contentDocument;
    var delta = svgDoc.getElementById("delta");
    delta.addEventListener("mousedown",function(){alert('HI')},false);
}); 
SVG JS Libraries
Raphael
jQuery SVG
svgweb
SVGKit

Embedding SVG in HTML documents SVG Primer (from W3C) suggests 5 ways to putting SVG to HTML documents:
    * <embed>  --> browser preferred way
<embed name="E" id="E" src="simplest.svg" width="50" height="50"> 
    * <frame> and <iframe>
<iframe id="B" src="simpleShell.svg" width="250" height="150"/>
    * <object> --> W3C preferred way
<object id="E" type="image/svg+xml" data="ovals.svg" width="320" height="240">
 <param name="src" value="ovals.svg">
</object>
    * <img>  
<img src="simplest.svg" width="250" height="150"/>

    * inline (XHTML or HTML5) --> new way from HTML5
<body>
  <b>scriptable SVG in XHTML</b><br/>
  <svg id="SVG" xmlns="http://www.w3.org/2000/svg" 
     onload="receive(evt)" width="600" height="200">
     <circle cx="100" cy="100" r="100" fill="green" />
  </svg>
</body>

Reference:
http://warunapw.blogspot.com/2009/07/svg-string-inline-with-html.html
http://raphaeljs.com/
http://keith-wood.name/svg.html
http://code.google.com/p/svgweb/
http://svgkit.sourceforge.net/SVGKit.html
http://stackoverflow.com/questions/2753732/how-to-access-svg-elements-with-javascript/3379830#3379830
http://stackoverflow.com/questions/588718/jquery-svg-vs-raphael 
http://www.w3.org/Graphics/SVG/IG/resources/svgprimer.html#SVG_in_HTML

Monday, April 9, 2012

JVM memory model 101

Heap
    Young Generation
        Eden space, two Survivor (From/To) spaces                   
    Old Generation
        Tenured space
Non-Heap (Perm + C-Heap)
    Permanent Space
    Class files and jar files
    Code Generation
    Socket Buffers
    Thread stacks
    Direct Memory Space
    JNI Code
    Garbage Collection
    JNI allocated memory

Space Allocation
-Xmx -Xms -Xmn -Xss
Young size(-XX:NewRatio)
Survivor Ratio(-XX:SurvivorRatio)
-XX:PermSize=<value> (initial)
-XX:MaxPermSize=<value> (max)
-XX:MaxDirectMemorySize=<value>


Concurrent/Parallel Garbage Collection Settings
-XX:+UseParNewGC
Parallel GC in the New(Young) Generation
-XX:+UseConcMarkSweepGC
Concurrent in the Old generation
Use these two combined
Multiple CPU box can take advantage of this

More GC Settings:
-XX:+CMSIncrementalMode
-XX:+CMSIncrementalPacing
-XX:+CMSIncrementalDutyCycleMin=0
-XX:+CMSIncrementalDutyCycle=10
-XX:+CMSPermGenSweepingEnabled

Debug
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+TraceClassUnloading
-XX:+HeapDumpOnOutOfMemoryError

Update 4/25/2012
http://javaeesupportpatterns.blogspot.com/2011/02/java-hotspot-vm-permgen-space.html

https://blogs.oracle.com/jonthecollector/entry/presenting_the_permanent_generation
Java classes are stored in the permanent generation. What all does that entail? Besides the basic fields of a Java class there are
  • Methods of a class (including the bytecodes)
  • Names of the classes (in the form of an object that points to a string also in the permanent generation)
  • Constant pool information (data read from the class file, see chapter 4 of the JVM specification for all the details, including static fields)
  • Object arrays and type arrays associated with a class (e.g., an object array containing references to methods)
  • Internal objects created by the JVM (java/lang/Object or java/lang/exception for instance)
  • Information used for optimization by the compilers (JITs) 

Thursday, April 5, 2012

My experience with deep breath air duct clean

Couple of months ago Groupon had a coupon from "Deep Breath Air Duct Clean", and I did purchase it because I thought it was from Groupon, an IPO company. After purchased, I called this "Deep Breath Air Duct Clean" customer service and mentioned groupon, the woman said the latest appointment slot was 2 months away . I had no choice but waited 2 months.

When the appointment day came, there was no any pre-service call from this merchant, so I called them again and asked if my appointment was still there at 3:30pm. The woman responded that the appointment was 3pm to 5pm, with not kind voice. I was kind of curious how they could complete the clean work if they came over so late. At 5:10pm, two guys did show up, driving a small van, only pulled out one short ladder. What they did was quickly checked the attic and told us they could not do the service and recommended to change the air duct to new plastic. Damn, the total cost was around 3k dollars. Then they left with the ridiculous estimate. I realized this was a scam, starting from purchasing groupon. I did some research that night, and found a lot of useful information from youtube. The conclusion was the usual work of an air duct clean needs about 2 hours using negative pressure vacuum, and my experience was totally a potential scam.

Recently Groupon revised their 1st quarter revenue, and its stock dropped to $14.50 or lower. This trend reminded me to write up above experience with below thoughts:
  1. Groupon is not serious about consumer, returning coupon can not return consumer time and spirit
  2. Groupon is not careful when selecting merchants
  3. Groupon has a lot of discount every day, but these coupons are not the basics of every day life
  4. Deep Breath Air Duct Clean is for upsell instead of clean service (from my experience)
  5. Air Duct clean is not necessary, the most important part is furnace pre and post filters to ensure air quality. Change or clean your filters instead of clean your air duct. 
  6. Under $50 Air Duct clean is impossible, look for some service around 100 dollars if you do need clean your air duct (like after remodel, moving to a new place etc)