Sep 5, 2011

Install driver for Atheros AR9271 on Ubuntu

    thinkpad x10 无线网卡太弱,买了块无线网卡,插入无法识别,打开带的光盘,里面只有windows驱动。

   了解了下,已经有人做好了安装工具 - ath9k_htc-installer,还是deb包,下载安装,然后,终端运行

$ ath9k_htc-installer

出来一个图形界面,直接安装即可,然后,插入 无线网卡 ,仍然无法识别
$ dmesg | tail
[  143.882952] usb 1-1: ath9k_htc: Firmware - htc_9271.fw not found
[  143.882983] ath9k_htc: probe of 1-1:1.0 failed with error -22

$ sudo wget  -P /lib/firmware http://wireless.kernel.org/download/htc_fw/1.3/htc_9271.fw

重新插上,小灯开始闪烁了。

从 ath9k_htc-installer 的运行log看,这个工具应该是修改.config文件,然后重新编译kernel了,所以,和http://wireless.kernel.org/en/users/Drivers/ath9k_htc 讲的一样,只是不用一般用户自己编译kernel。

Jul 7, 2011

test

just test from my android phone!

Jun 29, 2011

lidroid 2.6 replace TouchWiz40Launcher to TouchWiz30Launcher

Samsung I9000, sometimes TWL4 is very slow, so I want to use TWL3.

download lidroid 2.7 from here.
$ unrar -e lidroid-sgs-2.7.0-i9000.rar
$ tar xvf PDA-i9000.tar.md5
$ sudo mount -o loop factoryfs.rfs /mnt
$ adb remout
$ adb push /mnt/app/TouchWiz30Launcher.apk /system/app
$ adb shell reboot

May 25, 2011

set time zone on Ubuntu

Modify time zone on Ubuntu 10.04.

$ sudo tzselect

$ sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

$ sudo ntpdate cn.pool.ntp.org

# disable UTC
$ sudo sed -i 's/^UTC=yes/UTC=no/' /etc/rcS

setup vpn server on Amazon EC2

My environment: Amazon free EC2, Ubuntu 10.04 64bit

You should modify some hard code.

server side

  • $ cat setup-pptpd.sh
    #!/bin/bash
    
    # install pptpd
    apt-get install -y pptpd
    
    # config pptpd
    echo "localip 192.168.2.1" >> /etc/pptpd.conf
    echo "remoteip 192.168.2.2-10" >> /etc/pptpd.conf
    echo "ms-dns 172.16.0.23" >> /etc/ppp/options.pptpd
    echo "ms-dns 8.8.8.8" >> /etc/ppp/options.pptpd
    
    # generate user's password
    passwd=`openssl rand 10 -base64`
    if [ "$1" != "" ]
    then passwd=$1
    fi
    
    # setup authenticated user
    echo "user pptpd $passwd *" >> /etc/ppp/chap-secrets
    
    # for ipv4 forwarding
    sed -i 's/^#net.ipv4.ip_forward = 1/net.ipv4.ip_forward = 1/' \
     /etc/sysctl.conf
    sysctl -p
    
    # use iptabes to get the net forward
    iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -j SNAT \
     --to-source $(ifconfig  | grep 'inet addr:'| \
     grep -v '127.0.0.1' | cut -d: -f2 \
     | awk 'NR==1 { print $1}')
    iptables -A FORWARD -p tcp --syn -s 192.168.2.0/24 \
     -j TCPMSS --set-mss 1356
    service iptables save
    
    # make the iptables and pptpd auto start
    chkconfig iptables on
    chkconfig pptpd on
    
    service iptables start
    service pptpd start
    
    echo "VPN service is installed"
    echo "VPN username is user,VPN password is $passwd"
     

client side

$ cat setup-pptp-client.sh
#!/bin/bash

apt-get install -y pptp-linux

# modify those variable for your environment
vpn_server="1.2.3.4"
user="user"
passwd="secret"

echo "pty \"pptp $vpn_server --nolaunchpppd\"
name $user
remotename pptpd 
require-mppe-128
file /etc/ppp/options.pptp
ipparam pptpd" > /etc/ppp/peers/pptpd

echo "$user pptpd $passwd *" >> /etc/ppp/chap-secrets

echo "setup vpn client done."
echo -e "now, you shoule run:"
echo -e "\t$ pon pptpd # start pptpd"
echo -e "\t$ pon pptpd debug dump logfd 2 nodetach # debugging"
echo -e "\t$ poff pptpd # stop pptpd"
echo -e "\t$ ifconfig # check network config"

