Thursday, March 25, 2010

Singleton vs Class method

I want to tell you before go on through the detail that following article is based on Java. Different implemented language might not have the similar behavior.

Singleton or Class method ?

This topic might too old for some of you but I always was reminded to this issue when I was going to write some method just do some algorithms - take inputs, processing, return output.

We will find many discussions on this issue if we do googling. Below this are what I conclude those discussions for myself.
  1. Singleton provides typing. You can subclassing or passing it around whatever you can do to an object-oriented instance you can do to Singleton object.
  2. Singleton provides state which a lot of you may think it is disgusting.
  3. Singleton provides lazy-initialization. You have not to have it on your memory until you are really want it.
  4. You can have many instances of Singleton-type. Also can limit number of them. While you can not do this with Class method.
I'm going to update this if I find more distinction points

Monday, January 11, 2010

Shutdown Mac OS X with command line

I have founded that ordinary

$shutdown -p now

command line not enough to close Mac box. It doesn't turn the machine off.

After some googlings, I founded this The Command Line Junkie's Guide To Mac OS X,

which tell me that I can shut it down with command :

osascript -e 'tell application "Finder" to shut down'

Thursday, January 7, 2010

Java thread stack size

Today, I have just known that there's an another interesting parameter to set to JVM. It is java thread stack size.

With too high thread stack size, it will effect to low number of thread JVM can create - see this experiment. Not enough memory for java thread (cause from too big stack size) will produce "java.lang.OutOfMemoryError: unable to create new native thread"

You can set java stack thread size by adding -XssnK to JVM argument where n stands for a wanted size.

Now, I am not sure what is the default java thread stack size. Someone tells it is 512Kb. Another one tells it is up to the platform. One thing is that it's vary between each java versions. However, there is a way to get it from your running JVM. I got this trick from Get thread stack size at runtime thanks to claudio. Note that this trick may work only with *nix family.

First, you have to know your target JVM's pid (process id). If your system has only one JVM running, it is easy to use 'ps' or top to find it. But if it has many, my often used approach is to use

jps -lv

and justify it from the informations provided. If the informations are equally the same, help yourself :P.

Now you have target JVM's pid.

Then run following command

jinfo -flag ThreadStackSize {PID}

The jvm's set thread stack size will show to you in Kb.

Saturday, November 28, 2009

How to connect VPN via PPTP with Ubuntu

I had tried to connect to my office local network with my Karmic machine via PPTP protocol. I saw a VPN stuff when clicked 'Edit Connections' of NetworkManager Applet (normally on top left of you screen) but couldn't do anything to it. So I started googling and found below.

First, I had to install PPTP for NetworkManager
sudo apt-get install network-manager-pptp
Now, we can do setting PPTP VPN.

Just enter gateway, username and password your PPTP VPN will be now ready to work.

But for me, I want to go out to normal internet with my internet router not to go through my office network. I have to do something a bit.

In editing vpn, click on tab IPv4 setting -> Routes.

Enter ip(s) that want to use vpn and netmark.

You can leave another 2 columns, gateway and metric blank.

Thick in box "Use this connection only for resources on its network"

done.


Credit : VPN - Ubuntu Wiki, Howto configure PPTP VPN in Ubuntu Intrepid and Jaunty
Testing OS : Ubuntu 9.10 (Karmic Koala)

Friday, June 5, 2009

[FIXED] This project needs to migrate WTP metadata

After I checkout code from SVN repository, some of my Eclipse's projects alert this error

"This project needs to migrate WTP metadata"

and it's no provide clue for solve them.

I found this thread Eclipse error: This project needs to migrate WTP metadata

There's a way to solve this error almost bottom of the page.

Just right-click at alerting project and click "Validate"

Then the problem must be solved

Sunday, May 31, 2009

Advance Ubuntu keybindings setting

You can go to System -> Preferences -> Keyboard Shortcuts for normal shortkey setting but it isn't enough for me because it isn't work with "Windows" key.

I want Windows+d to bind to "show desktop" as used in Windows but Keyboard Shortcuts doesn't work in this case.

And I found from here How come pressing Super+D doesn't show my desktop?

There's deeper setting.

Run gconf-editor (at command line)

and went to apps -> metacity -> global_keybindings and change "show_desktop" from "d" to "d" (Mod4 is represent Windows key)

And I have also binded "run_command_terminal" to "t"

Configurations after installation my Jaunty Jackalope

After clean installation new Ubuntu - Ubuntu 9.04 or Jaunty Jackalope, I have made many configurations and installing softwares.
Font size
For softwares installations, I chose from Add/Remove so nothing to remember just tick and click but I might forget what and how to make some configurations next installtion time so below is my jot down about these.

That's all for now. I will add it if more configurations are added

Collectd PostgreSQL Plugin

I couldn't find this link when searching with google https://www.collectd.org/documentation/manpages/collectd.conf.html#plugin-postgresq...