Wednesday, December 11, 2013

Github Longest Streak...60 days and counting!

I had wondered for a while what is that grid of boxes on Github profile and what is the use of it until I read 177 days of Github. Just about the same period, I read How To Stay Focused When You Get Bored Working Toward Your Goals and How to Stop Procrastinating on Your Goals by Using the “Seinfeld Strategy”.  In short, they are all about habits.
But if you look at the people who are consistently achieving their goals, you start to realize that it’s not the events or the results that make them different. It’s their commitment to the process. They fall in love with the daily practice, not the individual event.
In the blog post, he tells the story of a successful comedian who had written a joke every day for many years. He kept doing it. He didn't want to break the chain.

I was really motivated by those blogs and started a mission. I decide to write some code every day and push them to Github. Do it as a daily exercise. Keep doing it every day and don't break the chain.

I created a few projects to work on such as grunt-protractor-runner and WhatNext.  At that time, I also had to practice my skill for upcoming coding interview. I chose to solve some problems on Project Euler every day and pushed my solutions to Github. I have solved 38 problems. :D

These projects gives me enough amount of work to do every day. After I had done for a few weeks, I started to be afraid of breaking this chain. The deadline time for each day is at 2PM in my timezone. When I got it done for the day, I felt relieved haha. Some days I have to sleep late just to solve a problem on Project Euler because I cannot do it the day after.

And now I did it. Today is the 60th day!!

I have done it for 60 consecutive days and I hope I can do it more. Let's see how far I can go. :)

Monday, November 18, 2013

WhatNext: My first android application on Google Play

I just published my first Android application on Google Play.

The application name is WhatNext. It is a simple tool to help you do "single tasking". The idea comes the first time when I played nodejs, tried to wrap my brain around its single-threading and event-driven model. Then I started thinking about applying this idea to how I handle things before I found out that people outside technology circle calls it "single tasking". There are a couple articles about this concept as listed below

I'm usually overwhelmed with a pile of long-standing tasks in my long todo list and my energy always get drained upfront and then I procrastinate.

I've been wanting to develop this idea into android application for a while but I procrastinated. :-/

Finally, I started developing it 2-3 weeks ago with an idea to keep it simple, focused and effective. I also want to keep iterating, gradually improving and release the application early and often. I try to ship it as soon as possible.

Another goal is to learn Android application development and its components which I think I'm really late to the area. The best way to learn new technology is learning by doing. Although I tried to ship the first version as soon as I can, my habits still keep me reading all the things upfront before coding the first line.

Now I understand why people often say that developing a good Android application is difficult and takes much time. After I have read Android documentation and guides and watched some I/O talks, I see that Android is quite big in term of platform. There are many components, concepts and design patterns. I just read about 15% of them. These patterns and concepts enable very much flexibility and extensibility and force some good practices and design but, on the other hand, it is difficult to get it right the first time for developers.

The project is really young and I open source here.  If you want to try the app, get it on Google Play. The application supports only >= 4.x by intention and only tested with my Galaxy Nexus.

Enjoy! :D

Get it on Google Play

Monday, November 11, 2013

My first experience maintaining a project on Github

A month ago, I started playing AngularJS and tried setting up a working dev/testing build environment. To do E2E testing with Angular app, they recommend newly test framework called protractor. I jumped to it and it happened that there was no usable Grunt task to run protractor in the build process yet. So I spent a night creating a small grunt task for myself and published it to npm registry.

A couple days later, I got the first issue in Github which is "can't run". Haha. After I had eagerly investigated, I didn't know what is the problem and the issue still hasn't been resolved until now. :-/ 

A few days later, I got the first pull request to add new option to the task. I was quite surprised and excited. I eagerly worked with him and merged it quickly because I know how it feel when you want your pull request to be merged as soon as possible especially a npm module. 

I was more surprised that I got an issue or pull request almost every day after that. I felt really great and tried to clear these issues and merge these pull requests as fast as possible. 


