2010-09-16

sb2-init: cannot run C compiled programs

> sb2-init -c /opt/qemu/bin/qemu-arm sheeva_debian /root/opt/toolchains/arm-2010q1/bin/arm-none-eabi-gcc

checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... configure: error: cannot run C compiled programs.


The reason of failed test was the gcc compiler was wrong. See
I downloaded "Sourcery G++ Lite Edition for ARM" with target OS "EABI". After I switched to the one target OS "GNU/Linux", the error disappeared.

2010-09-15

Installation xp on Thinkpad Edge 13"

  • Enter BIOS, set S-ATA(AHCI) to S-ATA(Compatible), otherwise, you will get bluescreen during installation xp on a thinkpad notebook.
  • Find the latest drivers of Thinkpad laptop here.
  • Create an image for system disk after installation of system, driver, hotfix. Ghost 2003 BootCD, whose iso file can be downloaded here, is a good tool to do this job. It also supports USB CD-Rom, which old Ghost may not support. 
  • EASEUS Partition Master - Home Edition is very nice free disk partition software.

2010-09-08

Should I refactor?

A more important question suppose to be "why should I refactor?"

Becasue we have to constantly change our code. You may ask, "is it possible some computer genius can implement a software just for once, then the software works perfectly and it requires no further efforts?" The answer is NO. If it is a real software, not just a simple programming exercise task, this kind "once forever" story never happens. In this cruel world, we must be ready to change the given code, perhaps quite often, for example fixing new bugs, adding new features or porting to other programs.

The structure of software becomes more and more complex, even a simple 'notepad' program has hundreds of lines. It is a nightmare for a programmer to changing a spaghetti code mess to make the software work as you wish. Thusfore, we need a good program struture. It can only save a lot of time, effort and money, but more importantly, it makes the software is maintainable, scalable and reliable against to modifications.

Is it possible that architecture can design a nice structure from top to bottom at the beginning, then programmers just write the code execatly according to this perfect design? Theoretically maybe, in pracice almost IMPOSSIBLE. The truth is that you can only more clearly understand your problem, as you have start to tackle it. In a design phase of a software project, it is diffcult for architectures and developpers to fully understand all requirements, to see all aspects of implmenetation and design a perfect structure, until the implementation really is ongoing and people meet one unexpected problem after the other and little by little have a better idea to implement the software. Don't be frustrated, we are human with a limited perception, even the best programmer.

As we constantly update our understanding of project and decide to improve the structure, refactor comes into the play. Refactor is a work that make the program have a better inner struture, but doesn't change it external function and behavior.

"What is a better structure?" I think a good structure is a realization of a right design pattern, so that people can esily understand the code and easily change the code in future.

Personally, I like to refactor before I have to change the code. For example, I want to implement a new feature of software and I find out that I need to change more than ten classes. It is a smell of bad structure. I'd better refactor the program at first. After refactoring, the program has a better inner strucure, perhaps I only need to write a tiny subclass to implement the feature. Summary: Before you want to change the existing code, think about at first the possiblity of refactor. Believe me, you will largely benifit from this good programming habit.

Sometimes, if I don't have too much time pressure, I'd like to spend some hours to investigate whether some classes in the project are too big or too complicated. The command below could be useful to show the line number of class files:

>find -type f -name '*.qml' | xargs wc -l | less

A class with huge size may be a candidate of refactor, more specifically, decomposition: sperate it into several small classes. Small classes are better, easily to understand and easily to maintain than big ones.

2010-09-07

Processing each line of a file by batch

An example of processing each line of a given file
@echo off
for /f "delims=] tokens=1*" %%a in ('find /v /n "" ^<.\newsources.txt') do (
   echo %%b
)

QML Weather

Based on Google online API, Max implemented a weather panel using QML (Qt 4.7 declarative).


The three XmlListModels are used to extract need information for display.


RssModeInfo.qml
XmlListModel {
    source: "http://www.google.com/ig/api?weather=forchheim"
    query: "/xml_api_reply/weather/forecast_information"

    //forecast information
    XmlRole { name: "city"; query: "city/@data/string()" }
    XmlRole { name: "forecast_date"; query: "forecast_date/@data/string()" }
    XmlRole { name: "current_date_time"; query: "current_date_time/@data/string()" }

RssModeCurrent.qml
XmlListModel {
    source: "http://www.google.com/ig/api?weather=forchheim"
    query: "/xml_api_reply/weather/current_conditions"

    //current condition
    XmlRole { name: "condition"; query: "condition/@data/string()" }
    XmlRole { name: "temp_c"; query: "temp_c/@data/string()" }
    XmlRole { name: "humidity"; query: "humidity/@data/string()" }
    XmlRole { name: "icon"; query: "icon/@data/string()" }
    XmlRole { name: "wind_condition"; query: "wind_condition/@data/string()" }

}

RssModeDailyForecast.qml
XmlListModel {
    property int index

    source: "http://www.google.com/ig/api?weather=forchheim"
    query: "/xml_api_reply/weather"

    XmlRole { name: "day_of_week"; query: "forecast_conditions[" + index.toString() + "]/day_of_week/@data/string()" }
    XmlRole { name: "low_f"; query: "forecast_conditions[" + index.toString() + "]/low/@data/string()" }
    XmlRole { name: "high_f"; query: "forecast_conditions[" + index.toString() + "]/high/@data/string()" }
    XmlRole { name: "icon"; query: "forecast_conditions[" + index.toString() + "]/icon/@data/string()" }
    XmlRole { name: "condition"; query: "forecast_conditions[" + index.toString() + "]/condition/@data/string()" }

} 

2010-09-06

Google Weather API

iGoogle Weather Feed API hasn't yet officially support the xml feed of weather. Anyway it can be used by http://www.google.com/ig/api?weather=$city.

For example, you want the rss feed of shanghai:

http://www.google.com/ig/api?weather=shanghai

In the xml, you will get current conditions and 4-days forcast.

22 Possible condition icons:

chance_of_rain.gif
sunny.gif
mostly_sunny.gif
partly_cloudy.gif
mostly_cloudy.gif
chance_of_storm.gif
showers.gif
rain.gif
chance_of_snow.gif
cloudy.gif
mist.gif
storm.gif
thunderstorm.gif
chance_of_tstorm.gif
sleet.gif
snow.gif
icy.gif
dust.gif
fog.gif
smoke.gif
haze.gif
flurries.gif

    Reference:

    2010-09-01

    QRegExp Extracts the Content of Online-News

    The following example shows how to extract the string between <div class="yn-story-content"> and </div>.

    ContentExtractor::ContentExtractor(QObject *parent)
        : QObject(parent)
    {
    
        //regexp pattern
        QString escape1 = QRegExp::escape("<div class=\"yn-story-content\">");
        QString escape2 = QRegExp::escape("</div>");
        QString aPattern = escape1 + "(.*)?" + escape2;
        regExp_.setPattern ( aPattern );
        regExp_.setMinimal ( true );
        regExp_.setCaseSensitivity(Qt::CaseInsensitive);
    }
    void ContentExtractor::extractContent(QString text_in)
    {
        if (regExp_.indexIn(text_in) != -1) {
            content_ = regExp_.cap(1);
            content_ = content_.trimmed();
            content_ = content_.remove('\n');
            content_ = content_.remove('\t');
        }
    }
    

    It could be very useful to extract the contents of online news. If the extractor is applied on the page "http://news.yahoo.com/s/ap/20100831/ap_on_re_us/us_obama" and content_ is displayed by Text element in QML, you will get well-formatted news text:


    If you want to get the source, please let me know.