- 博客(28)
- 问答 (1)
- 收藏
- 关注
原创 控制反转与以来注入
控制反转简单的一段代码如下:<?phpclass Person { public function eat() { $restaurant = new Mcdonald(); echo "I am eating at ".$restaurant->getName()."\n"; } }class Mcdonald {
2016-05-23 23:04:06
485
原创 Component理解
一下是Component小demo。<?phpclass Event { public $name; public $data;}abstract class Component { private static $_events = []; public function on($name, $handler, $data = null) {
2016-05-21 16:02:03
510
原创 mysql php使用
$link = mysql_connect('db11-dev.bj1.haodf.net', 'hdf', 'hdf@haodf.com'); if (!$link) { die('Not connected: '.mysql.error()); } $db_selected = mysql_select
2015-12-25 19:12:38
298
原创 nginx php环境搭建
1. 下载nginx源码编译测试运行是否正常2. 下载php源码编译,测试是否能用3. nginx通过fast-cgi转发请求给php的php-fpm进程进行处理所以确保1)编译nginx时候,fast-cgi启用2)编译php的时候php-fpm启用没有启用则重新编译4. 配置nginx.conf location ~ \.php$ {
2015-12-24 17:20:37
392
原创 Connection reset by peer原因
今天开了100个线程去连接server, read数据的时候出现了,read返回-1的情况,errno的值是104.104应该是 connection reset by peer。网络查询知道, Connection reset by peer的常见原因:1. 服务器的并发连接超过了其承载量, 服务器会将其中一些连接关闭。所以应该是正常情况。
2015-11-19 11:13:56
1723
原创 方便的类成员访问接口
对于含有许多数据成员的类, 通常需要提供数据的set和get接口,下面的代码提供了一种set和get的形式,接口比较简洁:#include #include #include using namespace std;class Person{public:Person(const string& name, int age) :mName
2015-11-04 14:24:36
335
原创 智能指针创建多叉树
参考:http://thispointer.com/shared_ptr-binary-trees-and-the-problem-of-cyclic-references/#include #include #include using namespace std;class Node : public enable_shared_from_this{public: typ
2015-11-04 14:09:08
462
转载 GDB 支持多线程调试
原文:http://stackoverflow.com/questions/2702628/gdb-cannot-find-new-threads-generic-errorQuestions:When I run GDB against a program which loads a .so which is linked to pthreads, GDB reports e
2015-09-10 17:04:45
497
原创 no terminal colors in Linux
export LS_OPTIONS='--color=auto'eval "`dircolors`"alias ls='ls $LS_OPTIONS'
2015-09-02 15:37:57
319
原创 C++ Read a whole File using ifstream
std::ifstream ifs("filename.txt");std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator());Mind the extra parenthesis in the str declaration, it's necessary for correct p
2015-08-17 20:16:55
507
原创 代码格式工具
1) astyle安装方法apt-get install astyle2) indentapt-get install indent
2015-08-17 17:52:57
367
原创 Windows 上使用cmake
1. 安装一款C/C++编译器 例如 VS系列, Mingw系列, Dev-C++系列2. 安装CMake3. 安装make4. 设置好他们的环境变量5. 编写测试文件 hello.cpp#include int main(){ int d; printf("hello world."); scanf("%d", &d); getchar(); re
2015-08-14 11:59:31
314
原创 APR 内存池
#include #include int main(){ apr_pool_t *pool; apr_status rv; char *buf; rv = apr_initialize(); if (rv != APR_SUCCESS) { return -1; } rv = apr_pool_create(&po
2015-08-13 20:27:50
342
原创 用boost::shared_ptr 进行数据管理
我们经常遇到这样的情况, 类A和类B同时需要使用类C这个数据。那么类C这个数据由谁来存储呢?比如:有个Student A, Class C(班级), Student Union SU(学生会), 这个学生A既可能是班级C的一员,也可能是学生会SU的一员。下面是一个demo。#include #include #include #include class Student{p
2015-08-10 18:04:03
393
原创 状态模式
状态模式如下:#include #include class State{public: virtual void handle(const std::string &arg) = 0;};using StatePtr = boost::shared_ptr;class Context{public: void setState(StatePtr sta
2015-07-10 11:24:12
336
原创 回调框架 不知道异步可以用不,在尝试
#include using namespace std;class ITransaction{public: virtual ~ITransaction(){}};class Task{public: virtual int process(ITransaction *) = 0; virtual void doAfterSync(ITransaction *ctx)
2015-07-07 19:43:11
389
原创 Thrift TThread
Thrift TThread的使用[cpp] view plaincopy#include #include #include #include using namespace boost; using namespace apache::thrift::concurrency; c
2015-06-29 18:24:26
487
原创 CMake的CTest方法
参考:http://hahack.com/codes/cmake/Demo目录结构如下:Test/├── add.cpp└── CMakeLists.txtadd.cpp#include #include int main(int argc, char *argv[]){ if (argc != 3) { std::cout << "pa
2015-06-26 17:28:35
12353
1
转载 程序员最常去的网站
转自:http://blog.youkuaiyun.com/u011225629/article/details/46645431
2015-06-26 10:19:05
321
原创 nginx 内存池
nginx内存池测试了一下:#include #include "ngx_config.h"#include "ngx_conf_file.h"#include "nginx.h"#include "ngx_core.h"#include "ngx_string.h"#include "ngx_palloc.h"#include "ngx_array.h"volatile n
2015-06-25 19:02:04
269
原创 右值引用
我们写代码的时候,总会遇到下面的情况:class Obj {};Obj getObj() { Obj obj; // 创建临时变量 // some initialize code for obj return obj; // 返回一个临时变量}int main() { Obj obj = getObj(); // 这里会将返回值赋值给obj}
2015-06-24 16:31:47
273
原创 JsonCpp 使用
test.json{ "name":"huyanjie", "age":25, "peiou":{ "name":"guoran", "age":26 } }#include "json/json.h"#include #include const std::string jsonFile("test.
2015-06-17 10:33:27
265
原创 Thrift TServer
1. poll的使用#include #include #include #include #include #include int main(void) { struct pollfd fds[1]; int timeout_msecs = 10000; int ret; fds[0].fd = 0; fds[0].events =
2015-06-16 11:19:51
294
原创 thrift TProcessor
TProcessor Demo 如下:#include #include class TProcessorEventHandler { public: virtual ~TProcessorEventHandler() {} virtual void processingEvent() {}};class TProc
2015-06-11 18:29:43
865
原创 thrift 继承设计
thrift采用了NVI(Non-Virtual Interface)模式, 我写了一个demo如下: #include #include class Parent { public: void read() { read_virt();
2015-06-11 17:39:22
2332
原创 Thrift 线程池
thrift线程池使用如下:#include #include #include #include #include #include using namespace apache::thrift::concurrency;using namespace apache::thrift::server;class MyTask : public Runnable { p
2015-06-11 17:02:40
4002
转载 二叉树的性质
二叉树具有以下重要性质:性质1 二叉树第i层上的结点数目最多为2i-1(i≥1)。证明:用数学归纳法证明: 归纳基础:i=1时,有2i-1=20=1。因为第1层上只有一个根结点,所以命题成立。 归纳假设:假设对所有的j(1≤jj-1个结点,证明j=i时命题亦成立。 归纳步骤:根据归纳假设,第i-1层上至多有2i-2个结点。由于二叉树的每个结点至多有两个孩
2015-04-24 16:02:03
327
空空如也
这样设计继承有什么好处?
2015-06-10
TA创建的收藏夹 TA关注的收藏夹
TA关注的人