May 20, 2011

awk after the number of field or the value of field changed

# from awk manpage
References to non-existent fields (i.e. fields after $NF) produce the null-string.
However, assigning to a  non-exis‐tent field (e.g., $(NF+2) = 5) increases the value of NF,
creates any intervening fields with the null string as their value, and causes the value
of $0 to be recomputed, with the fields being separated by the value of  OFS.

References to negative numbered fields cause a fatal error.

Decrementing NF causes the values of fields past the new value to be lost,
and the value of $0 to be recomputed, with the fields being separated by the value of OFS.

Assigning a value to an existing field causes the whole record to  be  rebuilt  when  $0  is  referenced.
Similarly, assigning a value to $0 causes the record to be resplit, creating new values for the fields.


意思是:
1. 引用不存在的字段,会使增加NF的值,$0要根据OFS的值重新创建,中间的字段设置为空字符串, 然后根据FS的值重新对$0进行分割.
如:
$ echo 'a b c' | awk '{print $0; $6=60; OFS=":"; print $0}'
a b c
a:b:c:::60
可以清楚的看到, 第4,5字段的值都是空字符串.

2. 引用编号小于零的字段,会引起错误.
如:
$ cal | awk '{print $-1}'
awk: (FILENAME=- FNR=1) fatal: attempt to access field -1

3. 减少NF的值,编号大于NF的字段将丢失,$0根据OFS的值重新创建,然后根据FS的值重新分割记录.
如:
$ echo 'a b c d e f' | awk '{print $0; NF=3; print $0}'
a b c d e f
a b c

4. 给存在的字段赋值,使$0根据OFS的值重新创建,然后根据FS的值重新分割记录.
如:
$ echo 'a b c' | awk '{print $0; $1=$1;OFS=":"; FS=":"; print $0; print $1}'
a b c
a:b:c
a

5. 给$0赋值,$0现在是被赋予的新值,$0根据FS的值重新分割记录.
$ echo 'a b c' | awk '{print $0; $0=$0;OFS=":"; FS=":"; print $0; print $1}'
a b c
a b c
a

echo 'a b c' | awk '{print $0; $0="c d e"; print $0; print $1}'
a b c
c d e
c

note:
  a. 4, 5是ChinaUnix.net Shell 编程大赛的第8题.
  b. 可以发现当字段个数或者字段被修改后,都要根据OFS的值进行$0重建, 然后,$0根据FS的值重新分割.
  c. 只修改$0, 使$0用新值根据FS的值重新分割.

May 9, 2011

build Android 2.3, ld cannot find -lz

Build Android 2.3 (gingerbread), report error: /usr/bin/ld: skipping incompatible /usr/lib/libz.so when searching for -lz /usr/bin/ld: skipping incompatible /usr/lib/libz.a when searching for -lz /usr/bin/ld: cannot find -lz collect2: ld returned 1 exit status fix it: $ sudo apt-get install lib32z-dev

Mar 25, 2011

c tips from wang

wlh走前给大家分享的一些c tips, 我还没搞懂,先记下
#include <stdio.h>

#define get_parent(x) (struct A*)((unsigned int)x - (unsigned int)&((((struct A*)0)->j)))

struct A
{
    char name[37];
    int i;
    int j;
    int k;
    char city[37];
};

void func(int* p_int)
{
    printf("in function %x\n", (unsigned int)get_parent(p_int));
}

int main()
{
    struct A a_var;
    printf("address of a_var is %x\n", (unsigned int)&a_var);
    func(&(a_var.j));
    return 0;
}

变态的面试题

从下面两个地方看到的 via Google Reader ...
http://www.kernelchina.org/?q=node/961
http://coolshell.cn/articles/3961.html
int n=20;
for(int i=0; i<n; i--){
    printf("-");
}
将上面的代码,修改或添加一个字符,使程序可以输出20个减号.(据说c有三种;java有二种修改方法)
C代码:
#include <stdio.h>

int main(int argc, char *argv[])
{
    /* first way */
    int n=20;
    for(int i=0; i<n; n--){
        printf("-");
    }
    printf("\n");

    /* second way */
    n=20;
    for(int i=0; -i<n; i--){
        printf("-");
    }
    printf("\n");

    /* third way */
    n=20;
    for(int i=0; i+n; i--){
        printf("-");
    }
    printf("\n");

    return 0;
}

