Skip to content

Instantly share code, notes, and snippets.

View microcai's full-sized avatar

microcai microcai

View GitHub Profile
@microcai
microcai / easy_http.cpp
Created September 4, 2019 14:15
Boost.spirit based URL parser, and Boost.Beast based HTTP/HTTPS client
#include <iostream>
#include <optional>
#include <variant>
#include <boost/beast.hpp>
#include <boost/asio/ssl/stream.hpp>
#include <boost/asio/ssl/rfc2818_verification.hpp>
#include "easyhttp/easyhttp.hpp"
#include "./url_parser.hpp"
@microcai
microcai / easy_http.cpp
Created September 4, 2019 14:03
HTTP/HTTPS beast wrapper
#include <iostream>
#include <optional>
#include <variant>
#include <boost/beast.hpp>
#include <boost/asio/ssl/stream.hpp>
#include <boost/asio/ssl/rfc2818_verification.hpp>
#include "easyhttp/easyhttp.hpp"
#include "./url_parser.hpp"
std::string easyhttp::sync::post(std::string post_url, std::string post_content, std::string content_type)
{
try
{
auto url = parse_url(post_url);
boost::asio::io_context io;
boost::asio::ssl::context ssl_ctx(boost::asio::ssl::context::sslv23);
ssl_ctx.set_default_verify_paths();
#include <string>
#if defined(_MSC_VER) && _MSC_VER < 1920
#include <stdlib.h>
#define strtoll _strtoi64
#endif
namespace Traits{
template<int digits>
@microcai
microcai / decimal.hpp
Created May 30, 2019 08:08
templated decimal
#include <string>
namespace Traits{
template<int>
struct ScaleTraits;
template<>
struct ScaleTraits<4>
@microcai
microcai / decimal.hpp
Created May 30, 2019 07:49
c++03 compatable
#include <string>
class decimal
{
long long fixed_float;
private:
void from_string(const std::string& string_reprent)
{
class decimal
{
long long fixed_float;
public:
decimal() : fixed_float(0) {}
decimal(int i) : fixed_float(i * 10000) {}
decimal(unsigned i) : fixed_float(i * 10000) {}
decimal(long i) : fixed_float(i * 10000) {}
decimal(unsigned long i) : fixed_float(i * 10000) {}
#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(
@microcai
microcai / url_parser.cpp
Created December 13, 2018 09:38
use boost.spirit to parse url
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>
struct KV
{
std::string k;
std::string v;
};
#pragma once
#include <boost/noncopyable.hpp>
#include <boost/beast/websocket.hpp>
#include <boost/beast/websocket/ssl.hpp>
struct websocket_stream : boost::noncopyable