Mar 28, 2009

申请了一个域名

ox0spy.cn 现在指向 ox0spy.blogspot.com

Windows下使用linux coreutils

工作中要在Windows下,想用一些Linux下的常用工具时就比较郁闷了
cygwin太大了,而且我只用几个简单的命令,不想装...
还好,这有 GNU utilities for Win32

下载下来,设置下Windows的环境变量就好了

这样,id, pwd, uname, wc, grep, tee, cut, tail, sed, gawk等都可以使用了...

Mar 25, 2009

又在chinaunix中奖了

大家没事多上去玩玩,Chinaunix

2009-3-18,就公布获奖名单了
今天还是看wzt的博客上说他得了入围奖,想起我也做过一道题 O(∩_∩)O~
获得 ChinaUnix第一届“C语言代码”开发大赛 优秀奖
早知积分给这么多,我就都做了...

8. 写一个程序,列出环境变量PATH中包含的所有目录的路径名。注意,Unix/Linux上PATH中各个路径名之间的分隔符与Windows上的不同。 使用条件编译,使你的程序可以适用于这两种系统。


/*************************************************************************
Author : ox0spy
Email : ossteerer@gmail.com
Blog : ox0spy.blogspot.com
Created Time : Tue 17 Feb 2009 08:49:09 AM CST
File Name : 8.c
Description :
************************************************************************/
#include <stdio.h>
#include <stdlib.h>

#define infilename "in.txt"
#define outfilename "out.txt"

/* 定义不同的分隔符 */
#ifdef _WIN32
#define SEPARATOR ";"
#else
#define SEPARATOR ":"
#endif


int main()
{
char *path; /* PATH环境变量 */
char *token;
FILE *outfile; /* 保存结果 */

if(NULL == (outfile = fopen(outfilename, "w")))
{
printf("open output file : %s error!\n", outfilename);
return -1;
}

if(NULL != (path = getenv("PATH"))) /* 获取PATH变量的值 */
fprintf(outfile, "PATH = %s\n\n\n", path);
token = strtok(path, SEPARATOR);
while(NULL != token)
{
fprintf(outfile, "%s\n", token);
token = strtok(NULL, SEPARATOR);
}

return 0;
}


奖品:1000积分 or 一本书

1000积分,但是100积分才1块钱,也就是才10元,拿着10元啥都干不了...
都在坛子混了4年了,积分才1k多,想想,还是再拿本书吧
于是乎,捡了本最贵的o(╯□╰)o 算法导论(原书第2版)
虽然舍长推荐的那本算法书还没看呢 o(︶︿︶)o唉

超级郁闷,算法导论没了,其他书没兴趣,只能拿1000分了

Mar 23, 2009

可以多睡会了....

不用在路上堵着了,自己控制速度,绕着二环路跑...

Mar 22, 2009

Firefox Vimperator

如果你是vim fans, 如果你想扔掉鼠标高效上网,不妨试试 Vimperator

如何使用 vimperator 更好的折腾 firefox 给出了很多有用链接


我整理的一些快捷键(那些英文的都来自linux.com,有时看着英文挺爽的,就没懒得翻译)

1. Google search
        t+要搜索的内容  在新标签中打开Google搜索内容
        t+url                   在新标签中打开url
2. 书签
        M+字幕   定义快捷书签
        go+字幕  转到已定义的快捷书签
        ctrl+D   存到美味书签
        ctrl+K   打开美味书签主页访问
3. 恢复以前的样子
        :set go+=mT             <=> :set guioptions=mT
        :mkv    保存设置
4.
        gt or ctrl-n    : 下一个标签
        gT or ctrl-p    : 前一个标签
        gh                              : 访问Home page
        gH                              : 在新标签中访问Home page
        gu                              : go up.比如,把你从www.test.com/test 带到www.test.com
        H                               : go to the previous page in your browser history.
        L                               : go to the next page in your browser history.
5. commands
    :o http://ox0spy.blogspot.com    : open ox0spy.blogspot.com
    :o search term                    : use the default search engine to search for a search term.
    :o filename                        : open a local file using firefox
    :q                                : close the current tab. if only one tab is open, exit firefox.
    :zi                                : zoom in. Increases text size by 25% on the page that has focus.
    :qI                                : zoom in by 100% on the page that has focus.
    :zo                                : zoom out.Decreases text size by 25% on the page that has focus.
    :zO                                : zoom out by 100% on the page that has focus.
    :zz                                : used alone zz will reset page to 100%. use witha a count, it will set the text size to any value between 25% and 500%. So, 105zz will set the text size to 105% of normal.
