Month: August 2010

Mozilla extension develop center

Posted by – August 12, 2010

Open https://addons.mozilla.org/zh-CN/developers/docs/reference to see more…

Linux All Man page

Posted by – August 12, 2010

Login into http://www.tin.org/bin/allman.cgi

Linux下C取得磁盘空间信息

Posted by – August 11, 2010

#include “sys/vfs.h”

struct statfs * buf;
int b = statfs( “/dev”, buf );

if ( ! b )  {
printf( “free space: %u Kbytes”, buf->f_bfree * 4 );
}
else {
printf( ” Failed “);
}

Refers to:

http://blog.chinaunix.net/u1/44301/showart_2086603.html

先说statfs结构:

#include <sys/vfs.h>    /* 或者 <sys/statfs.h> */

int statfs(const char *path, struct statfs *buf);
int fstatfs(int fd, struct statfs *buf);

参数:
path: 位于需要查询信息的文件系统的文件路径名。
fd: 位于需要查询信息的文件系统的文件描述词。
buf:以下结构体的指针变量,用于储存文件系统相关的信息

struct statfs {
long    f_type;     /* 文件系统类型  */
long    f_bsize;    /* 经过优化的传输块大小  */
long    f_blocks;   /* 文件系统数据块总数 */
long    f_bfree;    /* 可用块数 */
long    f_bavail;   /* 非超级用户可获取的块数 */
long    f_files;    /* 文件结点总数 */
long    f_ffree;    /* 可用文件结点数 */
fsid_t  f_fsid;     /* 文件系统标识 */
long    f_namelen;  /* 文件名的最大长度 */
};

statfs结构中可用空间块数有两种f_bfree和 f_bavail,前者是硬盘所有剩余空间,后者为非root用户剩余空间,ext3文件系统给root用户分有5%的独享空间,所以这里是不同的地方。 这里要强调的是每块的大小一般是4K。因此,要实现与df结果一致的就得在获得块数上乘以4,这样已用、可用、总块数就可以实现。如果还要实现百分比一 致,那么要注意的是,df命令获得是整数百分比,没有小数,这里使用的进一法,而不是四舍五入法。所以在程序里直接+1取整。

下面是实现的一个例子:(home目录为一个独立分区)

#include <stdio.h>
#include <sys/vfs.h>

int main()
{
struct statfs sfs;
int i = statfs(“/home”, &sfs);
int percent = (sfs.f_blocks – sfs.f_bfree ) * 100 / (sfs.f_blocks – sfs.f_bfree + sfs.f_bavail) + 1;
printf(“/dev/sda11            %ld    %ld  %ld   %d%% /home\n”,
4*sfs. f_blocks, 4*(sfs.f_blocks – sfs.f_bfree),      4*sfs.f_bavail, percent);
system(“df /home “);
return 0;

}

执行结果:
leave@LEAVE:~/test$ gcc -o df df.c
leave@LEAVE:~/test$ ./df
/dev/sda11            42773008    540356  40059864   2% /home
文件系统           1K-块        已用     可用 已用% 挂载点
/dev/sda11            42773008    540356  40059864   2% /home
leave@LEAVE:~/test$

html span: left and right align

Posted by – August 5, 2010

Refers to:
1. http://www.htmlcodetutorial.com/help/archive.php/o_t__t_3052__start_0__index.html
2. http://www.quackit.com/html/tags/html_span_tag.cfm

Here’s a solution that might work for you (did for me)

I have multiple lines each enclosed in <div> tags. I want to have some left adjusted and right adjusted text on each line.

Here is some code for one line:
Code:
<div name=”line”>
<div name=”left_text” style=”text-align: left”>My left text</div>
<span name=”right_text” style=”float: right”>My right text</span>
</div>

As I understand it, the (inside) div is a block level element so it can be left adjusted. The span is a line level element, so it cant’ be right adjusted, but it can be floated on the right (just like an image would).

Adding run-time dependency on Ubuntu

Posted by – August 5, 2010

This patch adds a runtime dependency on “dbus-1-utils” to the original source deb.

Refers to:
https://bugs.launchpad.net/ubuntu/+source/avahi/+bug/31458/comments/1
http://launchpadlibrarian.net/1571338/avahi-daemon.debdiff

diff -u avahi-0.5.2/debian/control avahi-0.5.2/debian/control
— avahi-0.5.2/debian/control
+++ avahi-0.5.2/debian/control
@@ -7,7 +7,7 @@

Package: avahi-daemon
Architecture: any
-Depends: ${shlibs:Depends}, ${misc:Depends}, adduser
+Depends: ${shlibs:Depends}, ${misc:Depends}, adduser, dbus-1-utils
Recommends: dbus, libnss-mdns
Suggests: avahi-dnsconfd
Conflicts: mdnsresponder
diff -u avahi-0.5.2/debian/changelog avahi-0.5.2/debian/changelog
— avahi-0.5.2/debian/changelog
+++ avahi-0.5.2/debian/changelog
@@ -1,3 +1,9 @@
+avahi (0.5.2-2) experimental; urgency=low
+
+  * Added dependency on dbus-1-utils, required by postinst
+
+ — Lorenzo J. Lucchini <ljlbox@tiscali.it>  Wed, 15 Feb 2006 02:39:05 +0100
+
avahi (0.5.2-1) experimental; urgency=low

* New upstream release.

Got Canon camera last Sunday.

Posted by – August 4, 2010

I have got my Canon ixus 200 is camera  Last Sunday!
How happy am I!

So I took some pictures with my darling & beautiful wife Hua…
Only I knew how hard it is last Sunday!

写给新入IT的新人们

Posted by – August 3, 2010

Refers to:
http://iove.net/733/

design: sign a Debian changes and dsc file pair using GPG/PGP

Posted by – August 1, 2010

On Ubuntu there are at least two methods to sign a debian changes & dsc file pair using PGP:
Enter into source codes dir, and type below each one commands:
1.sudo dpkg-buildpackage -sa -k$GPG_KEY

note: sign the pair during building package.

2. Two steps below:
1). sudo dpkg-buildpackage -sa
2). sudo debsign -k$GPG_KEY *.changes

note: sign the pair AFTER build package.