记录学习过程中的点点滴滴
2011年六月
[编程之美]使用最大堆和最小堆来求中位数
六 28th
好久没更新blog,都快荒废了,今天发个算法问题
题目介绍:
输入为不断地数字流,实时显示出当前已经输入的数字序列的中位数
解答:
求中位数的方法很多,对于大数据量最经典是桶的计数方法,但是对于这个问题不适用,因为数据是不断变化的
可以用最大堆和最小堆来解答这个问题:
1.假设当前的中位数为m,其中最大堆维护的是<=m的数字序列,最小堆维护的是>=m的数字序列,但是两个堆都不包含m
2.当新的数字到达时,比如为a,将a与m进行比较,若a<=m 则将其加入到最大堆中,否则将其加入到最小堆中
3.如果此时最小堆和最大堆的元素个数的差值>=2 ,则将m加入到元素个数少的堆中,然后从元素个数多的堆将根节点赋值到m,最后重建两个最大堆和最小堆,返回到2
vim中recording模式详解
六 9th
今天看到这个视频:http://v.youku.com/v_show/id_XODk1NjkyNTI=.html
里面有一段是对某一行进行修改,然后可以将这些修改应用到与这一行类似的其他行,然后就想到了vim中recording模式,今天好好总结学习下。
进入recording模式
在正常状态(正常状态 = !insert状态 && !visual状态)下,按q,再按下一个字母或数字,这个数字代表缓冲区的名字,是键盘操作存储的位置,这时编辑器下方就显示”recording(记录)”字样,然后进行操作,最后按q退出这中模式,这样在这期间进行的操作就保存在缓冲区中了
生效缓冲区的内容
怎样将同样的操作在类似的行上生效呢?
使用@后面加上缓冲区的名字即可
实际例子
在文本区中存在以下内容:
int a; int b; int c; int d;
然后将光标放入到第一行的第一个字符输入以下内容:qm$i=1+1<ESC>q
qm:表示进入recording模式,选择缓冲区m
$i:定位到行尾并进入插入模式
=1+1:表示插入的内容
<ESC>q:返回正常状态,并退出recording模式
最后将光标定位到第二行的行首,输入:@m
以下几行类似操作。
最后文本内容变为:
int a=1+1; int b=1+1; int c=1+1; int d=1+1;
参考资料:http://hi.baidu.com/xiaowp/blog/item/c27b50543bb08a53574e0066.html
SMTP邮件服务器postfix配置与使用
六 1st
最近要帮朋友配置一个SMTP服务器,需求就是每天需要向外发送上百万封邮件,google之,发现postfix邮件服务器比较靠谱, 能够发送外部邮件,于是就选它了
操作系统:CentOS 5 32bit
postfix安装
可以通过源码安装最新的版本,但是为了方便,我直接使用yum安装
sudo yum install postfix
配置文件路径:/etc/postfix/main.cf
postfix启动与停止命令:
sudo /etc/init.d/postfix start sudo /etc/init.d/postfix stop sudo /etc/init.d/postfix restart
postfix日志文件位置:/var/log/maillog
卸载sendmail
检查系统是否安装sendmail:
rpm –qa |grep sendmail
如果存在,卸载之
rpm -e sendmail --nodeps
安装cyrus-sasl-2.1.23
由于在centos 源中不存在,直接通过源码安装cyrus-sasl-2.1.23.tar.gz
下载地址
./configure &&make &&make install
这个软件包的作用就是postfix邮件服务器的认证,因为如果转发外部的邮件,必须使用smtpd_recipient_restrictions选项的值check_relay_domains或者是reject_unauth_destination,二者必须选一个,而relay_damains手工来配置允许的邮件域太麻烦,所以就选用sasl认证
修改sasl配置:/etc/sysconfig/saslauthd为
# Directory in which to place saslauthd's listening socket, pid file, and so # on. This directory must already exist. START=yes SOCKETDIR=/var/run/saslauthd # Mechanism to use when checking passwords. Run "saslauthd -v" to get a list # of which mechanism your installation was compiled with the ablity to use. #MECH="pam" MECHANISMS="pam" #使用linux自身的用户认证 # Additional flags to pass to saslauthd on the command line. See saslauthd(8) # for the list of accepted flags. #FLAGS=
然后重启saslauthd:
sudo /etc/init.d/saslauthd restart
测试saslauthd生效:
/usr/sbin/testsaslauthd -u liyg -p liyangguang
将sasl与postfix结合
在main.cf文件中加入:
#added by liyangguang smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination #smtpd_client_restrictions = permit_sasl_authenticated smtpd_sasl_auth_enable = yes broken_sasl_auth_clients = yes smtpd_sasl_security_options = noanonymous
重启postfix :sudo /etc/init.d/postfix restart。
然后通过foxmail客户端配置smtp服务器地址,测试发送邮件是否成功
参考资料:
http://yahoon.blog.51cto.com/13184/40091
http://www.postfix.org/RESTRICTION_CLASS_README.html
http://publish.it168.com/2006/0221/20060221219401.shtml
近期评论