自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(26)
  • 资源 (1)
  • 收藏
  • 关注

原创 关于sigsetjmp和siglongjmp

在CSAPP上看到的例子:#include#include#include #includesigjmp_buf buf;void handler(int sig){ std::cout << "hi\n"; siglongjmp(buf, 3);}int main(){ signal(SIGINT, handler); if(!sigs

2015-09-26 23:44:55 418

原创 python修饰器

看了一下flask,发现不知python的修饰器是啥直接上代码:#coding:utf-8import __main__def dec(param): print(type(param)) print(str(param)) param("on dec") return param@decdef foo(str): print(st

2015-08-16 22:03:09 637

原创 关于c++析构函数

测试了一下c++的析构函数:#include #include#include#includeusing namespace std;using namespace boost::posix_time;time_duration td = seconds(4); //01:00:01class A{public: A(){ } ~A(){

2015-08-15 22:50:57 306

原创 写了个异步日志

主要实现:简单的异步日志,工作线程只需把日志消息写入缓冲,不必阻塞与耗时的IO操作,由一个背景线程专门负责IO操作。采用的数据结构,前端为双缓冲区,后端为BlockingQueue,缓冲区的初始化和析构都由背景线程负责,两块缓冲交替使用。大致的逻辑是:前端使用两块缓冲A和B,A为写缓冲,B为预备缓冲,当写满了A,则交换A和B,并通知背景线程来走B。背景线程接到前端线程的通知,被唤醒,取

2015-08-07 07:02:58 1358

原创 分治和自顶向下动态规划算法

Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are+, - and *.Example 1I

2015-08-03 23:11:47 808

原创 Merge k Sorted Lists

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity./** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *

2015-07-28 23:25:35 342

原创 Basic Calculator II

Implement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces. The integer division should

2015-07-19 22:55:30 407

原创 二叉树中序遍历(迭代)

Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the BST.Note: next() and

2015-07-11 00:35:19 347

原创 一个JAVA面试题

具体题目不记得了,大概实现:多线程中对某个共享的数据进行修改,保证线程安全,用内部类隐藏这些操作。package jav;import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;import java.util.concurrent.locks.Lock;import java

2015-06-01 21:09:59 361

原创 JAVA遍历目录

/*java实现了遍历文件和目录,文件过滤器,广度优先和深度优先两个版本*/package jav; import java.io.File;import java.io.FilenameFilter;import java.nio.channels.NonWritableChannelException;import java.util.*;import java.util.

2015-05-30 10:22:38 745

原创 写了个小爬虫

from mysql import connectorimport hashlib from _codecs import encodeclass Quercy(object): def __init__(self,mysqlDB ='crawler',mysqlUser='root'): self.db=connector.Connect(db=mysqlDB,

2015-05-17 22:51:44 271

原创 python twisted试用

reactor模式一个关键是当某个事件出发某个方法时,怎么正确的调用对应的处理函数。另一个问题是,twisted框架中,总是有事件驱动某个方法,即使总是被动的“被调用”,主动调用某个方法的入口应该在哪里?这两个问题很困扰,反复研究不官方文档,找到了些眉目。对比boost asio的proactor 模式,proactor总是主动的调用某个方法,然后注册一个回调处理函数,当这个方法执行完毕,就回

2015-05-10 20:20:22 384

原创 有向无环图的拓扑排序

有了之前实现的深度优先算法,可以直接给出有向无环图的拓扑排序。结果就是深度优先排序中,最后完成的要排在前面。Vertex是之前实现的from vertex import Vertexfrom collections import dequeclass Graph(object): def __init__(self): #Adjs邻接表字

2015-05-03 22:28:51 860

原创 深度优先

深度遍历下面的图,打印结果,有了之前实现的广度优先的两个类,修该一下便得出结果,顶点类,finish是遍历完成时间,深度deep则是发现时间class Vertex(object): time = 0#时间截 def __init__(self,Name = 'unNamed',Deep = 0,Color = "white",Parent = N

2015-05-03 16:28:18 526

原创 广度优先

源点是S,求这个图深度优先遍历的结果顶点类:class Vertex(object): def __init__(self,Name = 'unNamed',Deep = 0,Color = "white",Parent = None): self.name = Name self.deep = Deep self.color =

2015-05-03 14:30:17 478

原创 动态规划最长递增子序列问题

需要求解的序列是lineIncreasingLine (line[i])表示前 i 个 最大递增子序列。递归关系式:1。当 i = 0 时,最长递增序列就是 单个元素line[0]2。当0  length - 1)  时分两种情况:      a, 如果 line[i]  >= max (IncreasingLine (line[i -1]))时,则表示当前元素属于最长

