Mar 28, 2009
Windows下使用linux coreutils
cygwin太大了,而且我只用几个简单的命令,不想装...
还好,这有 GNU utilities for Win32
下载下来,设置下Windows的环境变量就好了
这样,id, pwd, uname, wc, grep, tee, cut, tail, sed, gawk等都可以使用了...
Mar 25, 2009
又在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
如何使用 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
上次笔试编程题
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
把build-essential装上就好了...
ox0spy@ox0spy-laptop:/code/c$ sudo apt-get install build-essential
Mar 13, 2009
ubuntu 8.04 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>
Mar 12, 2009
看中文 manpages
ox0spy@ox0spy-laptop:~$ sudo apt-get install manpages-zh
在.bashrc 中添加一个cman的别名
ox0spy@ox0spy-laptop:~$ grep cman .bashrc
alias cman='man -M /usr/share/man/zh_CN'
现在就可以用 cman 查看中文manpages了,不够中文manpages不是很全
另外,打算在ubuntu 上作开发,当然要再装个包了: manpages-dev
ox0spy@ox0spy-laptop:~$ sudo apt-get install manpages-dev
再分享一个小技巧,如果你想让grep 把关键字用其他颜色显示出来,那么,在.
bashrc 中把"alias grep='grep --color=auto'
"前的 "#"去掉即可
ox0spy@ox0spy-laptop:~$ grep grep .bashrc
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
最后,修改.bashrc 和 修改.profile效果一样。修改完这些文件记得执行
. .bashrc
或
source .bashrc
dpkg was interrupted, you must manually run 'dpkg --configure -a' to correct the problem.
.
..
...
Fetched 1165kB in 2min7s (9162B/s)
E: dpkg was interrupted, you must manually run 'dpkg --configure -a' to correct the problem.
竟然有错,
按提示,输入: dpkg --configure -a
ox0spy@ox0spy-laptop:~$ sudo dpkg --configure -a
Setting up initramfs-tools (0.85eubuntu39.3) ...
update-initramfs: deferring update (trigger activated)
Processing triggers for initramfs-tools ...
update-initramfs: Generating /boot/initrd.img-2.6.24-24-generic
gzip: stdout: No space left on device
update-initramfs: failed for /boot/initrd.img-2.6.24-24-generic
dpkg: subprocess post-installation script returned error exit status 1
原来没空间了
下面确定下,果然/boot 被100%的使用了
ox0spy@ox0spy-laptop:~$ df -m /boot/
Filesystem 1M-blocks Used Available Use% Mounted on
/dev/sda8 43 41 1 100% /boot
ox0spy@ox0spy-laptop:/boot$ sudo mv initrd.img-2.6.24-2*.bak ~/
然后,再看下/boot可用空间
ox0spy@ox0spy-laptop:/boot$ df -m /boot/
Filesystem 1M-blocks Used Available Use% Mounted on
/dev/sda8 43 26 15 64% /boot
恩,有15M 可用,先试试...
ox0spy@ox0spy-laptop:/boot$ sudo dpkg --configure -a
Setting up initramfs-tools (0.85eubuntu39.3) ...
update-initramfs: deferring update (trigger activated)
Processing triggers for initramfs-tools ...
update-initramfs: Generating /boot/initrd.img-2.6.24-24-generic
OK,没问题了
看来下次得把/boot空间分大点,50M有点小了...
或经常把/boot中的备份文件移到其他地方
ubuntu 字体美化
LiHeiPro.ttf Lucida Grande.ttf simfang.ttf stheiti.ttf
local.conf msyh.ttf simsun.ttc
ox0spy@ox0spy-laptop:~$ sudo mkdir /usr/share/fonts/truetype/msfonts/ &&
sudo cp /media/Soft/Linux/font/* /usr/share/fonts/truetype/msfonts/
ox0spy@ox0spy-laptop:~$ cd /usr/share/fonts/truetype/msfonts/
ox0spy@ox0spy-laptop:/usr/share/fonts/truetype/msfonts$ sudo mkfontscale
ox0spy@ox0spy-laptop:/usr/share/fonts/truetype/msfonts$ sudo mkfontdir
ox0spy@ox0spy-laptop:/usr/share/fonts/truetype/msfonts$ sudo fc-cache
ox0spy@ox0spy-laptop:/usr/share/fonts/truetype/msfonts$
字体设置:
Firefox 字体设置: