Sunday, September 5, 2010

How to reset the main menu in Ubuntu

I rearranged and deleted some menu items in the main menu. Finally they are in a mess. Some menu is missing and I can't remember the original position or command. I want to reset them to default like fresh install. I don't see any way to reset it easily. There's a revert button but It doesn't work right. So I searched and dug in some configurations.
Then I learn that there're default menu configuration somewhere. One of them is at /etc/xdg/menu which there're applications.menu and settings.menu for application menu and system setting menu respectively. And each user has its own customization of menu in ~/.config/menus which has applications.menu and settings.menu too. Those files contain some exclude configurations and they are merged with default configurations when it is used.

So deleting directory ~/.config/menus should reset the main menu to default state and that's all.

rm -rf ~/.config/menus  

and logout and login again.

but if it's still not be reset like in my case, it need to delete *.desktop in your home directory too.
find ~/ -name "*.desktop" -delete 

Wednesday, July 28, 2010

How to forward port by ssh

There are 3 machine
  1. My machine
  2. Host A with public IP
  3. Target Host B with can be reached from Host A
The goal is that I and my friends want to access target host B services in convenience. We can ssh to Host A with public IP.

Local Forwarding

Run this command on my machine

ssh -L 123:targetB:80 userA@hostA
  • We can access targetB:80 by myMachine:123 instead
  • The traffic will be forward from myMachine:123 through ssh tunnel to hostA and the forward to targetB finally.
Remote Forwarding

Run this command on hostA

ssh -R 123:targetB:80 me@myMachine
  • We can access targetB:80 by myMachine:123 instead
  • It's similar to local forwarding but the ssh tunnel is created by hostA which is the forwarder
  • The traffic will be forward from myMachine:123 through ssh tunnel to hostA and the forward to targetB finally.
Dynamic Forwarding

Run this command on my machine

ssh -D 123 userA@hostA
  • It's similar to local forwarding but it doesn't specify the target:port because the target address and the port will be determined automatically by application protocol such as SOCKS.
  • We can access targetB:80 by SOCKS proxy in browser or OS network settings.
  • Currently SOCKS4 and SOCKS5 protocols are supported.
Remarks
  • There might have firewall issues. It might have to change some port unless the packets will be blocked.
  • This method is for TCP traffic. For UDP, you may have to try other methods.

Wednesday, June 30, 2010

How to setup remote profiling session with JProfiler

What does JProfiler do?
JProfiler is a tool to profile a JVM in runtime locally or remotely. Its profiling features are mainly in 2 parts which are CPU and memory.

In CPU part, it can shows all threads situation in JVM and its state(RUNNING,BLOCKING,WAITING,..) and also traces which part of instruction the thread currently runs. It can show object locking graph to identify a locking problem which is difficult to figure out by normal debugging.

In memory part, it collects and shows memory allocation stats, object counts and also traces the methods or classes which do most of memory allocation. Furthermore, it can shows what and when java garbage collector do with current memory consumption as a time-based graph.

How to setup?


  1. Download JProfiler and its evaluation key

  2. Install JProfiler in your computer.

  3. Copy JProfiler agent library to a target which you want to do remote profiling. JProfiler agent library is in [JProfiler path]/bin/

  4. Add an argument in JVM which you want to do profiling. (I use FreeBSD.)

    -agentpath:/usr/home/tmp/jprofiler6/bin/freebsd-x86/libjprofilerti.so=port=8849

    ** 8849 is a port for JProfiler client to communicate with its agent. You can change this

    if you have firewall, you may need to allow the port

    ipfw add 6000 allow tcp from any to me dst-port 8849 keep-state




    1. Open JProfiler client. -> Start center -> New session tab -> New session button -> select remote -> configure host and port of target jvm -> Start

    2. Start target JVM. it will pause and wait JProfiler to attach it.

    3. In JProfiler client, click Attach and OK

    It should be work now.
    Next time I may write about how to setup JProfiler with Eclipse to do local profiling. If you can’t wait, find it in JProfiler help.
    ** When the evaluation ends, the client still can open but it doesn’t work

    Friday, February 5, 2010

    Picasa's bugs cause my images to be deleted.

    I use Picasa client and Picasa Web Album for a time and it works enough for me. In addition to managing my photos in Picasa client, I also use Picasa Web Album as images hosting for my thai blog. It's really easy and safe in an album.

    Yesterday, an unlucky day, I wanted to sync the blog album to my Picasa client and tried setting them to keep syncing in the future therefore I can upload an image via either the client or the web album. It would be great, isn't it?
    I clicked the "download album to picasa" button in the web client. The album was downloaded to the client beautifully and it was shown as a downloaded web album. Then I clicked the "sync to web" button in the client. It asked something and uploaded all images in the album. Why did they need to be uploaded again?
    The problem is here. In the web client, there were 2 album now in the same name, the original and the recently uploaded. At first I thought it was not a bug, you might need to have a fresh uploaded album at the first time to keep syncing in the future and these twin albums was different album and unique.
    and this idea leads to the mistaken operation.
    I right-clicked at the downloaded web album in the client and chose to delete the album with "delete the online copies" checked. Then both original and recently uploaded album were gradually deleted! and they were deleted successfully.
    So I don't have any copies of this album left. It's a bug of Picasa and I reported to its forum yesterday.
    but good luck of me that the album has only 25 images and google still cache some of them. :P

    Sunday, January 24, 2010

    How to change 'open link in new tab' behavior in Firefox 3.6 back to the old style.

    I downloaded Firefox 3.6 yesterday and I see that the 'open link new tab' behavior is changed. In the previous version, an opened new tab will be inserted at the rightmost in the tab pane but now the new tab will be inserted next to the current related tab. It's just a style but I like the old one.
    To change it back to an old style. Steps are below.

    • Enter about:config in the location bar.

    • Press "I'll be careful, I promise!" button. yes, you have to be careful about this.

    • Type tab in filter box as in image.


    • Find the preference name browser.tabs.insertRelatedAfterCurrent and double click it. The value of this preference will be toggled to false.

    That's it.