Main BLOGGER
Google
WWW THIS BLOG
Tuesday, May 11, 2010
 
final answer to lazy initialization of Java singleton object
main idea: let Java JVM do the synchronization

static class SingletonContainer{
private static Singleton singleton = new Singleton();
public static Singleton getInstance(){
return singleton;
}
}


http://en.wikipedia.org/wiki/Initialization_on_demand_holder_idiom

Tuesday, April 27, 2010
 
JavaScript Quine

If in a browser, replace the "print" with "alert"


print((function(){return"print(("+arguments.callee.toString().replace(/\s/g,"")+")())";})())

Friday, April 17, 2009
 
write content to iframe
using ifrm.doc.open()/write()/close()
But not perfect for IE7 due to some cross-site issue

                function submitFormByAjax(targetId){
                    var form = dojo.byId("tab_form"); // save ref to form
                    dojo.xhrPost( {
                       form: form,
                       load: function(data) {
                          // set the form's HTML to be the response
                          var ifrm = document.getElementById(targetId);
                          /*
                          if(ifrm.contentDocument) 
                             ifrm.doc = ifrm.contentDocument; 
                          else if(ifrm.contentWindow) 
                             ifrm.doc = ifrm.contentWindow.document; 
                          else if(ifrm.document) 
                             ifrm.doc = ifrm.document;                           */
                          ifrm.doc = ifrm.contentWindow.document;
                          ifrm.doc.open();
                          ifrm.doc.write(data);
                          ifrm.doc.close();
                          dijit.byId("loadingDialog").hide();
                       }
                    });
                    dijit.byId("loadingDialog").show();
                }

--
Pop (Pu Liu)


Wednesday, March 25, 2009
 
a unified way to display svg in browsers
1. server side
   a. using flamingo tool
   java -cp flamingo-tst.jar:flamingo.jar:batik-all.jar:xml-apis-ext.jar:xml-apis.jar test.svg.SVGApplicaiton

   to convert SVG to Java2D class file
   b. The generated Java2D class file can in turn create the JPEG file to be displayed in browser

2. dojo client side
   using svg2gfx.xsl (dojox.gfx.demos.data) to convert SVG to JSON file which can be rendered by dojox.gfx

--
Pop (Pu Liu)


Tuesday, September 23, 2008
 
T42, Ubuntu, Gusty, boot up too slow
Check /etc/usplash.conf
Ajust the xres and yres to 1024X768
then run

    sudo update-usplash-theme usplash-theme-ubuntu

This should fix the problem
--
Pop (Pu Liu)


Monday, August 04, 2008
 
Re: Ubuntu font problem
Re: Ugly fonts on UTF-8 encoded Chinese webpages, etc.
I just now solved this problem!

