Skip to content

Instantly share code, notes, and snippets.

View ppLorins's full-sized avatar
🎯
Focusing

arthur ppLorins

🎯
Focusing
  • Tencent
  • ShenZhen,China
View GitHub Profile
@ppLorins
ppLorins / shared_mutex.hpp
Created May 10, 2018 13:26
boost::shared_mutex
class upgrade_mutex
{
typedef boost::mutex mutex_t;
typedef boost::condition_variable cond_t;
typedef unsigned count_t;
mutex_t mut_;
cond_t gate1_;
cond_t gate2_;
count_t state_;
@ppLorins
ppLorins / sample.py
Created May 31, 2018 07:22
demonstrate a pdfrw problem
import os
import pdfrw
INVOICE_TEMPLATE_PATH = 'sample-template.pdf'
INVOICE_OUTPUT_PATH = 'sample-output.pdf'
ANNOT_KEY = '/Annots'
ANNOT_FIELD_KEY = '/T'
ANNOT_VAL_KEY = '/V'
ANNOT_RECT_KEY = '/Rect'
@ppLorins
ppLorins / nanosecond.cc
Last active November 25, 2018 10:17
A std::chrono::nanoseconds issue found under MSVC.
#include <stdio>
#include <chrono>
/* Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24215.1 for x86 */
int main(int argc, char** argv)
{
//auto _nano = std::chrono::nanoseconds(3 * 1000 * 1000 * 1000); //wrong
auto _nano = std::chrono::duration<uint32_t, std::ratio<1, 1000000000>>(3 * 1000 * 1000 * 1000); //right
/*
*
* Copyright 2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
@ppLorins
ppLorins / windows_precision_issue.cc
Created June 12, 2019 16:41
std::chrono::system_clock::now() precision problem under windows .
#include <random>
#include <chrono>
int main(int argc, char** argv){
char sz_time_buf[1024] = { 0 };
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<unsigned long> dis(1,1000);
@ppLorins
ppLorins / subclass_pointer_convert2_parentclass_pointer.cc
Created June 17, 2019 07:52
subclass pointer convert2 parent class pointer issue
#include<iostream>
class CPartialBase {
public:
CPartialBase() {
std::cout << "CPartialBase this:" << this << std::endl;
}
virtual void funcPart() = 0;
@ppLorins
ppLorins / greeter_async_mixed_server.cc
Last active March 20, 2021 00:42
an example for writing an unary and bidi-stream mixed version of c++ async grpc server.
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ppLorins
ppLorins / bidi-server-cus.cc
Created July 18, 2019 07:22
an example for the bidirectional streaming async grpc c++ server.
/*
*
* Copyright 2016, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
@ppLorins
ppLorins / greeter_async_server.cc
Created July 18, 2019 07:23
an example for an unary async grpc c++ server.
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@ppLorins
ppLorins / greeter_proxy_server.cc
Created July 18, 2019 07:34
an example for the proxy async grpc c++ server forwarding requests for unary and bidi stream servers.
/*
*
* Copyright 2015 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*