对条件变量的用法的说明可以见这里,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 事件了,然后 ac…… 阅读全文
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…… 阅读全文
iOS 微信如何收藏动画表情
网上看了一些办法,都不靠谱,实践下来,其实方法如下:
在电脑上登录 Windows 微信(网页版不行)
把要收藏表情的那个网页分享到文件传输助手
在 Windows 上打开网页,把动画表情保存到桌面
从桌面把文件拖入文件助手的聊天窗,发送出去
在手机上收藏,完成
好吧,这明显又是一篇水文,但是没办法,这种文章搜索引擎…… 阅读全文
std::next_permutation
std 中有一个 next_permutation 的算法,见这里,http://en.cppreference.com/w/c…,这个页面上面有一个实现
template<class BidirIt>
bool next_permutation(BidirIt first, BidirIt last)
{
if (first == last) return false;
BidirIt i = last;
if (first == --i) return false;
…… 阅读全文
Populating Next Right Pointers in Each Node II
来看这个题,https://leetcode.com/problems/…,要求常数空间,想了想,没想到,找了答案,是这样
class Solution {
public:
void connect(TreeLinkNode *root) {
if (!root) {
return;
}
TreeLinkNode dummy(-1);
for (TreeLinkNode *prev = &du…… 阅读全文
Linux 调用 system 函数的注意事项
来看这个代码
#include <stdio.h>
#include <stdlib.h>
int main() {
system("sleep 5 && touch test.txt");
FILE *fp = fopen("test.txt", "r");
if (!fp) {
printf("%m\n");
return -1;
}
fclose(fp)…… 阅读全文
netty 初窥
先说结论,总体感觉很好,比 cpp 上的 nio 框架好。
缘起是一个同学来问 java web 的问题,帮他调了一下,两年没怎么碰过 java web 的东西了,各种生疏,而且在调试的过程中,也再次感觉到 java 这个东西实在不适合做 web,一个是重,ssh 框架一上来就给人压得喘不过气的感觉,新增一个功能,要 spring struts 里面 xm…… 阅读全文