• Potential Side Projects

    1. A server app (using Machine Learning technique ) that helps people organize their credit card transactions (hopefully written lisp).
    2. A device that could be used remotely to help me cook rice.
    3. A markdown language that I suits my daily use perfectly.
    4. Learn how to use Emacs for lisp.
    5. My AR.Drone project that needs the conclusion part finished an updated.

     

    Above are projects in the category of either engineer or practicing programming skills. Other aspects of life like health/food/social are listed below.

     

    1. Working out.The first step is to rent locker at the gym. Done
        Sit up + push up –> jogging  | swimming on weekends
    2. Food. Cooking is always important, I love good food.
    3. Learn Japanese.
    4. Learn investment / understand economy.
    5. Visit Canada
  • Hi, my site is back online again :) !

    This site was previously hosted by 000webhost.com. I used Windows Live Writer (WLW) as the offline editor.

    WLW is the best blog tool I have used so far. It copes with WordPress flawlessly and it has good plug-ins for all I need. For example, I can upload my pictures directly to Flickr with Flickr4Writer; I can pull old posts back with one click; I can drag and move things easily. Everything feels native, all I need to worry about is the actual content. With this tool, life is good and happy.

    However, free server is usually not well supported. My eventually went out of business around Oct. 2013. The log in option was intentionally directed to the main page of 000webhost.com . I can still edit the content of my blog,  but I no longer have the feeling that I am the owner of this server.

    Chance finally came this last Friday (11/29/2013), DigitalOcean has a promotion where people get $50 worth of credits if registered on that Black Friday. I was about to buy Linode but it is more expensive. With a little bit of thought I decided to give this VPS hosting service a shot.

    All other billing and registration things aside, the actual site relocation was not a smooth journey.  I have the back-up file for my old site (old_database.sql). What I need to do is to import this old MySQL database into the new MySQL database that is storing my newly installed WordPress database.

    One thing DigitalOcean VPS does differently from 000webhost is that how it connects MySQL database with the WordPress. DigitalOcean VPS has a mysql installed on the VPS machine. All database operations are done on that machine. It is like you have a really machine and you just ssh into that machine and does operations there inside the machine (You can install the graphic interface  phpAdimin on that machine too). 000webhost will just give you a control panel and you can do the database manipulation within the panel.

    Therefore what I did is type in ‘mysql’ in to the terminal that connects to the VPS and following this post at StackOverflow on how to copy one table in one database to another database. The is useful because what I intended to do is to copy the wp_posts table in my old database to the wp_posts in the new database. Because the installation process for WordPress is just creating new tables  in given databases.  For my own record, the list of tables I have copied is the following:

    wp_posts
    wp_comments

    Once these two tables are imported to the database, all my posts and comments are back and online.

    So far so good, data is back how could one ask for more? What had been achieved was good enough for most people but not for a pathetic stubborner. I want the WLW back too. Even though now I am using a mac. I have always wanted to find the alternative to Windows Live Writer. I searched once furiously online when I turned from Windows to Ubuntu and failed. This time I was hoping Mac users will have a beautiful solution. With this motivation I started looking for a good blogging tool on Mac OS X platform. Long story short, I failed, again. There is nothing event close to WLW. However possibility exists that people do not write their blogs inside a high integrated environment. They might just write the markdown and then run a script that will generate HTML+CSS code for them.

    There are two lessons I learned here. First, free service is not necessary always good; Second, there is no good alternative to WLW.

  • Quick tutorial to GNU make

    The idea for this post comes from this thread (How did you learn the GNU make tool) from StackOverflow.

    The GNU make command will look for a file named makefile by default.

    Makefile is just a set of rules. If you offer options for make to build, then make will go to that rule to build according to the rules corresponds to the rules you give it. If you do not offer make any option, then make will go with its default option which is identical to the option all.

    For simple projects like projects with one or two files. The following makefile is already good enough.

    all:
         gcc foo.c – o foo

    We can also have different rules for different object files (files with .o extension), like the following.

    all:
         gcc -c foo.c
         gcc -c bar.c
         gcc foo.o bar.o -o app

    There is a problem as we add more files in to projects because the we need to type in the name for each one of them. Make will compile and link everyone of them every time you invoke make command. This way, it will do some unnecessary work.

    Make knows how to save this extra work if makefile tells make which object file depends on which source file. With this dependency assumed, make will compare the time stamp of source file and object file. If the source is no newer than the object file, then make will not recompile the source file. Else if the source file is newer than the object file, then make will recompile the source file and link it the final executable.

    An example makefile will be the following.

    foo.o: foo.c
          gcc -c foo.c
    bar.o: bar.c
          gcc -c bar.c
    all:
          foo.o bar.o gcc foo.o bar.o -o app

    Those text in red is the part tells make which source file some object file corresponds to. At this point the makefile is already in good shape and make will not do extra work when invoked. However, there is still some extra typing we need to do. In other words, for each object file, we need to create one specific rule to compile it, and add its name for “all” option. Fortunately, this extra work could be further saved.

    Make will assume the dependency by default. So we can do the following thing.

    OBJS=foo.o bar.o

    app: $(OBJS)
        gcc $(OBJS) -o app

    all: app

    This is almost the final version. The only problem for this is that we cannot change the flag, plus we may want to use anther command other than cc command to compile our code like gcc.

    The final version is:

    CC=gcc
    CFLAGS=-Wall -g
    OBJS=foo.o bar.o

    app: $(OBJS)
        $(CC) $(CFLAGS) $(OBJS) -o app

    all: app

    That is it, a quick introduction to GNU make command.

  • How the Compiler Works

    I have always wondered how the compiler works, after I have watched this video, I understood the overall process.

    image[3]

     

    Processing: expand the macros

    image_thumb[7]

    Compilation: from source code to assembly language

    image_thumb[6]

    Assembly: from assembly language to machine code

    image_thumb[5]

    Linking: create the final executable

    image_thumb[10]

    Compilation Stages

    image_thumb[12]

    Compilation Stages

    image_thumb[15]

  • AR.Drone


    The Video above comes from this project: link.

    This one comes from here

    This one is a quadrotor playing ball catch here

  • 地球那边的月亮圆吗?

    到美帝三个月了,一个学期结束,趁还记得点什么赶紧把感受都记下。一是留作备份,二是可供大家参考,少走弯路。

    总体来说,我从交大参加交换项目出国的流程大体是这样的。

    • 收到交换项目的报名通知(我们这届,理学院是孙维敏老师在负责)
    • 在明大的网站上提交申请
    • 准备出国要用的相关材料
      • 大学本科已经有的成绩(在交大办理)
      • 下学期在交大的选课的清单(在交大办理)
      • 高考成绩(去交大档案馆办理)
      • 托福成绩(回家过年的时候顺便准备托福)
    • 明大邮件通知录取结果
      • 可以考虑买机票
    • 申请留学签证(具体过程请参照这里
      • 搞定护照先(具体过程请看这里
      • 跟明大有关的材料
        • 明大给你的通知书
        • 明大跟你的邮件往来
      • 跟交大有关的材料
        • 在交大的成绩
        • 交大跟明大的协议
      • 跟自己有关的材料
        • 英语能力证明
        • 财力证明
        • 学习能力证明
        • 亲属的相关证明等
    • 放暑假,跟好朋友们聚一聚,准备出国用的行李等各种杂物
    • 到美国,找房子
    • 到明大报道,参加各种入学前的培训
    • 上课

    总而言之,语言 + 签证
    Continue reading “地球那边的月亮圆吗?” »

  • 明早出发

    当明早的太阳换下今夜值班的月,我就要出发,去往地球的另一半.

  • dfs 小结

    【poj1426】

    【代码】

    #include<iostream>
    using namespace std;
     
    int n,a[100],ac;
     
    void dfs(int c,int s)//c代表当前长度,s代表余数
    {
        if(s == 0 && ac == 0)
        {
            for(int i=0;i<c;i++)
                cout << a[i];
            cout << endl;
            ac = 1;
        }
        else if(c < 100 && ac == 0)//在深度100内进行递归
        {
     
            a[c] = 1;
            dfs(c + 1,(s * 10 + 1) % n);//s值的更新是难点
            a[c] = 0;
            dfs(c + 1,(s * 10) % n);
     
        }
    }
     
    int main()
    {
        while(cin>>n,n)
        {
            a[0] = 1,ac = 0;
            dfs(1,1);
        }
        return 0;
    }

    Continue reading “dfs 小结” »

  • PC/UVa IDs: 110204/843 Crypt Kicker

    【题目大意】已知一部字典。给出一句加密的话。字母的加密方法是一对一的映射。求密文对应的原文。

    【输入】n个单词,构成了一本字典

    【输出】如果能匹配成功,就输出对应的明文。如果失败,就输出‘*’

    【代码】

    #include<iostream>
    #include<map>
    #include<vector>
    #include<sstream>
    #include<algorithm>
    using namespace std;
    
    
    bool finished = false;
    
    
    void line2word(string line,vector<string> &word)
    {
        istringstream iss(line);
        string w;
        bool found;
    
    
        while(iss >> w){
            found = false;
            for(int i=0;i<word.size();i++)
                if(w == word[i])
                    found = true;
            if(!found)
                word.push_back(w);
        }
    }
    
    
    bool cmp(char a,char b)
    {
        return a<b;
    }
    
    
    bool conflicts(string cipher)//检查是不是有两个密文字母映射到同一明文字母
    {
        sort(&cipher[0],&cipher[0]+cipher.size(),cmp);
    
    
        for(int i=0;i<cipher.size()-1;i++){
            if(cipher[i] != '*' && cipher[i + 1]!='*' &&
                        cipher[i] == cipher[i + 1])
                        return true;
        }
        return false;
    }
    
    
    bool match(string d,string w,string &cipher)
    {
        string tmp = cipher;
    
    
        if(d.size() != w.size())
            return false;
    
    
        for(int i=0;i<w.size();i++){
            if(cipher[w[i] - 'a'] == '*')
                cipher[w[i] - 'a'] = d[i];
            else{
                if(cipher[w[i] - 'a'] != d[i]){
                    cipher = tmp;
                    return false;
                }
            }
        }
    
    
        if(conflicts(cipher)){
            cipher = tmp;
            return false;
        }
    
    
        return true;
    }
    
    
    void decipher(vector<string> &dict,vector<string> &word,int start,string &cipher)
    {
        string tmp = cipher;
        if(start == word.size()){
            finished = !conflicts(cipher);//一般的DFS直接就写成t>**之类的就行了
            return ;
        }
    
    
        for(int i=0;i<dict.size();i++)
            if(match(dict[i],word[start],cipher)){
                decipher(dict,word,start + 1,cipher);
    
    
                if(finished)
                    return ;//返回 main()
                else
                    cipher = tmp;
            }
    }
    
    
    void output(string line,string cipher)
    {
        for(int i=0;i<line.size();i++)
            if(line[i] == ' ')
                cout << ' ';
            else
                cout << cipher[line[i] - 'a'];
        cout << endl;
    }
    
    
    int main()
    {
        string line;
        int n;
        vector<string> dict;
        map<string,int> exist;
        map<string,int>::iterator it;
        vector<string> word;
    
    
        cin >> n;
        cin.ignore();
    
    
        for(int i=0;i<n;i++){
            getline(cin,line);
            it = exist.find(line);
            if(it == exist.end()){
                dict.push_back(line);
                exist.insert(make_pair<string,int>(line,dict.size() - 1));
            }
        }
        /*DFS*/
        while(getline(cin,line)){
    
    
            if(line.size() == 0){
                cout << endl;
                continue;
            }
            /*这里进行了一些处理*/
            word.clear();
            line2word(line,word);
    
    
            finished = false;
            string cipher(26,'*');
    
    
            if(!(word.size() > dict.size()))
                decipher(dict,word,0,cipher);
    
    
            output(line,cipher);
        }
    
    
        return 0;
    }

    【总结】

    这段代码是模仿别人写的。

    该代码的思路是DFS,用递归的方式实现。最重要的两个函数是decipher和match。

    需要专门练习一下DFS的题目。

  • PC/UVa IDs: 110106/10033 Interpreter

    【题目大意】给出一个与代码相对应的表格。不同的代码表示不同的操作。模拟计算机运行。给出最后处理了多少条代码。

    【输入】case数以及具体的代码。

    【输出】运行的代码总条数。

    【程序】

    #include<stdio.h>
    #include<iostream>
    #include<cstdlib>
    #include<cstring>
    using namespace std;
     
    int execute(int mem[],int reg[])
    {
        int p = 0, res = 0, a, b, c;
        while(++res){
            a = mem[p]/100;
            b = mem[p]%100/10;
            c = mem[p]%10;
            if(mem[p++] == 100)
                break;
            switch(a)
            {
                case 2: reg[b] = c; break;
                case 3: reg[b] += c; reg[b] %= 1000; break;
                case 4: reg[b] *= c; reg[b] %= 1000; break;
                case 5: reg[b] = reg[c]; break;
                case 6: reg[b] += reg[c];reg[b] %= 1000; break;
                case 7: reg[b] *= reg[c];reg[b] %= 1000; break;
                case 8: reg[b] = mem[reg[c]]; break;
                case 9: mem[reg[c]] = reg[b]; break;
                case 0: if(reg[c]) p = reg[b]; break;
            }
        }
        return res;
    }
     
    int main()
    {
        int ram[1005];
        int reg[10];
        string line;
        int n;
        cin >> n;
        cin.ignore();
        getline(cin,line);
     
        while(n--){
            memset(ram,0,sizeof(ram));
            memset(reg,0,sizeof(reg));
     
            for(int i=0;getline(cin,line) && line.length();i++)
                ram[i] = atoi(line.data());
     
            cout << execute(ram,reg) <<endl;
            if(n)
                cout<<endl;
        }
     
        return 0;
    }

     

    Continue reading “PC/UVa IDs: 110106/10033 Interpreter” »