Skip to content

Instantly share code, notes, and snippets.

View microcai's full-sized avatar

microcai microcai

View GitHub Profile
@microcai
microcai / cfunc
Last active August 29, 2015 14:01
cfunc
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
// insert
namespace trails_detail{
template <typename... T>
std::string bintohexstring(std::string md5bin)
{
typedef boost::hex_from_bin<
boost::archive::iterators::transform_width<std::string::iterator, 4, 8, char>
> hex_from_bin_iterator;
return std::string(hex_from_bin_iterator(md5bin.begin()),
hex_from_bin_iterator(md5bin.end()));
}
/*
* If you think you are smart than the compiler , then you can optimize this code.
* otherwise, just leave it untouched.
*
* the base idea this code is that, simplify the md5 digest Algorithm to calculate only 4byte.
* thus, only 4 basic md5 round is needed.
* after 4 basic md5 round, shift the result and xor itself.
* the the lower 16bits is the peerhash.
*
#pragma once
#include <mutex>
#include <functional>
#include <boost/asio.hpp>
template<typename TimerType, typename T>
class smart_timer
{
@microcai
microcai / cache_map.hpp
Created April 9, 2017 10:42
简单 cache 容器,使用异常处理 cache_miss
#pragma once
#include <tuple>
#include <map>
#include <boost/thread.hpp>
#include <boost/thread/shared_mutex.hpp>
#include <boost/date_time/posix_time/ptime.hpp>
@microcai
microcai / smart_timer.hpp
Last active April 16, 2017 08:01
新的 smart_timer 来啦!
#pragma once
#include <tuple>
#include <mutex>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#pragma once
#include <boost/beast/websocket.hpp>
#include <boost/beast/websocket/ssl.hpp>
struct websocket_stream : boost::noncopyable
{
using wss_socket_t = boost::beast::websocket::stream<boost::asio::ssl::stream<boost::asio::ip::tcp::socket&>>;
@microcai
microcai / gist:19638946cd595bbf2924f37a6f750fd7
Created September 26, 2018 09:21
websocket_stream adopt to wss/ws
#pragma once
#include <boost/noncopyable.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/beast/websocket/ssl.hpp>
struct websocket_stream : boost::noncopyable
#pragma once
#include <boost/noncopyable.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/beast/websocket/ssl.hpp>
struct websocket_stream : boost::noncopyable
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include "url_parser.hpp"
namespace qi = boost::spirit::qi;
BOOST_FUSION_ADAPT_STRUCT(