Java代码:
class Test
{
    public static void main(String[] args)
    {
        /*
        int n=20;
        for(int i=0; i<n; i--){
            printf("-");
        }
        */

        /* first way */
        int n=20;
        for(int i=0; i<n; n--){
            System.out.print("-");
        }
        System.out.print("\n");

        /* second way */
        n=20;
        for(int i=0; -i<n; i--){
            System.out.print("-");
        }
        System.out.print("\n");
    }
}
C中的第三种:
/* third way */
n=20;
for(int i=0; i+n; i--){
    System.out.print("-");
}
System.out.print("\n");
$ javac Test.java
Test.java:28: incompatible types
found   : int
required: boolean
        for(int i=0; i+n; i--){
                      ^
1 error

Mar 23, 2011

enable core dump on Debian

globally enable core dump on Debian
1. edit /etc/security/limits.conf, add the bellowing line
*               soft    core            unlimited
2. logout and login
$ ulimit -c
$ ulimit -a

blogspot code syntax highlight

以前写的blogspot贴代码:http://ox0spy.blogspot.com/2009/03/test.html
参考: http://mlawire.blogspot.com/2009/07/blogger-syntax-highlighting.html
下载模板,在 </head> 前添加
    <!-- highlighting code -->
    <link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>
    <link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/>
    <!-- add brushes here -->
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPerl.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'/>
    <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js' type='text/javascript'/>
    <script type='text/javascript'>
      SyntaxHighlighter.config.bloggerMode = true;
      SyntaxHighlighter.all();
    </script>
然后上传模板,保存 ...
测试c程序
#include <stdio.h>

int main(int argc, char* argv[])
{
    printf("test only ...\n");
    return 0;
}
测试bash程序
#/bin/bash

echo "test only ..."

不希望显示行号,使用: class="brush:bash; gutter:false"

Mar 22, 2011

一道笔试题

#include <stdio.h>
#include <string.h>

char *shift_r(const char *src, const int n, char *dst)
{
    int i, len;

    if (src == NULL || (len = strlen(src)) == 0)
        return (dst = NULL);

    for (i = 0; i < len; i++)
        dst[(i+n)%len] = src[i];
    dst[i] = '\0';

    return dst;
}

int main(int argc, char *argv[])
{
    const char *src = "abcdef";
    char dst[80];
    const int n = 2;

    printf("%s\n%s\n", src, shift_r(src, n, dst));

    return 0;
}
好吧, 这个也算 ... 口头描述这个真没劲 ...
#!/bin/bash

echo "testing for ..."
for ((i=0; i < 10; i++))
do
    echo $i
done

echo "testing while ..."
i=0
while [ $i -lt 10 ]
do
    echo $i
    i=$((i+1))
done

Mar 18, 2011

学习 qt c++

下次需要学什么还是碰到就开始好好学, 过去这么多时间,悲剧阿 ...

log ...

Mar 15, 2011

Installing Debian from USB

download files

Make bootable USB

  • Note: in this example, the USB stick is SCSI device /dev/sdb
  • $ sudo apt-get install mtools syslinux dosfstools
  • $ sudo modprobe usb-storage
  • $ sudo fdisk -l /dev/sdb
  • $ sudo mkdosfs -I /dev/sdb
  • $ sudo syslinux /dev/sdb
  • $ sudo mount /dev/sdb /mnt
  • $ sudo cp -f vmlinuz initrd.gz syslinux.cfg debian-6.0.0-i386-netinst.iso /mnt
  • $ sudo umount /mnt

boot from USB stick

  • set the first boot device in the BIOS to USB-ZIP.
  • insert your USB drive, and boot your computer.

Mar 10, 2011

同事的你 [zz]

/*
 * author: unknown, 来自网络
 * description: 这个时间看到这个歌词, 感慨万千 ~ 
 */


明天你是否会想起
昨天你写的程序
明天你是否还惦记
曾经爱编程的你
领导们都已想不起
曾经加班的你
我也是偶然看程序
才想起同事的你
谁聘了牛B烘烘的你
谁安慰天天加班的你
谁把你的设计做起
谁给你做的升级

你从前总是很小心
从不把离职的事提起
你也曾无意中说起
薪水实在太低
那时候屏幕总是在闪
日子总过得太慢
你总说离职遥遥无期
转眼就各奔东西
谁聘了牛B烘烘的你
谁安慰天天加班的你
谁看了我给你写的信
谁把它删在垃圾文件夹里

从前的日子都远去
我也将有我的新上司
我也会给他编程序
给他讲同事的你
谁聘了牛B烘烘的你
谁安慰天天加班的你
谁把你的设计做起
谁给你做的升级
. . .

Mar 3, 2011

Python Challenge

http://www.pythonchallenge.com

太有意思了, 已经使我无法认真看 Android App 开发了 ...
我把自己做得答案都放到 github 上了,
https://github.com/ox0spy/Python-Challenge

Feb 18, 2011

empathy MSN error "Network error connecting"

ubuntu 10.10, empathy 无法登录 MSN, 错误信息: "Network error connecting"

解决:
$ sudo apt-get purge telepathy-butterfly

Feb 11, 2011

MeeGo估计被废了

  等了好久的 2011-02-11,今天终于等到了nokia的重大消息, 其实是预料之中的(2010年10月就应该知道今天的肯定会来的),但,听到时还是无法淡定。
  对, nokia要和微软合作,nokia说要分2个部门,名字都是虚的,我更关注内容,说白了,1个搞智能手机(Windows Phone, Symbian, MeeGo); 1个搞非智能手机.
  关注nokia的时间较短有半年多,但,自从2010年10月左右,nokia的ceo闪人后,猛看了很多nokia的资料。加上这几个月的关注,让我无法看好它,基本认为它现在自己都不知道自己应该做什么,怎么做。
  2010年10月,nokia说要放弃symbian,搞symbian的裁员很多。说要全力以赴的搞MeeGo,MeeGo除了很慢,我不知道它还有啥其他关键问题。现在又说继续卖symbian, 继续裁员。不知道intel 今天情绪是否稳定 ...
  微软嘛,大家都知道我是 Linux fans, 爱生活,爱自由。微软的windows phone现在市场占有率很低, 而且,做windows phone的大厂, 三星,htc,motorola(之前也出过),现在都主要做Google android, 而且,自从做了android,腰不疼了,生活和谐了,也转亏为盈了(尤其motorola)。但,现在nokia不信邪,非要这么做,预测归预测,事实还要时间证明。

  今天让我对外包(outsource)有了新的认识.

  好,洗洗睡吧, 明天还是美好的。

Feb 4, 2011

黄石公园,大熊猫繁殖基地,动物园

黄石公园是看的纪录片,共3级,很不错,纯野生。

今天去大熊猫繁殖基地,成都动物园看了下,动物们活的真的很绝望啊,年复一年,房子虽然是有了,但,整天活着有啥意义呢,他们能改变点啥呢,其实就是人类盼他们了一个无期徒刑,还美其名曰 “保护” :-)

