<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>土贼的奇异生活 &#187; 技术 | 工作</title>
	<atom:link href="http://tuzei.net/category/tech_internet/feed/" rel="self" type="application/rss+xml" />
	<link>http://tuzei.net</link>
	<description>Talk is cheap. Show me the code.</description>
	<lastBuildDate>Wed, 16 May 2012 11:54:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Install tokyo cabinet and python tc egg step by step</title>
		<link>http://tuzei.net/2012/05/16/install-tokyo-cabinet-and-python-tc-egg-step-by-step/</link>
		<comments>http://tuzei.net/2012/05/16/install-tokyo-cabinet-and-python-tc-egg-step-by-step/#comments</comments>
		<pubDate>Wed, 16 May 2012 11:52:55 +0000</pubDate>
		<dc:creator>jaykenduke</dc:creator>
				<category><![CDATA[技术 | 工作]]></category>
		<category><![CDATA[tokyo cabinet]]></category>

		<guid isPermaLink="false">http://tuzei.net/?p=772</guid>
		<description><![CDATA[1: wget 下载tokyo cabinet 2: 编译, 安装 ./configure; make &#38;&#38; make install 注： 若提示-&#62;configure:error: zlib.h is required, 安装zlib1g-dev libssl-dev 若提示-&#62;configure:error: bzlib.h is required, 安装libbz2-dev 3：安装python的egg包: 1. git clone git://github.com/rsms/tc.git 2. python setup.py install 注： 若提示-&#62;fatal error: Python.h: No such file or directory, 安装python2.6-dev 另：查看缺文件所属包使用apt-file工具(apt-file update &#38;&#38; apt-file search xxx) // 环境 ubuntu 10.04 &#38;&#38; kernel [...]]]></description>
			<content:encoded><![CDATA[<p>1: wget 下载<a href="http://fallabs.com/tokyocabinet/tokyocabinet-1.4.47.tar.gz ">tokyo cabinet</a><br />
2: 编译, 安装</p>
<blockquote><p><strong> ./configure; make &amp;&amp; make install</strong></p>
<blockquote><p>注：</p>
<p>若提示-&gt;configure:error: <strong>zlib.h</strong> is required, 安装<strong>zlib1g-dev libssl-dev</strong><br />
若提示-&gt;configure:error: <strong>bzlib.h</strong> is required, 安装<strong>libbz2-dev</strong></p></blockquote>
</blockquote>
<p>3：安装python的egg包:</p>
<blockquote><p>1.<strong> git clone git://github.com/rsms/tc.git</strong><br />
2. <strong>python setup.py install</strong></p>
<blockquote><p>注：</p>
<p>若提示-&gt;fatal error: <strong>Python.h</strong>: No such file or directory, 安装<strong>python2.6-dev</strong></p>
<p>另：查看缺文件所属包使用apt-file工具(apt-file update &amp;&amp; apt-file search xxx)</p></blockquote>
</blockquote>
<p>// 环境 ubuntu 10.04 &amp;&amp; kernel 2.6.32-38-generic</p>
]]></content:encoded>
			<wfw:commentRss>http://tuzei.net/2012/05/16/install-tokyo-cabinet-and-python-tc-egg-step-by-step/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>设备名与文件系统结构的关系</title>
		<link>http://tuzei.net/2012/03/07/ddandfs/</link>
		<comments>http://tuzei.net/2012/03/07/ddandfs/#comments</comments>
		<pubDate>Tue, 06 Mar 2012 17:00:36 +0000</pubDate>
		<dc:creator>jaykenduke</dc:creator>
				<category><![CDATA[技术 | 工作]]></category>
		<category><![CDATA[Device driver]]></category>

		<guid isPermaLink="false">http://tuzei.net/?p=749</guid>
		<description><![CDATA[前段时间看字符设备驱动的时候，遇到了一些问题。在我们完成驱动模块开发后，将模块加入内核后，会对文件系统产生什么影响，也就是说会在哪里添加一些文件或者链接。后来查资料，做了记录。 一：主要进行的操作有: 1. 注册设备； 2. 加载模块； 3. 创建设备节点 4. 删除模块 二：主要影响的目录有以下四个: 1. /proc/devices； 2. /proc/modules； 3. /sys/modules； 4. /dev/ 三：详细说明 1./proc/devices:注册设备列表. 注册设备（register_chrdev_region,allow_chrdev_region）后在此添加一行，包含两列(主设备号，设备名称)。其中的模块名称就是在调用注册函数时，形参中的设备名。 2. /proc/modules:模块加载列表. insmod（加载模块）后在此添加一行。包含列(模块名称，模块大小(bytes)，加载数目，模块加载状态，内存偏移(用于debug))。其中模块名就是调用insmod时所使用参数中的设备名，即xx.ko中的xx。 3. /sys/module:添加一个目录. insmod（加载模块）后在此添加一子目录，同2. 4. /dev/*:设备节点. mknod（创建设备节点）后在此添加一设备文件。名称为mknod的参数名。 四：删除模块 使用rmmod xxx或modprobe -r xxx。删除模块后，/proc/devices, /proc/modules, /sys/module 中的记录都会被清除。 五：总结 为了避免混淆设备和模块名称，尽量在注册函数，插入模块，创建设备文件节点时使用同样的名称。 参考文档：Top-level Files within the proc File System]]></description>
			<content:encoded><![CDATA[<p>前段时间看字符设备驱动的时候，遇到了一些问题。在我们完成驱动模块开发后，将模块加入内核后，会对文件系统产生什么影响，也就是说会在哪里添加一些文件或者链接。后来查资料，做了记录。</p>
<p>一：主要进行的操作有: </p>
<blockquote><p>
1. 注册设备；<br />
2. 加载模块；<br />
3. 创建设备节点<br />
4. 删除模块
</p></blockquote>
<p>二：主要影响的目录有以下四个: </p>
<blockquote><p>
1. /proc/devices；<br />
2. /proc/modules；<br />
3. /sys/modules；<br />
4. /dev/ </p></blockquote>
<p>三：详细说明</p>
<blockquote><p>1.<strong>/proc/devices</strong>:注册设备列表.</p>
<blockquote><p>注册设备（register_chrdev_region,allow_chrdev_region）后在此添加一行，包含两列(主设备号，设备名称)。其中的模块名称就是在调用注册函数时，形参中的设备名。</p></blockquote>
<p><span id="more-749"></span></p>
<p>2. <strong>/proc/modules</strong>:模块加载列表.</p>
<blockquote><p>insmod（加载模块）后在此添加一行。包含列(模块名称，模块大小(bytes)，加载数目，模块加载状态，内存偏移(用于debug))。其中模块名就是调用insmod时所使用参数中的设备名，即xx.ko中的xx。<br />
<img src="http://farm8.staticflickr.com/7176/6959302677_3501d00ab6.jpg" alt="proc/modules" />
</p></blockquote>
<p>3. <strong>/sys/module</strong>:添加一个目录.</p>
<blockquote><p>insmod（加载模块）后在此添加一子目录，同2.</p></blockquote>
<p>4. <strong>/dev/*</strong>:设备节点.</p>
<blockquote><p>mknod（创建设备节点）后在此添加一设备文件。名称为mknod的参数名。</p></blockquote>
</blockquote>
<p>四：删除模块</p>
<blockquote><p>使用rmmod xxx或modprobe -r xxx。删除模块后，/proc/devices, /proc/modules, /sys/module 中的记录都会被清除。</p></blockquote>
<p>五：总结</p>
<blockquote><p>为了避免混淆设备和模块名称，尽量在注册函数，插入模块，创建设备文件节点时使用同样的名称。</p></blockquote>
<p>参考文档：<a href="http://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-proc-topfiles.html">Top-level Files within the proc File System</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tuzei.net/2012/03/07/ddandfs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>以太网卡混杂模式与Sniffer程序学习</title>
		<link>http://tuzei.net/2011/11/29/%e4%bb%a5%e5%a4%aa%e7%bd%91%e5%8d%a1%e6%b7%b7%e6%9d%82%e6%a8%a1%e5%bc%8f%e4%b8%8esniffer%e7%a8%8b%e5%ba%8f%e5%ad%a6%e4%b9%a0/</link>
		<comments>http://tuzei.net/2011/11/29/%e4%bb%a5%e5%a4%aa%e7%bd%91%e5%8d%a1%e6%b7%b7%e6%9d%82%e6%a8%a1%e5%bc%8f%e4%b8%8esniffer%e7%a8%8b%e5%ba%8f%e5%ad%a6%e4%b9%a0/#comments</comments>
		<pubDate>Tue, 29 Nov 2011 09:43:33 +0000</pubDate>
		<dc:creator>jaykenduke</dc:creator>
				<category><![CDATA[技术 | 工作]]></category>

		<guid isPermaLink="false">http://tuzei.net/?p=728</guid>
		<description><![CDATA[Wikipedia 混杂模式（Promiscuous Mode）是计算机网络中的术语。是指一台机器的网卡能够接收所有经过它的数据流，而不论其目的地址是否是它。 一般计算机网卡都工作在非混杂模式下，此时网卡只接受来自网络端口的目的地址指向自己的数据。当网卡工作在混杂模式下时，网卡将来自接口的所有数据都捕获并交给相应的驱动程序。网卡的混杂模式一般在网络管理员分析网络数据作为网络故障诊断手段时用到，同时这个模式也被网络黑客利用来作为网络数据窃听的入口。在Liunx操作系统中设置网卡混杂模式，时需要管理员权限。在windows操作系统和Linux操作系统中都有使用混杂模式的抓包工具，比如著名的开源软件wireshark. Linux下手动切换网卡(eth0)为(非)混杂模式。 默认为非混杂模式： ifconfig eth0 -promisc 将eth0置为混杂(promiscuous)： ifconfig eth0 promisc 查看网卡是否混杂： ifconfig eth0 输出若包含PROMISC则说明处于混杂模式。 例： eth0 Link encap:以太网 硬件地址 xx:xx:xx:xx:xx:xx inet 地址:x.x.x.x 广播:x.x.x.x 掩码:x.x.x.x UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 跃点数:1 &#8230; 注： 1. struct ifreq结构定义在/usr/include/net/if.h，用来配置ip地址，激活接口，配置MTU等接口信息的。ifreq包含在ifconf结构中。而ifconf结构通常是用来保存所有接口的信息的。 2. 使用tcmdump监视某个主机设备(端口), 并产生C代码, 并可使用setsockopt绑定filter : $ sudo tcpdump -i wlan0 -dd port xxxx and host xxx.xxx.xxx.xxx [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://zh.wikipedia.org/wiki/%E6%B7%B7%E6%9D%82%E6%A8%A1%E5%BC%8F">Wikipedia</a><br />
<blockquote>混杂模式（Promiscuous Mode）是计算机网络中的术语。是指一台机器的网卡能够接收所有经过它的数据流，而不论其目的地址是否是它。</p>
<p>一般计算机网卡都工作在非混杂模式下，此时网卡只接受来自网络端口的<strong>目的地址指向自己</strong>的数据。当网卡工作在混杂模式下时，网卡将来自接口的<strong>所有数据</strong>都捕获并交给相应的驱动程序。网卡的混杂模式一般在网络管理员分析网络数据作为网络故障诊断手段时用到，同时这个模式也被网络黑客利用来作为网络数据窃听的入口。在Liunx操作系统中设置网卡混杂模式，时需要管理员权限。在windows操作系统和Linux操作系统中都有使用混杂模式的抓包工具，比如著名的开源软件wireshark.</p></blockquote>
<p>Linux下手动切换网卡(eth0)为(非)混杂模式。</p>
<blockquote><p>
默认为非混杂模式：</p>
<blockquote><p>ifconfig eth0 -promisc</p></blockquote>
<p>将eth0置为混杂(promiscuous)：</p>
<blockquote><p>ifconfig eth0 promisc</p></blockquote>
<p>查看网卡是否混杂：</p>
<blockquote><p>ifconfig eth0</p></blockquote>
<p>输出若包含PROMISC则说明处于混杂模式。<br />
例：</p>
<blockquote><p>
eth0    Link encap:以太网  硬件地址 xx:xx:xx:xx:xx:xx<br />
           inet 地址:x.x.x.x  广播:x.x.x.x  掩码:x.x.x.x<br />
           UP BROADCAST RUNNING <strong>PROMISC</strong> MULTICAST  MTU:1500  跃点数:1<br />
           &#8230;
</p></blockquote>
</blockquote>
<p>注：<span id="more-728"></span><br />
       1. struct ifreq结构定义在/usr/include/net/if.h，用来配置ip地址，激活接口，配置MTU等接口信息的。ifreq包含在ifconf结构中。而ifconf结构通常是用来保存所有接口的信息的。</p>
<p>       2. 使用tcmdump监视某个主机设备(端口), 并产生C代码, 并可使用setsockopt绑定filter :</p>
<blockquote><p>$ sudo tcpdump -i wlan0 -dd port xxxx and host xxx.xxx.xxx.xxx </p></blockquote>
<p>       3. 以太网帧结构(42)：Ethernet header(14)&#8212;>Dest Mac(6 bytes)[0-5], Source Mac[6-11]; IP header(20)&#8212;>[12-15]Dest IP(4 bytes), Source IP[16-19]; Tcp/Udp(8); Dest(2    bytes)/source port[20-21,22-23]</p>
<p>       4. IP报文起始为0&#215;45, 即版本(4 bit)与首部长度，占一个字节;</p>
<p>参考资料：<br />
               <a href="http://hi.baidu.com/zkheartboy/blog/item/2dd5207abfbeb8ef2e73b3bf.html">C语言编程来使网卡工作在混杂模式</a><br />
               <a href="http://2006zhouxinfeng.blog.163.com/blog/static/502402162011102532453/"> ioctl和struct ifreq </a><br />
               <a href="http://www.cnblogs.com/jinrize/archive/2009/11/24/1609902.html">Linux下Sniffer程序的实现</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tuzei.net/2011/11/29/%e4%bb%a5%e5%a4%aa%e7%bd%91%e5%8d%a1%e6%b7%b7%e6%9d%82%e6%a8%a1%e5%bc%8f%e4%b8%8esniffer%e7%a8%8b%e5%ba%8f%e5%ad%a6%e4%b9%a0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[魔都日记2]关于目前正在做的和将要做的</title>
		<link>http://tuzei.net/2011/11/02/%e9%ad%94%e9%83%bd%e6%97%a5%e8%ae%b02%e5%85%b3%e4%ba%8e%e7%9b%ae%e5%89%8d%e6%ad%a3%e5%9c%a8%e5%81%9a%e7%9a%84%e5%92%8c%e5%b0%86%e8%a6%81%e5%81%9a%e7%9a%84/</link>
		<comments>http://tuzei.net/2011/11/02/%e9%ad%94%e9%83%bd%e6%97%a5%e8%ae%b02%e5%85%b3%e4%ba%8e%e7%9b%ae%e5%89%8d%e6%ad%a3%e5%9c%a8%e5%81%9a%e7%9a%84%e5%92%8c%e5%b0%86%e8%a6%81%e5%81%9a%e7%9a%84/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 15:55:35 +0000</pubDate>
		<dc:creator>jaykenduke</dc:creator>
				<category><![CDATA[技术 | 工作]]></category>
		<category><![CDATA[生活 | 碎片]]></category>

		<guid isPermaLink="false">http://tuzei.net/?p=702</guid>
		<description><![CDATA[来到魔都的第二周。一切都比较顺利，我们部门主要做大中型交换机的研发，机体板子结构比较复杂，模块区分非常明晰，产品已经发售使用。接下来需要做的就是将板子上跑的vxworks替换成目前比较流行的Linux，说白了就是系统移植方面的东西。最近这两天都是做一些准备工作，需要对LINUX底层的API接口，设备驱动，网络协议，以及VxWORKS与底层硬件交互的驱动进行深入了解。再有就是接触宏观的一些东西，比如板子内部的信息流通，整体的架构，收发报文的流程，抓包及包内数据的具体分析。板子主要有两块NT和LT板，即通常所说的网卡与线卡。整个MDU拿起来很沉，能看到的模块除了上述两个，还有风扇模块，电源模块及trace&#038;debug接口,adsl&#038;vdsl接口等。比较有幸的是直接见到了2u MDU的设计师，就坐在我附近，以后就有得学了。这是我为数不多的几次接触嵌入式系统的研发，比较有挑战性。 看源码有一周多，有很大的收获，架构方面在逐步的成型。还是得努力，多学东西吧。题外话。早上跟会长学了一手，动态的更改MAC地址，由此花费了一上午时间写了个脚本，解决了不少问题。会长看了以后只说搞这行三分技术七分守管理，比较汗颜，我搞的这个也是无耻的暴力使用其他人的网络资源，乖乖的学东西。所谓大道至简，虚怀若古嘛。题外话2：不知道怎的突然就贼想玩玩TWITTER，用ANDROID客户端软件SSHTUNNEL也没什么大的效果，只能求助。题外话3：工作这一年会坚持写下去这个BLOG，当然大多数会写技术相关性的东西，留下一些印记。内容可能五花八门，python,tornado,linux,kernel,c/c++,algorithm. etc。就先这样，睡觉先，明天早起。安。]]></description>
			<content:encoded><![CDATA[<p>来到魔都的第二周。一切都比较顺利，我们部门主要做大中型交换机的研发，机体板子结构比较复杂，模块区分非常明晰，产品已经发售使用。接下来需要做的就是将板子上跑的vxworks替换成目前比较流行的Linux，说白了就是系统移植方面的东西。最近这两天都是做一些准备工作，需要对LINUX底层的API接口，设备驱动，网络协议，以及VxWORKS与底层硬件交互的驱动进行深入了解。再有就是接触宏观的一些东西，比如板子内部的信息流通，整体的架构，收发报文的流程，抓包及包内数据的具体分析。板子主要有两块NT和LT板，即通常所说的网卡与线卡。整个MDU拿起来很沉，能看到的模块除了上述两个，还有风扇模块，电源模块及trace&#038;debug接口,adsl&#038;vdsl接口等。<span id="more-702"></span>比较有幸的是直接见到了2u MDU的设计师，就坐在我附近，以后就有得学了。这是我为数不多的几次接触嵌入式系统的研发，比较有挑战性。</p>
<p>看源码有一周多，有很大的收获，架构方面在逐步的成型。还是得努力，多学东西吧。题外话。早上跟会长学了一手，动态的更改MAC地址，由此花费了一上午时间写了个脚本，解决了不少问题。会长看了以后只说搞这行三分技术七分守管理，比较汗颜，我搞的这个也是无耻的暴力使用其他人的网络资源，乖乖的学东西。所谓大道至简，虚怀若古嘛。题外话2：不知道怎的突然就贼想玩玩TWITTER，用ANDROID客户端软件SSHTUNNEL也没什么大的效果，只能求助。题外话3：工作这一年会坚持写下去这个BLOG，当然大多数会写技术相关性的东西，留下一些印记。内容可能五花八门，python,tornado,linux,kernel,c/c++,algorithm. etc。就先这样，睡觉先，明天早起。安。</p>
]]></content:encoded>
			<wfw:commentRss>http://tuzei.net/2011/11/02/%e9%ad%94%e9%83%bd%e6%97%a5%e8%ae%b02%e5%85%b3%e4%ba%8e%e7%9b%ae%e5%89%8d%e6%ad%a3%e5%9c%a8%e5%81%9a%e7%9a%84%e5%92%8c%e5%b0%86%e8%a6%81%e5%81%9a%e7%9a%84/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>django上传图片问题</title>
		<link>http://tuzei.net/2011/05/30/django%e4%b8%8a%e4%bc%a0%e5%9b%be%e7%89%87%e9%97%ae%e9%a2%98/</link>
		<comments>http://tuzei.net/2011/05/30/django%e4%b8%8a%e4%bc%a0%e5%9b%be%e7%89%87%e9%97%ae%e9%a2%98/#comments</comments>
		<pubDate>Sun, 29 May 2011 16:43:46 +0000</pubDate>
		<dc:creator>jaykenduke</dc:creator>
				<category><![CDATA[技术 | 工作]]></category>
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://tuzei.net/?p=692</guid>
		<description><![CDATA[最近这个在admin上传图片的东西搞的我非常郁闷，求教了很多人，查了很多资料。知道问题出在setting.py中的路径，但是怎么着改都有问题，今晚实在没辙就完全推倒重做，又仔细的分析了一遍media_root,media_url,static_root,static_url,admin_media_prefix。参考帮助文档，终于搞定，mark一下。 > MEDIA_ROOT the directory where you upload media > MEDIA_URL the url where your site media &#8211; css, js, icons etc live > ADMIN_MEDIA_PREFIX the alias to where the admin media lives &#8211; django/contrib/admin/media 设置好setting.py文件后，在urls.py文件中添加一个urlpattern，如下代码： url&#40;r'^media/(?P&#60;path&#62;.*)$', &#160; &#160; &#160; &#160; 'django.views.static.serve', &#160; &#160; &#160; &#160; &#123;'document_root': settings.MEDIA_ROOT&#125; &#160; &#160;&#41;,]]></description>
			<content:encoded><![CDATA[<p>最近这个在admin上传图片的东西搞的我非常郁闷，求教了很多人，查了很多资料。知道问题出在setting.py中的路径，但是怎么着改都有问题，今晚实在没辙就完全推倒重做，又仔细的分析了一遍media_root,media_url,static_root,static_url,admin_media_prefix。参考<a href="https://docs.djangoproject.com/en/1.3/ref/settings/">帮助文档</a>，终于搞定，mark一下。<span id="more-692"></span></p>
<blockquote><p>> MEDIA_ROOT</p>
<p>the directory where you upload media</p>
<p>> MEDIA_URL</p>
<p>the url where your site media &#8211; css, js, icons etc live</p>
<p>> ADMIN_MEDIA_PREFIX</p>
<p>the alias to where the admin media lives &#8211; django/contrib/admin/media </p></blockquote>
<p>设置好setting.py文件后，在urls.py文件中添加一个urlpattern，如下代码：</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">url<span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^media/(?P&lt;path&gt;.*)$'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #483d8b;">'django.views.static.serve'</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: black;">&#123;</span><span style="color: #483d8b;">'document_root'</span>: settings.<span style="color: black;">MEDIA_ROOT</span><span style="color: black;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span></div></div>
<p><!--more--><br />
<img src="http://photo2.bababian.com/upload5/20110530/D8428A43A5222DEB92374F4970927EF9.jpg" alt="setting" /></p>
]]></content:encoded>
			<wfw:commentRss>http://tuzei.net/2011/05/30/django%e4%b8%8a%e4%bc%a0%e5%9b%be%e7%89%87%e9%97%ae%e9%a2%98/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>django学习记录1</title>
		<link>http://tuzei.net/2011/05/29/django%e5%ad%a6%e4%b9%a0%e8%ae%b0%e5%bd%951/</link>
		<comments>http://tuzei.net/2011/05/29/django%e5%ad%a6%e4%b9%a0%e8%ae%b0%e5%bd%951/#comments</comments>
		<pubDate>Sun, 29 May 2011 01:56:45 +0000</pubDate>
		<dc:creator>jaykenduke</dc:creator>
				<category><![CDATA[技术 | 工作]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://tuzei.net/?p=686</guid>
		<description><![CDATA[Django报错UnicodeEncodeError: &#8216;ascii&#8217; codec can&#8217;t encode characters 之解决方法！ how-to: 编码问题。Change the __str__ methods on your models to be __unicode__ methods. Just change the name. Usually, nothing else will be needed. 　 admin.site.root vs admin.site.urls admin.site.root does not exist under Django 1.3 anymore, and you can use the last one instead. &#160;from django.conf.urls.defaults import * &#160;from django.contrib [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Django报错UnicodeEncodeError: &#8216;ascii&#8217; codec can&#8217;t encode characters 之解决方法！</strong><br />
how-to:<br />
编码问题。Change the __str__ methods on your models to be __unicode__ methods. Just change the name. Usually, nothing else will be needed. 　<span id="more-686"></span></p>
<blockquote><p>admin.site.root <strong>vs</strong> admin.site.urls</p></blockquote>
<p>admin.site.root does not exist under Django 1.3 anymore, and you can use the last one instead.</p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp;<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">conf</span>.<span style="color: black;">urls</span>.<span style="color: black;">defaults</span> <span style="color: #ff7700;font-weight:bold;">import</span> *<br />
&nbsp;<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">contrib</span> <span style="color: #ff7700;font-weight:bold;">import</span> admin<br />
&nbsp;admin.<span style="color: black;">autodiscover</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
&nbsp;<br />
&nbsp;urlpatterns <span style="color: #66cc66;">=</span> patterns<span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span><span style="color: #66cc66;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^admin/'</span><span style="color: #66cc66;">,</span> include<span style="color: black;">&#40;</span>admin.<span style="color: #dc143c;">site</span>.<span style="color: black;">urls</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: #66cc66;">,</span><br />
&nbsp;<span style="color: black;">&#41;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://tuzei.net/2011/05/29/django%e5%ad%a6%e4%b9%a0%e8%ae%b0%e5%bd%951/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>从无头单链表中删除节点</title>
		<link>http://tuzei.net/2011/05/14/%e4%bb%8e%e6%97%a0%e5%a4%b4%e5%8d%95%e9%93%be%e8%a1%a8%e4%b8%ad%e5%88%a0%e9%99%a4%e8%8a%82%e7%82%b9/</link>
		<comments>http://tuzei.net/2011/05/14/%e4%bb%8e%e6%97%a0%e5%a4%b4%e5%8d%95%e9%93%be%e8%a1%a8%e4%b8%ad%e5%88%a0%e9%99%a4%e8%8a%82%e7%82%b9/#comments</comments>
		<pubDate>Sat, 14 May 2011 13:59:56 +0000</pubDate>
		<dc:creator>jaykenduke</dc:creator>
				<category><![CDATA[技术 | 工作]]></category>

		<guid isPermaLink="false">http://tuzei.net/?p=682</guid>
		<description><![CDATA[题目： 假设有一个没有头指针的单链表。一个指针指向此单链表中间的一个节点（非第一个节点， 也非最后一个节点）。请将该节点从单链表中删除。 解答： 典型的“狸猫换太子”， 若要删除该节点，正常情况下，应该要知道该节点的前面节点的指针，但是由于单链表中没有头结点，所以无法追溯到该节点前面的那个节点，因此，这里采用了“移花接木”的方法。设该节点为B，下一个节点为C。那么，首先将B节点的内容替换为C节点的内容，然后，将C节点删除，这样就达到了我们的目的。代码如下： pcur->next = pnext->next; pcur->data = pnext->date; delete pnext; via 附录程序via： //考虑删除节点为尾节点 void deleteNode2&#40;Node * pCurrent, Node * head&#41; &#123; &#160; &#160; if&#40;pCurrent != NULL&#41; &#160; &#160; &#123; &#160; &#160; &#160; &#160; if&#40;pCurrent-&#62;next != NULL&#41; &#160; &#160; &#160; &#160; &#123; &#160; &#160; &#160; &#160; &#160; &#160; Node * pTemp = [...]]]></description>
			<content:encoded><![CDATA[<p>题目：<br />
 假设有一个没有头指针的单链表。一个指针指向此单链表中间的一个节点（非第一个节点， 也非最后一个节点）。请将该节点从单链表中删除。<br />
解答：<br />
        典型的“狸猫换太子”， 若要删除该节点，正常情况下，应该要知道该节点的前面节点的指针，但是由于单链表中没有头结点，所以无法追溯到该节点前面的那个节点，因此，这里采用了“移花接木”的方法。设该节点为B，下一个节点为C。那么，首先将B节点的内容替换为C节点的内容，然后，将C节点删除，这样就达到了我们的目的。代码如下：<span id="more-682"></span></p>
<blockquote><p>
pcur->next = pnext->next;</p>
<p>pcur->data = pnext->date;</p>
<p>delete pnext;</p></blockquote>
<p><a href="http://hi.baidu.com/silverxinger/blog/item/be3b0667b776c8710c33fafe.html">via</a><br />
<!--more--><br />
附录程序<a href="http://www.cnblogs.com/kurtwang/archive/2010/09/22/1833050.html">via</a>：</p>
<div class="codecolorer-container c default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">//考虑删除节点为尾节点</span><br />
<span style="color: #993333;">void</span> deleteNode2<span style="color: #009900;">&#40;</span>Node <span style="color: #339933;">*</span> pCurrent<span style="color: #339933;">,</span> Node <span style="color: #339933;">*</span> head<span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>pCurrent <span style="color: #339933;">!=</span> NULL<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>pCurrent<span style="color: #339933;">-&gt;</span>next <span style="color: #339933;">!=</span> NULL<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Node <span style="color: #339933;">*</span> pTemp <span style="color: #339933;">=</span> pCurrent<span style="color: #339933;">-&gt;</span>next<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pCurrent<span style="color: #339933;">-&gt;</span>value <span style="color: #339933;">=</span> pTemp<span style="color: #339933;">-&gt;</span>value<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pCurrent<span style="color: #339933;">-&gt;</span>next <span style="color: #339933;">=</span> pTemp<span style="color: #339933;">-&gt;</span>next<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; delete pTemp<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Node <span style="color: #339933;">*</span> temp <span style="color: #339933;">=</span> head<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span>temp <span style="color: #339933;">!=</span> NULL<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>temp<span style="color: #339933;">-&gt;</span>next <span style="color: #339933;">==</span> pCurrent<span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; delete pCurrent<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp<span style="color: #339933;">-&gt;</span>next <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp <span style="color: #339933;">=</span> temp<span style="color: #339933;">-&gt;</span>next<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009900;">&#125;</span></div></div>
<p>#做Graph相关，使用到，思想来源于编程之美</p>
]]></content:encoded>
			<wfw:commentRss>http://tuzei.net/2011/05/14/%e4%bb%8e%e6%97%a0%e5%a4%b4%e5%8d%95%e9%93%be%e8%a1%a8%e4%b8%ad%e5%88%a0%e9%99%a4%e8%8a%82%e7%82%b9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>define与typedef的区别</title>
		<link>http://tuzei.net/2011/05/12/define%e4%b8%8etypedef%e7%9a%84%e5%8c%ba%e5%88%ab/</link>
		<comments>http://tuzei.net/2011/05/12/define%e4%b8%8etypedef%e7%9a%84%e5%8c%ba%e5%88%ab/#comments</comments>
		<pubDate>Thu, 12 May 2011 01:38:45 +0000</pubDate>
		<dc:creator>jaykenduke</dc:creator>
				<category><![CDATA[技术 | 工作]]></category>

		<guid isPermaLink="false">http://tuzei.net/?p=670</guid>
		<description><![CDATA[简单来讲：#define只是简单的进行了替换,而typedef则是为类型取了个&#8221;别名&#8221; 1) #define是预处理指令，在编译预处理时进行简单的替换，不作正确性检查，不关含义是否正确照样带入，只有在编译已被展开的源程序时才会发现可能的错误并报错。例如： #define PI 3.1415926 程序中的：area=PI*r*r 会替换为3.1415926*r*r 如果你把#define语句中的数字9 写成字母g 预处理也照样带入。 2）typedef是在编译时处理的。它在自己的作用域内给一个已经存在的类型一个别名，但是You cannot use the typedef specifier inside a function definition。 3）typedef int * int_ptr; 与 #define int_ptr int * 作用都是用int_ptr代表 int * ,但是二者不同，正如前面所说 ，#define在预处理 时进行简单的替换，而typedef不是简单替换 ，而是采用如同定义变量的方法那样来声明一种类型。也就是说; //refer to (xzgyb(老达摩)) #define int_ptr int * int_ptr a, b; //相当于int * a, b; 只是简单的宏替换 typedef int* int_ptr; [...]]]></description>
			<content:encoded><![CDATA[<p><strong>简单来讲：#define只是简单的进行了替换,而typedef则是为类型取了个&#8221;别名&#8221;</strong></p>
<p>1) #define是预处理指令，在编译预处理时进行简单的替换，不作正确性检查，不关含义是否正确照样带入，只有在编译已被展开的源程序时才会发现可能的错误并报错。例如：<br />
#define PI 3.1415926<br />
程序中的：area=PI*r*r 会替换为3.1415926*r*r<br />
如果你把#define语句中的数字9 写成字母g 预处理也照样带入。<br />
<span id="more-670"></span><br />
2）typedef是在编译时处理的。它在自己的作用域内给一个已经存在的类型一个别名，但是You cannot use the typedef specifier inside a function definition。</p>
<p>3）typedef int * int_ptr;<br />
与<br />
#define int_ptr int *<br />
作用都是用int_ptr代表 int * ,但是二者不同，正如前面所说 ，#define在预处理 时进行简单的替换，而typedef不是简单替换 ，而是采用如同定义变量的方法那样来声明一种类型。也就是说;</p>
<p>//refer to (xzgyb(老达摩))<br />
#define int_ptr int *<br />
int_ptr a, b; //相当于int * a, b; 只是简单的宏替换</p>
<p>typedef int* int_ptr;<br />
int_ptr a, b; //a, b 都为指向int的指针,typedef为int* 引入了一个新的助记符</p>
<p>//看看结果就知道了</p>
<div class="codecolorer-container cpp default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="cpp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339900;">#include &lt;iostream&gt;</span><br />
<span style="color: #339900;">#include &lt;typeinfo&gt;</span><br />
<span style="color: #0000ff;">using</span> <span style="color: #0000ff;">namespace</span> std<span style="color: #008080;">;</span><br />
<br />
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">typedef</span> <span style="color: #0000ff;">char</span> <span style="color: #000040;">*</span> CHAR<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; CHAR c,d<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #0000ff;">typeid</span><span style="color: #008000;">&#40;</span>c<span style="color: #008000;">&#41;</span>.<span style="color: #007788;">name</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000080;">&lt;&lt;</span> <span style="color: #0000ff;">typeid</span><span style="color: #008000;">&#40;</span>d<span style="color: #008000;">&#41;</span>.<span style="color: #007788;">name</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span><br />
<span style="color: #339900;">#define CH char*</span><br />
&nbsp; &nbsp; CH c1,c2<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #0000ff;">typeid</span><span style="color: #008000;">&#40;</span>c1<span style="color: #008000;">&#41;</span>.<span style="color: #007788;">name</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000080;">&lt;&lt;</span> <span style="color: #0000ff;">typeid</span><span style="color: #008000;">&#40;</span>c2<span style="color: #008000;">&#41;</span>.<span style="color: #007788;">name</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> endl<span style="color: #008080;">;</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>这也说明了为什么下面观点成立<br />
typedef int * pint ;<br />
#define PINT int *</p>
<p>那么：<br />
const pint p ;//p不可更改，但p指向的内容可更改<br />
const PINT p ;//p可更改，但是p指向的内容不可更改。</p>
<p>pint是一种指针类型 const pint p 就是把指针给锁住了 p不可更改<br />
而const PINT p 是const int * p 锁的是指针p所指的对象。</p>
<p>3）也许您已经注意到#define 不是语句 不要在行末加分号，否则 会连分号一块置换。</p>
<p>来源于<a href="http://topic.csdn.net/u/20080401/14/1a5aa568-bea5-43d1-9245-cf555ef8f228.html">csdn</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tuzei.net/2011/05/12/define%e4%b8%8etypedef%e7%9a%84%e5%8c%ba%e5%88%ab/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tree, a program for displaying trees.</title>
		<link>http://tuzei.net/2011/05/04/tree-preprocessor/</link>
		<comments>http://tuzei.net/2011/05/04/tree-preprocessor/#comments</comments>
		<pubDate>Wed, 04 May 2011 13:33:38 +0000</pubDate>
		<dc:creator>jaykenduke</dc:creator>
				<category><![CDATA[技术 | 工作]]></category>

		<guid isPermaLink="false">http://tuzei.net/?p=660</guid>
		<description><![CDATA[The `Tree&#8217; program formats trees for screen display or printing with TeX . The `Tree&#8217; preprocessor For example: Usage: tree &#8220;\tree (S(NP(John))(VP(runs)))&#8221; PS：这个小工具非常好用，看了以后，决定不自己搞了。]]></description>
			<content:encoded><![CDATA[<p>The `Tree&#8217; program formats trees for screen display or printing with TeX .<br />
<a href="http://www.essex.ac.uk/linguistics/external/clmt/latex4ling/trees/tree/">The `Tree&#8217; preprocessor</a></p>
<blockquote><p>For example:</p>
<blockquote><p><strong>Usage: </strong>tree &#8220;\tree (S(NP(John))(VP(runs)))&#8221;</p></blockquote>
<blockquote><p><img src="http://www.essex.ac.uk/linguistics/external/clmt/latex4ling/trees/tree/g1.gif" alt="Ptree" /></p></blockquote>
</blockquote>
<p>PS：这个小工具非常好用，看了以后，决定不自己搞了。</p>
]]></content:encoded>
			<wfw:commentRss>http://tuzei.net/2011/05/04/tree-preprocessor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>统计近期使用过的linux命令详解</title>
		<link>http://tuzei.net/2010/12/07/history-command-in-regex/</link>
		<comments>http://tuzei.net/2010/12/07/history-command-in-regex/#comments</comments>
		<pubDate>Tue, 07 Dec 2010 14:56:51 +0000</pubDate>
		<dc:creator>jaykenduke</dc:creator>
				<category><![CDATA[技术 | 工作]]></category>

		<guid isPermaLink="false">http://tuzei.net/?p=644</guid>
		<description><![CDATA[history &#124; sed &#8220;s#^\s\+[0-9]\+\s\+##g&#8221; &#124; grep -oP &#8220;(?&#60;=^&#124;\&#124;)\w+&#8221;&#124;sort &#124;uniq -c&#124; sort -k1,1nr -k2 用于统计最近使用的linux命令。从rex大神的blog上学来的。以前学过一部分基本的正则，但是看这行还是比较费解。根据rex兄指点，搞了半天文档，基本明白相关正则表达式的用法了。感慨一下，正则表达式真是个牛X的东东，威力无穷啊！谢谢rex兄！ history 目的：从 history 命令中得到最近使用过的linux命令。 sed &#8220;s#^\s\+[0-9]\+\s\+##g&#8221; 目的：删除每行的行号。 解析：#号为分割符，可以自定义为&#8217;/',&#8217;:'等;&#8217;^\s+&#8217;表示一行开始的一个或多个空白符；&#8217;[0-9]\+&#8217;表示一个或多个数字；接下来&#8217;\s\+&#8217;与前面的一致，表示多个空白符；##为分割符号；g﻿为结尾修饰符，在替换区之外作限制修饰作用，这里表示全局含义，与此类似的还有【i,m,g,,,】,via。 grep -oP &#8220;(?&#60;=^&#124;\&#124;)\w+&#8221; 目的：记录每一行中的命令。行首的第一个英文单词，以及管道后面的第一个英文单词，视为命令名称。 解析：零宽断言(?&#60;=exp)表示匹配exp后面的位置，为分组语法。-o表示输出匹配行的非空匹配部分。&#8217;^&#124;\&#124;&#8217;表示行开始或(&#8216;&#124;&#8217;)管道标识符开始的。&#8217;\w+&#8217;表示一个或多个字符，这里位一个英文单词。 sort 目的：将得到的命令列表排序。 uniq -c&#124;sort -k1,1nr -k2 目的：统计每个命令的出现次数，先以次数降序排列，再以命令名称升序排列。 解析：&#8217;k1,1nr&#8217;表示按照第一行降序排列。&#8217;-k2&#8242;默认表示按照第二行升序列，也可写为&#8217;-k2,2n&#8217;。 参考文档： 统计最近用过的linux命令 Sed &#8211; An Introduction and Tutorial Regular Expressions 正则表达式30分钟入门教程 用sort对ip地址排序]]></description>
			<content:encoded><![CDATA[<blockquote><p><em>history | sed &#8220;s#^\s\+[0-9]\+\s\+##g&#8221; | grep -oP &#8220;(?&lt;=^|\|)\w+&#8221;|sort |uniq -c| sort -k1,1nr -k2</em></p></blockquote>
<p>用于统计最近使用的linux命令。从<a href="http://iregex.org">rex</a>大神的blog上学来的。以前学过一部分基本的正则，但是看这行还是比较费解。根据rex兄指点，搞了半天文档，基本明白相关正则表达式的用法了。感慨一下，正则表达式真是个牛X的东东，威力无穷啊！谢谢rex兄！</p>
<blockquote><p>history</p></blockquote>
<p>目的：从 history 命令中得到最近使用过的linux命令。</p>
<blockquote><p><em>sed &#8220;s#^\s\+[0-9]\+\s\+##g&#8221;</em></p></blockquote>
<p>目的：删除每行的行号。<br />
解析：#号为分割符，可以自定义为&#8217;/',&#8217;:'等;&#8217;^\s+&#8217;表示一行开始的一个或多个空白符；&#8217;[0-9]\+&#8217;表示一个或多个数字；接下来&#8217;\s\+&#8217;与前面的一致，表示多个空白符；##为分割符号；g﻿为结尾修饰符，在替换区之外作限制修饰作用，这里表示全局含义，与此类似的还有【i,m,g,,,】,<a href="http://www.zeuux.org/science/learning-regex.cn.html">via</a>。</p>
<blockquote><p><em>grep -oP &#8220;(?&lt;=^|\|)\w+&#8221;</em></p></blockquote>
<p>目的：记录每一行中的命令。行首的第一个英文单词，以及管道后面的第一个英文单词，视为命令名称。<br />
解析：零宽断言(?&lt;=exp)表示匹配exp后面的位置，为分组语法。-o表示输出匹配行的非空匹配部分。&#8217;^|\|&#8217;表示行开始或(&#8216;|&#8217;)管道标识符开始的。&#8217;\w+&#8217;表示一个或多个字符，这里位一个英文单词。</p>
<blockquote><p><em>sort</em></p></blockquote>
<p>目的：将得到的命令列表排序。</p>
<blockquote><p><em>uniq -c|sort -k1,1nr -k2</em></p></blockquote>
<p>目的：统计每个命令的出现次数，先以次数降序排列，再以命令名称升序排列。<br />
解析：&#8217;k1,1nr&#8217;表示按照第一行降序排列。&#8217;-k2&#8242;默认表示按照第二行升序列，也可写为&#8217;-k2,2n&#8217;。</p>
<p>参考文档：<br />
<a href="http://iregex.org/blog/most-frequently-used-linux-commands.html">统计最近用过的linux命令</a><br />
<a href="http://www.grymoire.com/Unix/Sed.html">Sed &#8211; An Introduction and Tutorial</a><br />
<a href="http://www.grymoire.com/Unix/Regular.html">Regular Expressions</a><br />
<a href="http://deerchao.net/tutorials/regex/regex.htm">正则表达式30分钟入门教程</a><br />
<a href="http://hi.baidu.com/technotes/blog/item/4598832f1659ba381e30895d.html">用sort对ip地址排序</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tuzei.net/2010/12/07/history-command-in-regex/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

