Jul 27, 2014

I created a new Blog

I created a new blog, Raspberry Pi Programming. I am planning to fill it up with some RPi related programming; or Linux/Web programming in general.

I liked the auto-generated new skin. It is wider and it can show longer lines of code.

One of the reasons I created a new Blog is that Google said my current Blog contains copyright material, which they didn't exactly point out. So I am hoping that I can learn and be more sensitive about copy-right materials by managing the new blog.

Also I like to develop my programming skills in Linux/Web based platform more.

Jul 25, 2014

A try with Autotools, EclipseCDT and MingW

I am a big fan of GNU utilities but I have never had a chance to use "Autotools" before. Autotools is a tool set for generating Makefile/configure. As far as I know, autotools checks what kind of OS/compiler characteristics have such as byte-endian-ness or the size of boolean. And it generates Makefile depending on the characteristics.

A few days ago, I found that Eclipse CDT has a project template for GNU autotools, so I tried it. It seems that I have been following instructions from web pages but I am stuck at some point. It shows me this error message:
Generating Makefile in build directory: C:/Users/wrice/workspace/cpp/camd/

sh -c "C:/Users/wrice127/workspace/cpp/camd/C/Users/wrice127/workspace/cpp/camd/configure CFLAGS=\"-g\""
sh: C:/Users/wrice127/workspace/cpp/camd/C/Users/wrice127/workspace/cpp/camd/configure: No such file or directory

Configuration failed with error
 Somehow the autotool successfully generated a file, "configure". But it cannot execute because the path is wrong. The folder path is repeated twice: "C:/Users/wrice/workspace/cpp/camd/C/Users/wrice/workspace/cpp/camd/configure".

I am thinking that it may be a bug in CDT not working with my MingW. I may need to try Cygwin instead.

Jul 23, 2014

Finite State Machine in programming language

Finite State Machine is very powerful and well-known concept in computer science. However it is not well-integrated into any programming language. When it is expressed with UML diagram, it is often effectively represent how the state relationship changes. I have been looking for a solution for utilizing the power of finite state machine in programing language level.

Here is an example of a simple state machine, taken from Wiki.

When you think about how to express it in a plain text, it is not an easy task because those relation ship is not one-dimensional or one-directional.

I was able to find several different notations for FSM but I found SCXML most promising.

The UML above can be written in an XML:
< ?xml version="1.0" encoding="UTF-8"?>
< scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="ready">
    < state id="ready">
        < transition event="watch.start" target="running"/>
    < /state>
    < state id="running">
        < transition event="watch.split" target="paused"/>
        < transition event="watch.stop" target="stopped"/>
    < /state>
    < state id="paused">
        < transition event="watch.unsplit" target="running"/>
        < transition event="watch.stop" target="stopped"/>
    < /state>
    < state id="stopped">
        < transition event="watch.reset" target="ready"/>
    < /state>
< /scxml>    
Now I want to translate the state machine into a programing language and I want to force the state at compile time.package stateMachine;
public interface Watch_FiniteStateMachine {

    public StartingState initial();
    public StoppedState finalState();

    static public interface StartingState {
        public RunningState start();

    static public interface RunningState {
        public PausedState pause();
        public StoppedState stop();

    static public interface PausedState {
        public RunningState resume();
        public StoppedState stop();

    static public interface StoppedState {
The set of interface will be used like this:
        Watch_FiniteStateMachine watchFSM = new Watch_FiniteStateMachineImpl();
        StartingState watchStarting = watchFSM.initial();
        RunningState watchRunning = watchStarting.start();
        PausedState watchPaused = watchRunning.pause();
        StoppedState watchStopped = watchPaused.stop();
This is a simple case but it shows that the state change is determined at compile time. Since there is no way for us to get "PausedState" object until we get "RunningState", the order of state machine is forced at compile time.

If we can automatically generate the set of interface from a SCXML, it will be very useful.
In Java, fortunately, there is a compile time "annotation" so that I can execute my own Java program at compile time through java compiler. Most of time the feature is used to map SQL table and Java class member variables. I think it should work for my idea as well.

I have another example of file handler.
The problem of traditional file handle wrapping classes is that it has several methods and they are allowed to be used anytime. For example, even though "open()" method must be called before "read()" or "write()", there is no way for compiler to force it. This problem can be addressed by state machine.
< scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" initial="readyToOpen">
    < state id="readyToOpen">
        < transition event="openForRead" target="reading"/>
        < transition event="openForWrite" target="writing"/>
        < transition event="openForReadAndWrite" target="readingAndWriting"/>
    < /state>
    < state id="reading">
        < transition event="close" target="readyToOpen"/>
    < /state>
    < state id="writing">
        < transition event="close" target="readyToOpen"/>
    < /state>
    < state id="readingAndWriting">
        < transition event="close" target="readyToOpen"/>
    < /state>
< /scxml>   

This SCXML can be (automatically) translated to a set of interface; except the OpenAction part below:
public interface FileHander_FiniteStateMachine {

