一点一滴的积累
东边日出西边雨 · 共 90 篇文章
隐私政策
本应用尊重并保护所有使用服务用户的个人隐私权。为了给您提供更准确、更有个性化的服务,本应用会按照本隐私权政策的规定使用和披露您的个人信息。但本应用将以高度的勤勉、审慎义务对待这些信息。除本隐私权政策另有规定外,在未征得您事先许可的情况下,本应用不会将这些信息对外披露或向第三方提供。本应用会不时更新本隐私权政策。 您在同意本应用服务使用协议之时,即视为您已经同意本隐私权政策全部内容。本隐私权政策属于本应用服务使用协议不可分割的一部分。 1. 适用范围 (a) 在您注册本应用帐号时,您根据本应用要求提供的个人注册信息; (b) 在您使用本应用网络服务,或访问本应用平台网页时,本应用自动接收并记录…
2019-01-20 12:18 · 其他 · 评论(0)
windows下安装c扩展的python模块
在windows下安装c语言写的python模块时,例如: pip install lz4 有时会报错 “Unable to find vcvarsall.bat", 这是由于安装c写的模块时,有个编译的过程,默认会查找vs2008的编译器,如果找不到就会报错,如果系统上安装有vs2008就不会报错。这时如果电脑上安装有vs2010 或者 vs2012,可以在命令行执行以下命令解决: vs2010 SET VS90COMNTOOLS=%VS100COMNTOOLS% vs2012 SET VS90COMNTOOLS=%VS110COMNTOOLS%
2014-03-13 19:46 · python · 评论(0)
c++ vector list map在遍历中删除元素
c++ STL 中的vector, list, map这些数据结构,经常需要在遍历时删除其中的元素,但是又不能直接删除,会出错。 在你调用erase方法删除元素时,erase方法会返回下一个元素的迭代器,利用这一点,可以写这样的代码: for(vector<int>::iterator it=d.begin();it!=d.end(); ) { if(*it==3) { it=d.erase(it); } else { it++; } } 这一点对于vector, list和map都适用。 对于map还可以写成这样 for(vector<int>::iterator it=d.begin()…
2013-05-07 14:47 · c · 评论(0)
装饰器模式Decorator(c++)
相应的代码: #include <iostream> #include <vector> #include <string> using namespace std; // base class class Beverage { public: virtual string getDescription() = 0; virtual float cost() = 0; }; // base class of condiment, also a base decorator class class CondimentDecorator : public Beverage { protected…
2013-04-27 14:59 · 设计模式 · 评论(0)
c++ 构造函数和析构函数调用顺序
#include <iostream> #include <vector> using namespace std; class Organisms { public: Organisms() { cout<<"Organisms constructor"<<endl; } ~Organisms() { cout<<"Organisms distructor"<<endl; } }; class Animal: public Organisms { public: Animal() { cout<<"Animal constructor"<<endl; } ~Animal() { cout<…
2013-04-25 16:54 · c · 评论(0)
epoll高效的原因
epoll高效的原因: 使用内核中断实现,中断后调用处理函数处理,是异步的。 http://blog.chinaunix.net/uid-17299695-id-3059110.html
交换两个数字的值(不用临时变量)
c语言, 有两个int型的数字,怎么样不用临时变量交换两个数字的值? 用如下方法即可: int a = 10; int b = 20; a = a^b; b = a^b; a = a^b; printf("%d %d\n", a, b); result: 20 10 这是为什么呢? 首先得理解“异或操作”, 异或是一种位操作,相同的位异或结果是0, 不同的位异或结果为1. 在第一个 a = a^b后,a的值其实保存了a, b两个变量之间的比较结果,也可以理解为a, b两变量的差异。 这时根据b和保存了差异的变量,可以推导出最初的a变量的值, 就是 b = a^b. 然后再类似的可以推导出b的…
2013-03-10 19:52 · 面试相关 · 评论(0)
shell脚本 查看还有多少天过生日
read -p "Input your birthday(mm-dd):" birth birth=`date +%Y`-$birth date_birth=`date --date $birth +%s` #得到生日的秒值 date_now=`date +%s` #得到当前时间的秒值 internal=$(($date_birth-$date_now)) #计算今日到生日日期的间隔时间 if [ "$internal" -lt "0" ]; then #判断今天的生日是否已过 echo I am sorry. else echo There is $((internal/60/60/24)…
2012-12-14 16:19 · linux系统 · 评论(0)
python 网络随即绑定一个可用的tcp端口
端口写成0就可以,python会查找一个可用的tcp口绑定。 def get_open_port(): import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(("",0)) s.listen(1) port = s.getsockname()[1] s.close() return port
2012-11-29 17:32 · python · 评论(0)
python 得到当前进程的信息(cpu 内存占用等)
可以用这个函数: import commands, os, re def process_info(): pid = os.getpid() res = commands.getstatusoutput('ps aux|grep '+str(pid))[1].split('\n')[0] p = re.compile(r'\s+') l = p.split(res) info = {'user':l[0], 'pid':l[1], 'cpu':l[2], 'mem':l[3], 'vsa':l[4], 'rss':l[5], 'start_time':l[6]} return info
2012-10-19 15:34 · python · 评论(0)
python 获得shell命令的返回值
如果只是简单地执行shell命令,可以这样: import os os.system('ls') 得到shell的输出(不管标准输出或是错误输出) import commands result= commands.getstatusoutput(shellcommand) output= result[1] 但是无法输入信息到shell,subprocess还是要更好用一些,可以和shell交互,因为重定向了stdin, stdout, stderr import subprocess p = subprocess.Popen(['cmd', 'arg'], stdin=subprocess…
2012-10-19 14:42 · python · 评论(0)
python获取网卡的IP地址
用这个函数可以实现功能: import socket import fcntl import struct def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915, struct.pack('256s', ifname[:15]) )[20:24] ) 使用 get_ip_address('eth0') 就可以获得eth0网卡的IP地址
2012-10-12 18:17 · python · 评论(0)
UNIX domain socket传递文件描述符
c版本(UNIX高级编程中的例子): // sendmsg.h #ifndef SENDMSG_H #define SENDMSG_H #include <sys/types.h> int send_fd(int fd, int fd_to_send); int recv_fd(int fd, ssize_t (*userfunc)(int, const void*, size_t)); #endif // semdmsg.c #include "sendmsg.h" #include <sys/socket.h> #include <stdio.h> #include <stdlib.h>…
2012-06-19 18:41 · c · 评论(0)
关于Apache与Nginx的优势比较
转载自: http://www.php100.com/html/itnews/PHPxinwen/2012/0103/9606.html 不断有人跟我说Nginx比Apache好、比Apache快之类。Nginx更主要是作为反向代理,而非Web服务器使用。我翻译过一本关于反向代理的技术书籍,同时精通Apache API开发,对Nginx和Apache的工作原理都略有了解,粗谈一下看法。 不管是Nginx还是Squid这种反向代理,其网络模式都是事件驱动。事件驱动其实是很老的技术,早期的select、poll都是如此。后来基于内核通知的更高级事件机制出现,如libevent里的epoll,使事…
2012-06-18 10:58 · 评论(0)