熊猫基地去年看过一次,实在没劲,但,为了让家人都近距离的看下国宝,今天还是去看了下,还是象去年的感觉一样, 离开人类, 大熊猫就挂了

熊猫基地里的小熊猫还是不错,今年又多了很多孔雀,不过,没看到孔雀开屏。貌似, 天鹅湖里还有3只鸳鸯?, 但,为啥就三只,这小东西不是特中感情,搞单了就会单相思,然后挂掉的吗

成都动物园,除了绝望的动物们,影响中就只有脏乱了,超多的人 ...
两栖馆竟然只有鱼类,还两栖 ....
一只大象正在吃草,看着那么多人看它,就把草用鼻子卷着进屋子吃了,我也很识趣的离开了 :-)

其他动物年老的都很淡定了,也许他们习惯了、麻木了; 年轻的虽然知道自己无法改变现实,但,或许他们还有一丝幻想,努力着,虽然有些狂躁,毕竟,他们在寻找出路 ...

PS: 看到很多家长带着孩子去看动物,看着那么多成年人看着那些动物还那么好奇,突然觉得生活在城市里的人好可怜啊,尤其小孩。想想自己小时候,鸡、鸭、鹅、鸽子、兔子、羊、牛、猪、狗都自己养过,很多家里无法喂养的,都近距离接触过 ...

想到 怦然心动 Flipped 中的女主角喂鸡,修花园的场景 ...

作为不认同城市让生活更美好的人,有机会还是去个山清水秀的小乡村,上着小网,过着自给自足的日子 ...

Jan 31, 2011

fatal: error processing config file(s)

一台服务器上的git版本太低, 如果 apt-get remove git 会 remove 掉很多我还想要得软件包。只好下载源码编译覆盖掉以前的(./configure --prefix /usr).