You should (don't have to) install the firefly font. Google it. It's
cleaner and does look better.
Then you need to disable antialiasing.

I had to create a file called .fonts.conf and place it in my home
directory.

Here is what the file looks like:
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<!-- Disable font alias for Chinese <= 16px -->
<match target="font">
<test qual="any" name="family" compare="eq">
<string>AR PL Mingti2L Big5</string>
<string>AR PL SungtiL Big5</string>
<string>AR PL New Sung</string>
<string>AR PL ShanHeiSun Uni</string>
<string>AR PL ZenKai Uni</string>
<string>Ming(ISO10646)</string>
<string>MingLiu</string>
<string>PMingLiu</string>
<string>Kochi Mincho</string>
<string>Baekmuk Dotum</string>
</test>
<test name="pixelsize" compare="less_eq">
<double>16</double>
</test>
<edit name="antialias">
<bool>false</bool>
</edit>
<edit name="hinting">
<bool>true</bool>
</edit>
</match>
<alias>
<family>serif</family>
<prefer>
<family>Bitstream Vera Serif</family>
<family>Times New Roman</family>
<family>Times</family>
<family>AR PL New Sung</family>
<family>AR PL ShanHeiSun Uni</family>
<family>AR PL Mingti2L Big5</family>
<family>AR PL SungtiL GB</family>
<family>SimSun</family>
</prefer>
</alias>
<alias>
<family>sans-serif</family>
<prefer>
<family>Bitstream Vera Sans</family>
<family>Arial</family>
<family>Verdana</family>
<family>Helvetica</family>
<family>AR PL New Sung</family>
<family>AR PL ShanHeiSun Uni</family>
<family>AR PL kaitiM Big5</family>
<family>AR PL kaitiM GB</family>
</prefer>
</alias>
<alias>
<family>monospace</family>
<prefer>
<family>Bitstream Vera Sans Mono</family>
<family>Courier New</family>
<family>Courier</family>
<family>AR PL New Sung</family>
<family>AR PL ShanHeiSun Uni</family>
</prefer>
</alias>
</fontconfig>


The fonts are no longer blurry and mismatched. This worked for the whole
system, firefox, everything. Let me know if you have any problems.


On Mon, 04 Aug 2008 16:05:03 -0400, Pu Liu <pop.liu@gmail.com> wrote:

> in home directory, create a hidden file .fonts.conf
>
> with the following content
>
>
> <?xml version="1.0"?>
> <!DOCTYPE fontconfig SYSTEM "fonts.dtd">
> <fontconfig>
> <!-- Disable font alias for Chinese <= 16px -->
> <match target="font">
> <test qual="any" name="family" compare="eq">
> <string>AR PL New Sung</string>
> <string>AR PL ShanHeiSun Uni</string>
> <string>AR PL ZenKai Uni</string>
> <string>Ming(ISO10646)</string>
> <string>MingLiu</string>
> <string>PMingLiu</string>
> <string>Kochi Mincho</string>
> <string>Baekmuk Dotum</string>
> </test>
> <test name="pixelsize" compare="less_eq">
> <double>16</double>
> </test>
> <edit name="antialias">
> <bool>false</bool>
> </edit>
> <edit name="hinting">
> <bool>true</bool>
> </edit>
> </match>
> <alias>
> <family>serif</family>
> <prefer>
> <family>Bitstream Vera Serif</family>
> <family>Times New Roman</family>
> <family>Times</family>
> <family>AR PL New Sung</family>
> <family>AR PL ShanHeiSun Uni</family>
> <family>AR PL Mingti2L Big5</family>
> <family>AR PL SungtiL GB</family>
> <family>SimSun</family>
> </prefer>
> </alias>
> <alias>
> <family>sans-serif</family>
> <prefer>
> <family>Bitstream Vera Sans</family>
> <family>Arial</family>
> <family>Verdana</family>
> <family>Helvetica</family>
> <family>AR PL New Sung</family>
> <family>AR PL ShanHeiSun Uni</family>
> <family>AR PL kaitiM Big5</family>
> <family>AR PL kaitiM GB</family>
> </prefer>
> </alias>
> <alias>
> <family>monospace</family>
> <prefer>
> <family>Bitstream Vera Sans Mono</family>
> <family>Courier New</family>
> <family>Courier</family>
> <family>AR PL New Sung</family>
> <family>AR PL ShanHeiSun Uni</family>
> </prefer>
> </alias>
> </fontconfig>
>
>
> On Sun, Aug 3, 2008 at 10:07 AM, yuan <pop.liu@gmail.com> wrote:
>
>> a. subpixel rendering:
>> 1. go to a terminal and type:
>>
>> sudo dpkg-reconfigure fontconfig-config
>> Then select "Autohinter", "Always" and "No" when prompted.
>>
>> 2.
>> Code:
>> sudo dpkg-reconfigure fontconfig
>>
>> 3. restart X and rendering is beautiful!
>>
>>
>> b. System>Prefs>Appearance>Fonts
>>
>> LCD smoothing, then details. Hinting - Slight.
>>
>>
>
>

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/


 
Re: Ubuntu font problem
in home directory, create a hidden file .fonts.conf

with the following content


<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<!-- Disable font alias for Chinese <= 16px -->
<match target="font">
<test qual="any" name="family" compare="eq">
<string>AR PL New Sung</string>
<string>AR PL ShanHeiSun Uni</string>
<string>AR PL ZenKai Uni</string>
<string>Ming(ISO10646)</string>
<string>MingLiu</string>
<string>PMingLiu</string>
<string>Kochi Mincho</string>
<string>Baekmuk Dotum</string>
</test>
<test name="pixelsize" compare="less_eq">
<double>16</double>
</test>
<edit name="antialias">
<bool>false</bool>
</edit>
<edit name="hinting">
<bool>true</bool>
</edit>
</match>
<alias>
<family>serif</family>
<prefer>
<family>Bitstream Vera Serif</family>
<family>Times New Roman</family>
<family>Times</family>
<family>AR PL New Sung</family>
<family>AR PL ShanHeiSun Uni</family>
<family>AR PL Mingti2L Big5</family>
<family>AR PL SungtiL GB</family>
<family>SimSun</family>
</prefer>
</alias>
<alias>
<family>sans-serif</family>
<prefer>
<family>Bitstream Vera Sans</family>
<family>Arial</family>
<family>Verdana</family>
<family>Helvetica</family>
<family>AR PL New Sung</family>
<family>AR PL ShanHeiSun Uni</family>
<family>AR PL kaitiM Big5</family>
<family>AR PL kaitiM GB</family>
</prefer>
</alias>
<alias>
<family>monospace</family>
<prefer>
<family>Bitstream Vera Sans Mono</family>
<family>Courier New</family>
<family>Courier</family>
<family>AR PL New Sung</family>
<family>AR PL ShanHeiSun Uni</family>
</prefer>
</alias>
</fontconfig>


On Sun, Aug 3, 2008 at 10:07 AM, yuan <pop.liu@gmail.com> wrote:
a. subpixel rendering:
1. go to a terminal and type:

sudo dpkg-reconfigure fontconfig-config
Then select "Autohinter", "Always" and "No" when prompted.

2.
Code:
sudo dpkg-reconfigure fontconfig

3.  restart X and rendering is beautiful!


b. System>Prefs>Appearance>Fonts

LCD smoothing, then details. Hinting - Slight.




--
Pop (Pu Liu)


 
ubuntu, locale generation hangs problem, a fix which works
 Fco Javier Lopez wrote on 2008-07-30: (permalink)

There's a easy workaround.

The /usr/share/locales/install-language-pack script, used in the postinst of the language-packs packages, invokes /usr/sbin/locale-gen.

locale-gen makes some work and finally it executes localedef, that hangs up. Looking the "ps -aux" output, copying the localedef execution order, deleting the option "--no-archive" it works correcty. It's a mistery, the problem is present when the locale information is stored in locale_country.charset directory inside /usr/lib/locale/, for instance, es_ES.utf-8.

This locale-gen shell script uses the /etc/belocs/locale-gen.conf conffile of belocs-locales-bin package, which has the variable ARCHIVE with the "no" value. By changing this value to "yes", the locale information is stored in one unique file /usr/lib/locale/locale-archive. And the most important, then localedef works, does not hangs up. Now we can install, reinstall language-packs and so on.

Greetings and a lot of luck



--
Pop (Pu Liu)


Tuesday, July 22, 2008
 
obscured URL

http://email.about.com/gi/dynamic/offsite.htm?site=http://www.pc-help.org/obscure.htm


In Sum

URLs can be obscured at least three ways:

  1. Meaningless or deceptive text can be added after "http://" and before an "@" symbol.
  2. The domain name can be expressed as an IP address, in dotted-decimal, dword, octal or hexadecimal format; and all of these formats have variants.
  3. Characters in the URL can expressed as hexadecimal (base 16) numbers.


--
Pop (Pu Liu)

 
POST redirect issue in HTTP
see:
http://www.theserverside.com/tt/articles/article.tss?l=RedirectAfterPost

t is interesting that PRG pattern exploits non-standard behavior of browsers and web servers. HTTP 1.1 defines several redirect response codes in 3xx range. Some of these codes require browser to use the same request type, some require to change POST to GET, some require to obtain user confirmation when request is redirected. Turns out that many of these requirements are not implemented by popular browsers. Instead, they have common de-facto behavior, like redirecting POST to GET without confirmation if received 302 code. This feature is used by PRG pattern.

This behavior is wrong for 302 ("Found") code, but is absolutely correct for 303 ("See Other") code. Still, few servers return 303 when redirect with GET method is required. HttpResponse.sendRedirect method does not allow to set response code, it always returns 302. It is possible to emulate sendRedirect(url) behavior using the following methods:

res.setStatus(res.SC_SEE_OTHER);
res.setHeader("Location",url);

where SC_SEE_OTHER is the proper 303 code, but sendRedirect provides some additional service like resolving relative addresses, so this is not a direct snap-in. The discrepancy between browser behavior and HTTP standard can be resolved, if 302 and 303 codes considered equal, and another code for proper 302 behavior were created.

In any case, I doubt that browser vendors will change implementation of 302 response code, because too many applications relay on it. The good thing is that modern browsers understand and correctly process 303 code, so if you want to be sure, return 303 instead of 302

--
Pop (Pu Liu)


Powered by Blogger

Google
WWW THIS BLOG