2015-05-02 10:43:32 285

原创 最长公共子序列问题

def lcs_length(x,y): i = len(x) j = len(y) if (i == 0 or j ==0): return 0,[] if(x[i-1] == y[j-1]): l,result = lcs_length(x[:-1],y[:-1]) result.append(x

2015-05-02 02:31:36 316

原创 Message_edit邮箱发送模块

简单介绍一个几个核心类:1.smtp和pop3:是之前发过的,这次对客户隐藏了基于BOOST::ASIO这个事实,由同步阻塞改成异步IO,内部加入了超时功能(每条指令设置4秒超时,为了省事没有开放接口)2.message类和他的子类.基类是message,实现了大部份公用的接口,比如加信头,设置邮件正文内容,设置字符和编码等操作.3

2015-05-01 03:24:59 771

原创 smtp version:2

重新实现了一下smtp,加入一些错误检查,可以发送附件.头文件:#ifndef SMTP_H#define SMTP_H#include#include#include#include#include"boost/asio.hpp"#include"boost/format.hpp"#include#include"logging.h"#include"MIM

2015-04-07 21:31:35 671

原创 基于asio实现pop3的几个指令

//测试#include#include#includeusing namespace std;using namespace email;int main(){ try{ io_service i; pop3 p(i,"pop.126.com"); p.Set_DebugLevel (true); p

2015-04-06 01:40:16 397

原创 优先队列实现

先上测试:#include#include#include#include#include#include"max_heap.h"#include"boost/progress.hpp"using namespace std;fstream output("log.log" , fstream::out);//生成1000个随机数,插入,void test1()

2015-04-04 17:40:48 466

原创 python的email模块

在Python官网上看到这个例子import smtplibfrom email.mime.text import MIMETextfrom email.mime.image import MIMEImagefrom email.mime.multipart import MIMEMultipartmsg = MIMEMultipart()msg['Subject'] = '

2015-03-31 22:42:38 2519

原创 用socket(asio)实现了smtp的几个简单的指令

测试主程序#include #include#include"logging.h"#include"smtplib.h"using namespace std;using namespace boost::asio;using namespace logging;using namespace smtplib;int main(){ try{

2015-03-29 20:05:46 644

原创 重新写了一个简单的日志类

之前写的了个日志类,感觉写得比较啰嗦,重新写一个比较简单的,功能跟之前差不多.#ifndef LOGGING#define LOGGING#include#include#include#include#includenamespace logging {static const long long MAXSIZE = 1024*1024; //最大尺寸using

2015-03-29 01:35:34 352

原创 python的__getattr__方法

#wrpme包装类class wrapme: def __init__(self,obj): self.__data = obj def get(self): return self.__data def __repr__(self): return str(self) def __str__(self):

2015-03-15 21:05:51 364

原创 asio测试

测试了一下boost的异步io.客户端::分出100个线程,每一个都向服务发出connect,连接成功就打印一条消息。服务器端:主线程调用async_accept,handler函数先调用一个async_accept以接收新的请求。然后就去干自己的事了(sleep几秒)服务器:#include#include#includeusing namespace std;

2015-03-04 22:04:06 504

C++编程规范101条规则、准则最佳实践

C++编程规范101条规则、准则最佳实践

2015-11-14

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除