ArrayList<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
list.remove(1);
System.out.println(list);
Monday, November 22, 2010
[Java] What will be printed to a console?
Thursday, November 18, 2010
Note for starting new Eclipse workspace
- Import Formatter.
- Customize Save Actions.
- Set text editor "spaces for tabs" and "displayed tab width".
- For MacOSX, change "Content Assist" short-key.
- Set content assist to help import favorite static members.
Monday, November 1, 2010
[Java] Jars inside Jar
Jar that contains multiple jars inside is not support directly by Java. There are some workarounds on this.
Java: Easiest way to merge a release into one jar-file
Is it possible to package all the jar dependencies in one big jar ?
- Put jars in to jar as ordinary files then load them with your own customized classloader. There is a tool such as One-JAR™ but some people told that it causes performance problem (I have not try this).
- Extract jars to .class and pack them together to a single jar. You can archive this easily with Ant's Zip Task
Java: Easiest way to merge a release into one jar-file
Is it possible to package all the jar dependencies in one big jar ?
Sunday, October 31, 2010
Ubuntu RAR package file name character encoding problem
In my Ubuntu (currently version 10.10), package named "rar" has encoding problem with file that has file name in Thai. But for package named "unrar" there is no problem.
Saturday, September 18, 2010
Graceful OSX Shutdown from command line
If you use shutdown -h now running GUI programs will be forced to close. To tell them to close use
osascript -e 'tell application "System Events"' -e 'shut down' -e 'end tell'Credit :
Thursday, June 17, 2010
Hg - How to combine many dirty commits to one
You can also make dirty research branch and remove it when done in Hg. Credit to Concatenating multiple changesets into one
The concepts are
** Strip is an Hg extension.
The concepts are
- Jump to a changeset that is your last stable(good) changeset with command 'update'.
- Use command 'revert' to the last changeset of dirty branch*.
- Commit reverting, this will produce new head.
- Remove old head with command 'strip'** or pull from other repository the new head with command 'pull -r' and delete this repository.
** Strip is an Hg extension.
Monday, May 10, 2010
VIM - How to format and syntax highlight JSON file
Formatting
Run this command in shell
sudo cpan JSON::XS
Put this line to ~/.vimrc
map <leader>jt <Esc>:%!json_xs -f json -t json-pretty<CR>
- When want to format JSON file press
\jt
- credit : “tidify” a json in vim
- Download json.vim form http://www.vim.org/scripts/script.php?script_id=1945 to ~/.vim/syntax/
- Put this line to ~/.vimrc
au BufRead,BufNewFile *.json set filetype=json
- credit : Add JSON syntax highlighting in Vim on OS X
Friday, April 23, 2010
VIM - How to format Html source code
- :filetype indent on
- :set filetype=html
- :set shiftwidth=n (n = indent size)
- :set smartindent
- gg=G (gg = top of file, = is a shortcut of re-tindent, G = botton of file)
For 1,3,4 , you can predefine at .vimrc. While editing Html file, just do 2 and 5
VIM - How to format JavaScript source code
- Download this plugin jsbeautify
- Copy it to $HOME/.vim/plugin/
- In Vim, while you want to format JavaScript code, press \ff*
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.
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.
- 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.
- Singleton provides state which a lot of you may think it is disgusting.
- Singleton provides lazy-initialization. You have not to have it on your memory until you are really want it.
- You can have many instances of Singleton-type. Also can limit number of them. While you can not do this with Class method.
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 :
$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.
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.
Subscribe to:
Posts (Atom)
Collectd PostgreSQL Plugin
I couldn't find this link when searching with google https://www.collectd.org/documentation/manpages/collectd.conf.html#plugin-postgresq...
-
sudo su postgres supply your Mac password modify /Library/PostgreSQL/9.x/data/pg_hba.conf from local all all md5 to local all all ...
-
Put your cursor on the text box of the post/comment you want to indent Go to the menubar at the top of the screen Edit > Emoji & ...
-
I ran to this error the other day when I tried to export a dump file from a slave Postgres database. cpg_dump: Dumping the contents of ta...