Sunday, October 20, 2013

A week with xmonad

Last weekend I read about xmonad at Liang Zan's blog and I think I have never used tiling window manager. I was using GNOME Shell and it freezes sometimes. So I give xmonad a try as well as xmobar and urxvt.

It took me more than a half day to set it up and get it working like I want and having the same functions as my previous gnome shell and its extensions.

After a week with xmonad, I get used to it and still find-tune some configs everyday for little edge cases and new hotkeys. I think the overall experience is great especially if you are keyboard-centric. Every window actions are at your fingertips. It's fast, customizable and simple.

Now, with xmonad, I can utilize my screen more effective. I haven't seen my wallpaper for a while. urxvt is also fast at startup, faster than gnome-terminal.

The documentation and information on the internet is acceptable. You might need to dig in haskell syntax sometimes when your config errors. However, if you are a linux user, you are fine.

Finally, here is my current screenshot. Nothing special and really minimalistic. :-)

Thursday, September 5, 2013

First impression of Golang

I have been playing with Go for 2 weeks. Here are my first impressions.

Good things

  • Concise and clearly expressed syntax - Its syntax smells like C and Python. It also has some small interesting improvements over typical C-family languages. 
    • if with a short statement. It might be just a syntactic sugar but I think it makes the code more concise.
    • I like the idea of having only for loop and C's while is a version of for. 
    • Capitalization means it is exported. Very simple and good formatting in the same time.
    • switch with break by default.  Yeah. It's arguable but break by default is my choice.
  • goroutine and channels - After I have been busy with thread-safe and concurrent issues using Java and Obj-c for a while, synchronized block, locks, java.util.concurrent, GCD and dispatch_async(), etc. I think this is another simple and amazing abstraction to deal with synchronization and concurrency in addition to a single thread and event-loop in nodejs.
  • Easily add methods to almost any types even function
  • Interface are satisfied implicitly - This is a 'wow' for me.
  • Toolchain included - testing, package management, formatting and documentation. This helps Go developers to have a uniform development flow.
  • Only one style and consistency - go fmt forces some styles and convention such as tab indentation. You might be annoyed if your preferred style is different from what the Go team has chosen. While I'm writing this, I found a very good explanation on why this is a good idea.

Interesting but in question

  • One place for packages - Go needs every packages to be under GOPATH and wants developer to avoid local/relative import. It provides a good structure for that. It needs to specify fully qualified name in code when import a package. For example, import "github.com/teerapap/mylib".  It seems to be a good idea but I wonder if the url changes. Do I have to changes every import lines in my code?
  • No versioning on package management - As opposed to npm, go get just get the latest version. I'm not sure if it is a good idea. Some said that you have to snapshot your tree. Some said that you need to use versioned path /v2/mylib instead.
  • Only static linking

Finally, I am very new to Go so I have no comments on speed/performance aspect and I am still not sure what Go fits but it is quite fun to explore the language.



Saturday, September 24, 2011

My experience with unit testing in software development

I am not a fan of software engineering which is taught in school. Waterfall model, spiral model,  many blah blah phases ,diagrams and documents. I usually thought of those as useless works or not worth to do.  I thought that software development should be simple. Get requirement -> Draft design -> Go coding! ->  Debug -> Someone test it manually -> Debug -> Test again (until it's acceptable) -> OK, Finished

Documentation should exist only if it is essential and the source code is one of the documentation. This methodology works fine because I usually develop alone or in a small team and the software does not have many modules.

Unit testing is one of those which I thought it's not worth to do. I agree that's it's useful for regression test of the code but I thought I know what I've done with my code and know what are affected. 

Around two years ago, I and my colleagues started a new project. One of them wanted to try a kind of Agile development model (I don't know the name. I've said I'm not a fan of these models) and we tried.

He encouraged me to write the unit test for each class and a few acceptance tests for overall project behaviors. I did it because I wanted to give it a try too.

Then I know I was wrong about testing. I usually see some bugs because the tests fail. In addition, I feels great when all the tests go green. The tests guarantee that the software still work as it should. However, I see some disadvantages or difficulties in writing test.

Sunday, August 14, 2011

VisualVM on ubuntu(lucid) failed to initialize the Profiler engine

I installed VisualVM on my lucid(amd64), luanch it and it shows an error.
Failed to initialize the Profiler engine: Problem with a required JFluid installation directory or file /usr/lib/jvm/java-6-openjdk/lib/visualvm/profiler3/lib/deployed/jdk16/linux-amd64/libprofilerinterface.so Original message: File does not exist.
In sprite of this error, the visualvm still can run but profiler/sampler doesn't show up.
Someone have filed this bug here. To fix this problem, recompile the missing lib manually and move to the right place.
Here are the steps
  1. Download visualvm source here (visualvm_1.2.2.orig.tar.gz at the right pane)
  2. Extract it and cd to the build directory
    tar -xzvf visualvm_1.2.2.orig.tar.gz
    tar -xzvf netbeans-profiler-visualvm_release68.tar.gz
    cd lib.profiler/native/build
  3. You will see build script ( buildnative-linux64.sh ) then edit it. 
    1. Replace gcc32 with gcc
    2. Change 2 BuildJDK lines to below. /usr/bin/jvm/default-java/ is my jdk path; yours may differ.
      BuildForJDK "/usr/lib/jvm/default-java" "jdk16"
  4. Make directory for release
    mkdir -p ../../release/lib/deployed/jdk16/linux-amd64/
  5. Run this build script. It will compile the source against jni headers in our jdk and output as libprofilerinterface.so
    ./buildnative-linux64.sh
  6. Move libprofilerinterface.so to the right place in your jdk path
    sudo cp ../../release/lib/deployed/jdk16/linux-amd64/libprofilerinterface.so /usr/lib/jvm/default-java/lib/visualvm/profiler3/lib/deployed/jdk16/linux-amd64/
  7. Launch VisualVM again. 

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