    public ReadyToOpenState initial();

    static public interface ReadyToOpenState {
        static public interface OpenAction {
            public void action(String line);
        public ReadingState openForRead(String filename, OpenAction action);
        public WritingState openForWrite(String filename, OpenAction action);
        public ReadingAndWritingState openForReadAndWrite( String filename, OpenAction action);

    static public interface ReadingState {
        public ReadyToOpenState close();

    static public interface WritingState {
        public ReadyToOpenState close();

    static public interface ReadingAndWritingState {
        public ReadyToOpenState close();

The set of interface can be used like this:
        FileHander_FiniteStateMachine fileFSM = new FileHander_FiniteStateMachineImpl();
        ReadyToOpenState fileReady = fileFSM.initial();
        ReadingState fileReading = fileReady.openForRead("filename.txt",
                line -> System.out.println(line));
        ReadyToOpenState fileReadyAgain = fileReading.close();

Note that I used lamda expression with a functional interface, "OpenAction", which is recent new feature from JDK-8.

Up to this point, it sounds good but there is a down-side I am reluctant to mention. This type of approach will make the implementation part more complicated; in the case of FileHandler example, the implementation class, "FileHandler_FiniteStateMachineImpl", will be more complicated than traditional file handling classes. It is due to the over-head of wrapping state with new objects. Performance-wise, it wouldn't be much different but the number of source code lines will be increased so does the difficulty of maintainability.

I am hoping that I can come up with better idea of suppressing the complexity over-head with the awesome compile-time annotation feature.

Jul 21, 2014

Private browsing in Firefox

Recently I learn about Private Browsing feature in Firefox web browser; it doesn't store any password or browsing history.

First I thought that where I can possibly use it for.
Later I found it handy at work; or I can use it when I borrow my wife's computer or something.

I shouldn't be but it happens from time to time that I check Amazon, check my emails or check YouTube videos. I don't want to store any record of them.

Jul 18, 2014

I got a new graphic card, GTX750

I got a new graphic card, GTX750. This is a low-end graphic card that is made by NVidia. The reason why I picked this graphic card is because it is designed to consume low power. Most of other graphic cards consumes about 150~250W while GTX750 consumes only 55W. The performance is little less than half of high-end graphic card but I think it is still strong enough to run most of Steam games. At worst case, I can reduce shadow map size or adjust some other options to get better performance. The price was also cheap; I got it at $120 from Fry's and it came with $20 rebate by mail.

*PS: image from http://www.geforce.com/hardware/desktop-gpus/geforce-gtx-650/product-images

*PS: image from http://www.geforce.com/hardware/desktop-gpus/geforce-gtx-650/performance

Recently I have been thinking that I should use more computer than just playing games. I used to write a lot and read more. But I am not doing them.

Last two years, I spent a lot of time commuting; five hours a day. Last December my wife and I agreed to move to a place close to my company. Since then, I got some free time back and I have been playing games. Recently I realized that I could have spent it better wisely. Once we have a baby, I wouldn't have time for myself again. So I have been trying to move from console to my desktop computer.

The problem I found was that my desktop computer is so loud. It might be fine a few years ago but since I got used to small and silent devices like RaspberryPi, Tablets and PlayStation, I couldn't bear the noise from my computer. It was also super hot after one or two hours later. I kept looking for a solution and a few days ago I found this awesome cool graphic card, GTX750. It took only two hours for me to get one after I learned about it. Also I took out my SSD drive from another computer and installed it on the desktop computer. I adjusted fan speed little bit and vacuumed inside of the computer. After all the effort, it still makes some fan noise but it is about the level I may be able to take. If it still bother me, I may try turning of one of five fans, replacing the power supply or replacing the CPU cooler with water cooling device. BTW, noise canceling headset certainly helps.