Skip to content

Instantly share code, notes, and snippets.

View usagi's full-sized avatar
🍣
Sushi

Usagi Ito usagi

🍣
Sushi
View GitHub Profile
@usagi
usagi / file0.txt
Last active February 14, 2017 09:09
C++のちょっとしたアプリでさっと使いやすい簡易ロガーの実装例 ref: http://qiita.com/usagi/items/d4aec8d3f748f4ba9d6a
小さなサンプルアプリ作る
でもまあロガーくらい入れて作りたい
boost::log入れるのめんどくさいしちょっとしたやつ
気づけばいつものロガーコードを書いている
@usagi
usagi / file0.txt
Created February 3, 2017 12:14
picojson::value を bool へ ECMA-262 互換で変換する実装例 ref: http://qiita.com/usagi/items/fe09583b4efe2fe77ead
#pragma once
#include "type.hxx"
namespace usagi::json::picojson
{
static inline auto to_bool( const boolean_type in ) { return in; }
/// @note ECMA-262 NaN: Boolean( 0/0 ) -> false
/// @note ECMA-262 +Inf: Boolean( +1/0 ) -> true
@usagi
usagi / file0.txt
Last active February 3, 2017 08:11
picojson の value, array, object の生成を簡単にするヘルパーライブラリーの実装例 ref: http://qiita.com/usagi/items/fa09b3881979b923e3a6
#pragma once
#include <picojson.h>
#include <string>
namespace usagi::json::picojson
{
using object_type = ::picojson::object;
using array_type = ::picojson::array;
using value_type = ::picojson::value;
@usagi
usagi / file0.txt
Created February 1, 2017 11:41
picojson で JSON-RPC-2.0 を扱う C++ のライブラリー実装 ref: http://qiita.com/usagi/items/27b5fa874496d05a3030
#include <usagi/json/picojson/rpc/jsonrpc20.hxx>
#include <memory>
auto main() -> int
{
using namespace usagi::json::picojson;
using namespace usagi::json::picojson::rpc::jsonrpc20;
server_type s;
@usagi
usagi / file0.txt
Created January 31, 2017 18:19
F# を ubuntu/mono と Visual Studio Code で始めるメモ ref: http://qiita.com/usagi/items/ee8300f897d7b85f6956
sudo apt-get install mono-complete fsharp nuget
@usagi
usagi / file0.txt
Created January 31, 2017 10:17
文字列のパスから picojson::object による階層構造に picojson::value を放り込む例 ref: http://qiita.com/usagi/items/2564e7f660c83793cfc3
/// @brief object_type に対しドット区切りのパスで object_type の階層を必要なら作成しながら辿り末梢の要素の参照を返す
static inline decltype( auto ) make_object_path
( object_type& root_object
, const std::string& dot_separated_path
)
{
// (1) ドット区切りのパス文字列を階層ごとに分離する機能
std::vector< std::string > path;
boost::split( path, dot_separated_path, boost::is_any_of( "." ) );
@usagi
usagi / file0.txt
Last active January 31, 2017 17:42
vscode を ubuntu に .deb で install したら実行ファイルがどこにあるか探して手 symlink を貼る必要があったメモ ref: http://qiita.com/usagi/items/d800457a7ee355d7305d
cd /usr/local/bin
sudo ln -s /usr/share/code/bin/code
@usagi
usagi / file0.txt
Created January 30, 2017 08:45
picojson::value に入った picojson::object のネスト構造をドット区切りのパス文字列で引っ張り出すヘルパー ref: http://qiita.com/usagi/items/da3568d8fa61e4aafede
// 理想: picojson には実装されていないが時折欲しくなる使用例
const auto element_value = root_value.[ "aaa.bbb.ccc" ].as< double >();
// 現実: 毎度こんなに書きたくない
const double element_value
try
{
element_value =
root_value.get< picojson::object >().at( "aaa" )
.get< picojson::object >().at( "bbb" )
@usagi
usagi / file0.txt
Last active January 5, 2017 08:39
LibreSSL と Boost.ASIO.SSL を組み合わせて使う事になった場合に ::SSL_CTX_get_default_passwd_cb_userdata 等複数箇所で翻訳時エラーが生じてしまう場合の応急対処法 ref: http://qiita.com/usagi/items/acee410849ca8f4f9c11
...include/boost/asio/ssl/impl/context.ipp: In destructor 'boost::asio::ssl::context::~context()':
.../include/boost/asio/ssl/impl/context.ipp:232:25: error: '::SSL_CTX_get_default_passwd_cb_userdata' has not been declared
void* cb_userdata = ::SSL_CTX_get_default_passwd_cb_userdata(handle_);
^~
@usagi
usagi / file0.cpp
Last active January 3, 2017 17:39
プラグインシステムを Boost.DLL で簡単に実装する紹介 ref: http://qiita.com/usagi/items/0722550dc5433bd07139
#pragma once
#include <string>
namespace usagi::example::boost_dll
{
class plugin_type
{
public:
virtual auto get_name() const -> std::string;