The last surprise is that it has been downloaded for 1426 times in the last month! :D

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

    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.

    Monday, November 16, 2009

    URL Regular Expression Pattern

    Tonight I search for a regex pattern to parsing ftp or http url. I found some but I choose Ivan's pattern and then I modify it to suit my problem. this is the result.

    ^(ht|f)tps?:(//)(w+(:w+)?@)?([-w]+.?)*[-w]+(:[d]{1,5})?(/([-w~!$+|.,=]|%[a-fd]{2})+)*(/)?(?([-w~!$+|.,*:]|%[a-fd{2}])+=?([-w~!$+|.,*:=]|%[a-fd]{2})*(&([-w~!$+|.,*:]|%[a-fd{2}])+=?([-w~!$+|.,*:=]|%[a-fd]{2})*)*)?(#([-w~!$+|.,*:=]|%[a-fd]{2})*)?$

    Some paths derive from Ivan's pattern and some I rewrite it. I note this for further use in the future. Hope it maybe useful to you too.
    And I also found regexpal which is a great online regex tool.

    Wednesday, October 28, 2009

    GoogleSurfKey will be outdated soon.

    Today I just see that Google is doing keyboard shortcut feature for their search result page. Although now it's in google lab and just a experimental feature but I think it will be out of the lab soon. It's a good news for keyboard-centric user like me. :D So my GoogleSurfKey script will be outdated soon.

    You can try this new Google's experimental feature out at the Google Experimental page. Now it can use only in main english google.

    Sunday, August 16, 2009

    Google Surf Key 0.3.0 is released!!

    I've not updated Google Surf Key script for a long time. Now I update it and release the new version 0.3.0. Recently google search has updated new result page layout and the DOM layout has changed (more complex) so my script hasn't worked anymore.

    Install it here

    This is version 0.3.0 changelog.

    version 0.3.0 released.(15 Aug 2009)
    - Updated for new Google's search result page layout.
    - Fixed the 10 results limitation.(Only j,k traversing not number keys)
    - Add l command to toggle show the index label.
    - Change the implementation to use JQuery 1.2.6.
    - Improve the link focusing.

    Hope you like it!

    Wednesday, June 24, 2009

    Convert all column data type from VARCHAR2 to NVARCHAR2 and vice versa in Oracle 11g

    I found a problem about the encoding and some data size issues. So I need to convert all column in all table in my database from VARCHAR2 to NVARCHAR2 with the same size. Definitely I can convert the data type column by column manually but it takes time and not a smart way. So this is the way.

    I logged in as SYS and run this sql statement.


    select 'ALTER TABLE '||OWNER||'.'||TABLE_NAME||' MODIFY('||COLUMN_NAME||' NVARCHAR2('||DATA_LENGTH||'));' AS GEN_SQL_STATEMENTfrom   SYS.DBA_tab_columnswhere  owner = 'ownername' and DATA_TYPE = 'VARCHAR2';



    The result is the rows of ALTER statement filled with the table name, column name and new data type.
    Then I copied all rows and concatenate them with some editor. and then run them as a sql script.

    If you want to convert from NVARCHAR2 to VARCHAR2, just switch 'VARCHAR2' and NVARCHAR2' in above sql statement. You can modify above script as well to suit your propose.

    Finally, you cannot convert the column which is not empty otherwise the error will occur.

    Tuesday, June 2, 2009

    IE6 crashes on JQuery append() function

    This is a problem only on IE6 as I know. (IE7 and Firefox3 are tested.) This is my JQuery code that causes IE6 crashed.


    var table = $("#contact_list");table.empty();$("group",data).each(function(){var group_name = $(this).attr("name");table.append("<tr><td>"+group_name+"</td></tr>");$("user",$(this)).each(function(){var username = $(this).text();table.append("<tr><td>"+username+"</td></tr>");});});


    When I saw IE6 crashed, I tried to figure out what was the problem and found it was an append function. So I tried to implement the code in many ways and I saw something.

    It will crashes if the html string as an argument of the function is not a properly dom object or closed tag. For example


    var box = $("#contact_list");box.append('<table>');//do something.....box.append('</table>');


    So I solved this problem by define an variable for collecting all the html string which I want to append and append it by append() in the end. And the code works fine on IE6.

    Friday, April 3, 2009

    Switch input language by Caps Lock #2

    Due to comments in this post, I tried to find another way to use caps lock key for switching input language. The limit of that post is it works only Windows which has grave accent(`) option for switch language but many computer hasn't that option. It usually has Left Alt+Shift option.

    So I have to remap caps lock key to left alt+shift. There is no way to do this in Windows registry. I found AutoHotkey can do this for me.

    Steps are



    1. Download and install AutoHotkey in your computer.

    2. Write .ahk script like below
      Capslock::Send {LAlt down}{Shift}{LAlt up}


    3. Save this file and try double click to run it.

    4. Test it by press caps lock and see.

    5. Create shortcut to this .ahk file and move it to Startup folder in Start menu. [Do this to run this script at startup]

    Hope you like it!!

    Tuesday, March 10, 2009

    Major Limitation of Gmail and Google Calendar in Offline Mode

    Recently Google launched an offline mode of Gmail in labs and just few days ago Google Calendar offline mode had been released in beta after the news of this feature over a year.

    Both of them use the capabilities of Google Gears for running in offline. So I installed Google Chrome for try out these things.

    It works nicely but I found a major limitation. A few days ago ,I was disconnected and I opened the Gmail. I expected that I could browse my email easily and see my drafts but it didn’t work.

    Google Chrome showed an error. It said “105 (net::ERR_NAME_NOT_RESOLVED)” that is about Chrome cannot resolve an IP address of website (gmail.com). So it cannot work offline. The same error was shown when I tried the Calendar.

    But Google Document or Remember The Milk which support Gears work correctly.

    Gmail and Calendar work in offline mode correctly if they have already been opened before your computer is disconnected. They will switch to offline mode and continue running correctly.

    I wish this limitation will be removed soon.

    Monday, March 2, 2009

    Booting Process Tuning in FreeBSD 7.1

    This is the last semester in my undergraduate student life, I attended the FreeBSD class and the last project is "Special Problem: Subsystem Tuning".
    The project's objective is to tune or optimize a subsystem of FreeBSD and/or its environs (applications, utilities, etc.) to make it perform better.
    I choose to tune the booting process of FreeBSD. Due to my laziness and lack of time, so I didn’t do tuning as much as I expected. but if I have time……if I have time…..
    Here is my presentation.