大体上参考这里,http://philherlihy.com/unix-domain-sockets-datagram/
改动之后如下
服务端
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <…… 阅读全文
Category Archives: Tech
laravel 分页的一个 bug
先定基调,laravel 是一个好框架
然后,他提供了一个自动分页的,叫 Page,可以自动分页,同时在分页的 RESTful 响应报文中给出上一页下一页的 url,这很好,但是,这个实现是通过 url 的 parma 来达成的,也就是如果你的路径本来是 http://xxx.com/path/to/a/page… /path/to/a/page?page=1,但是,如果你的路径本…… 阅读全文
比较字符串形式的版本号
版本号是一个字符串,主要考虑以下三种用例,点分的个数一致还好,不一致需要注意
#include <boost/algorithm/string.hpp>
#include <algorithm>
#include <vector>
#include <string>
bool version_less_than(std::string str_version_a, std::string str_version_b)
{
std::vec…… 阅读全文
word 交叉引用同时显示标题编号和标题文字
找了一圈,没有看到 word 中有这个功能,本来想着这种问题百度应该有,百度了一圈也没有找到,最后还是 Google 到一个 2005 年的帖子,看这里,http://www.wordbanter.com/show…
Trying to insert a cross reference that includes both the heading number and
the heading text … like “3.2 Contrac…… 阅读全文
条件变量的用法和封装
对条件变量的用法的说明可以见这里,http://www.wuzesheng.com/?p=1668,写的不错,看一个裸写的无封装的用法如下:
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <queue&…… 阅读全文
36 进制
看到同事桌上有一份面试题,有一个 36 进制运算的题目,手贱敲了一下,不调真的不好做啊
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
int convert_36_10(std::string strNum) {
std::reverse(strNum.begin(), strNum.end());
int n = 0;
for (…… 阅读全文
visual studio 配合 boost
visual studio 是写 c++ 最好的 IDE 这是宇宙真理没有什么好讨论了,加上 VAssistX 更是如虎添翼。哪怕是 linux 开发我都要搭一个 windows->linux 的文件自动实时同步环境,然后在 windows 上编码,上 linux 去 make。
但是,问题来了,如何让 visual studio 搭配 boost 呢。
找了一下资料,例如,http://blog.csdn.net/…… 阅读全文
再谈对非阻塞的理解
一般来说,现在大家 epoll 都是搭配着非阻塞 IO 一起用的,要问为什么?大家都这么用的啊,而且异步嘛,非阻塞嘛,很自然嘛
但是,非阻塞 IO 具体是怎么对 send 和 recv 起作用的。一般理解,我们之所以要用非阻塞,是为了避免这种情况:
客户端跟我们 tcp 三次握手完了,我们 listen fd 上得到一个 IN 事件了,然后 acc…… 阅读全文
getdatetimestr
下午写了这么一个函数
char* getdatetimestr() {
static char datetimestr[32] = {0};
static time_t last_update_time = 0;
struct timeval tv = {0};
gettimeofday(&tv, NULL);
time_t nowtime = tv.tv_sec;
if (nowtime != last_update_time) {
last_update_time = now…… 阅读全文
iOS 微信如何收藏动画表情
网上看了一些办法,都不靠谱,实践下来,其实方法如下:
在电脑上登录 Windows 微信(网页版不行)
把要收藏表情的那个网页分享到文件传输助手
在 Windows 上打开网页,把动画表情保存到桌面
从桌面把文件拖入文件助手的聊天窗,发送出去
在手机上收藏,完成
好吧,这明显又是一篇水文,但是没办法,这种文章搜索引擎才…… 阅读全文