但,运行 git 然后tab补齐时报错 "fatal: error processing config file(s)"

fix:
$ touch ~/.gitconfig

很早前就有人报过这个问题.

Jan 29, 2011

GStreamer move mailing list

昨晚看到GStreamer把邮件列表从sourceForge.net 迁移到 freedesktop.org ,还提到病毒之类的, 详情
刚才从 http://xorl.wordpress.com/2011/01/28/news-sourceforge-net-owned/ 才知道 sf 服务器被黑了
详情关注 http://sourceforge.net/apps/wordpress/sourceforge/


Jan 24, 2011

健康平安最重要

如题,第一次有这么强烈的感触,昨晚害怕、紧张、担忧、疲惫,总之,吓死我了 ...

今天凌晨4点开始睡觉,头一直好痛,早上9点被闹钟叫醒请假,头更加痛了。11点忍着爬起来,下午去上班 ...

人生苦短,健康、平安,有点追求就行

Jan 22, 2011

折腾gnome3

今天看到 gnome3.org 上线了,上去看了看,发现不错,就开始折腾了。

/*
早上又给长城宽带打电话让过来收钱, kao, 还是给我说,他们会尽快安排过来。一天又过去了,还是没见到他们工作人员,连个电话都没有。md, 这帮家伙是老板不给没发年终奖,还是打算闪人了 ....
*/

http://live.gnome.org/GnomeShell#building 根据这个页面讲得应该可以装好。

Note:
1. libtool 需要 2.2.10, 我的 ubuntu 10.10安装的是 2.2.6, 所以,需要自己下载编译.
2. gnome3 装好后,运行 $ ./gnome-shell --replace 报错
mutter: symbol lookup error: /home/ox0/gnome-shell/install/lib/gtk-3.0/modules/libcanberra-  gtk-module.so: undefined symbol: gtk_quit_add
ox0@lucid:~/gnome-shell/source/gnome-shell/src$ Cannot register the panel shell: there is already one running.
 解决:
$  rm ~/gnome-shell/install/lib/gtk-3.0/modules/libcanberra-gtk-module.so

Jan 1, 2011

2010 回顾, 2011展望

http://ox0spy.blogspot.com/2011/01/2010-books-movies.html 看到2010年没看啥技术书籍

2010大事记:
3月底,回了次家
5月底,到现在的公司,一切都比以前好很多,开始run scrum
7月,porting gstreamer, 大家想把dsp带起来,狂加班;负责gstreamer录音、录像的同学们也碰到了很多问题,大家都在加班
7月底,db选择换个行业去了北京,很有魄力,祝福
9月初,应该是这时候,lm 突然间就被调到其他项目组了,太突然,然后,wlh上 ...
9月中旬,代替xx做了几天郁闷的项目,没过几天,项目被cancelled
11月中旬,开始做 oss contribution, 先后跟过 alsa-project, pulseaudio, 现在跟gstreamer; 这时候项目组两人要出国做项目了, 先后换了几个scrum master, 很幸运(or 不幸 :-P),都是老外
12月,过来新PM, 现在是manager了,项目组又有了生机,大家用2周搭建,整理了一个wiki,为新员工的加入做好了准备

看下去年的计划,显然没有完成,但现在目标越来越清晰。
1. database现在基本不用,所以没有学习的必要
2. tuxedo, aix 也没有关注的必要了

2010目标:
1. 英语,必须抓紧了
2. oss contribution, 争取早日混个 developer
3. embedded linux, 开始学习Linux kernel
4. python 看上2本书,好好学下,在gae上实践
5. 系统的学下敏捷开发
6. 争取在成都Linux社区,参加组织点活动

2010 看过的书籍,电影

今年没看啥技术书
 2, 3, 7月一本都没看,
2月过年了,
3月开始工作,公司准备让我做xx省农信的的ECIF,项目组新成立,我忙着研究ETL工具,学习Oracle ...
5月底到现在的公司报道,6月开始做porting gstreamer,7月应该是项目组狂加班的那段时间,大家每天都加至少1小时.
9,10月开始住的离公司近了, 每天时间都多了好多
11,12月开始关注些其他东西,12月其实也看了很多东西,好多是技术手册,没放到豆瓣上

从下面两张图片可以看到, 除了7月加班,其他时间看书多,电影就少了 , 废话 !..

想知道怎么统计的,猛击这里