6. links
    打开链接:
        f 进入hints mode,所以链接都被高亮显示而且前面有标示,输入相应的标示键就可以到那个链接了.
    ??    ;; 进入ExtendedHint mode,和hints mode 类似,输入标示键,然后可用使用'y'复制url,'Y'复制url的描述文本.
7. history
    :history                : 默认显示10个历史浏览记录
    :history search term    : 搜索浏览历史
    ESC                        : 关闭显示
8. searching
    /search term
    ?search term            : like vim
9. quitting
    :qall or ZQ                : will exit firefox and clear the session history.
    ZZ                        : quit firefox, but restart it later with the same session.
    :restart                : restart firefox immediately.
10. refresh
    r                        : like <F5>, refresh page
11. copy && paste
    When I want to copy some text, I usually start by searching with '/' the
    beginning of it, then I press 'i' to go in CARET mode, 'v' to go in
    VISUAL mode. Then I can select my text. When I'm done, I type y to copy
    it, and I paste it wherever I want to.

Mar 21, 2009

搞定blogspot贴代码

现在代码可以高亮显示了...
1. pretty print
2. vim2html

#!/usr/bin/env python
print "Only test ..."


#include <stdio.h>
int main(void)
{
printf("Only test ...");
return 0;
}



不爽的是我一般通过email发布文章...

PS:把最新评论也添加上...

参考:
怎样给Blogger添加侧边栏评论和最新文章(续)
How to publish source code in Blogger.com

Mar 18, 2009

又开始工作了...

2009-03-17 又一次开始上班...

ox0spy@ox0spy-laptop:~$ date
Wed Mar 18 00:26:31 CST 2009

累啊,睡觉去...

上次笔试编程题

有一个文件,内容如下:
ox0spy@ox0spy-laptop:/code/c$ cat tt.txt
aa,female,21,54
abc,male,20,60
tt,male,22,58
ox0spy,male,23,80
mary,female,24,90
cc,female,22,88

每个字段代表的意思是:姓名,性别,年龄,成绩
请用c语言编写程序,打印成绩大于等于60分的同学的姓名和成绩.

ox0spy@ox0spy-laptop:/code/c$ cat parseCsv.c
/*************************************************************************
Author : ox0spy
Email : ossteerer@gmail.com
Blog : ox0spy.blogspot.com
Created Time : Tue 17 Mar 2009 11:35:04 PM CST
File Name : parseCsv.c
Description :
************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int main()
{
char filename[20] = "tt.txt";
FILE *fp;
char name[20];
char sex[8];
int age;
int grade;

if((fp = fopen(filename, "r")) == NULL)
{
printf("open file : %s error\n%s\n", filename, strerror(errno));
exit(1);
}

while(fscanf(fp, "%[^,],%[^,],%[^,],%d\n", name, sex, &age, &grade)
!= EOF)
{
if(grade >= 60)
printf("%s\t%d\n", name, grade);
}

fclose(fp);

exit(0);
}

Mar 17, 2009

error: stdio.h: No such file or directory

写了一个简单的程序出现错误,提示:error: stdio.h: No such file or directory

把build-essential装上就好了...

ox0spy@ox0spy-laptop:/code/c$ sudo apt-get install build-essential

Mar 13, 2009

ubuntu 8.04 install mpd

$ sudo apt-get install mpd
出错:
ALSA lib pcm_dmix.c:874:(snd_pcm_dmix_open) unable to open slave
No protocol specified
E: client-conf-x11.c: XOpenDisplay() failed

解决:
$ sudo apt-get install paprefs
$ paprefs
* Enable network access to local sound devices
* Don't require authentication

在/etc/mpd.conf 中添加:
audio_output {
type "pulse"
name "My MPD Pulse output"
}

$ sudo /etc/init.d/mpd restart

$ sudo mpd --create-db

$ mpc listall | mpc add

$ mpc play

mpc 与 vim 结合,以便写代码时听歌
编辑.vimrc,添加mpc的热键
map mp :!mpc play<cr>
map mn :!mpc next<cr>
map ms :!mpc stop<cr>