Skip to content

Instantly share code, notes, and snippets.

View usagi's full-sized avatar
🍣
Sushi

Usagi Ito usagi

🍣
Sushi
View GitHub Profile
#include <thread>
#include <string>
#include <chrono>
#include <iostream>
int main()
{
bool is_running = true;
auto t = std::thread([](bool& is_running)
#include <boost/thread.hpp>
#include <string>
#include <chrono>
#include <iostream>
int main()
{
bool is_running = true;
auto t = boost::thread([](bool& is_running)
cv::Mat m(480, 640, CV_8UC3);
Magick::Image i(m.cols, m.rows, "BGR", Magick::CharPixel, reinterpret_cast<char*>(m.data));
constexpr int jpeg_quality = 60;
Magick::Blob buffer;
i.magick("JPEG");
i.quality(jpeg_quality);
i.write(&buffer);
cv::Mat m(480, 640, CV_8UC3);
Magick::Image i(m.cols, m.rows, "BGR", Magick::CharPixel, reinterpret_cast<char*>(m.data));
Magick::Blob buffer;
i.compressType(Magick::LZWCompression);
i.magick("TIFF");
i.write(&buffer);
#include <vector>
#include <string>
#include <iostream>
int main(const int number_of_arguments_c, const char* const* const arguments_c)
{
const std::vector<std::string> arguments_cxx(arguments_c + 1, arguments_c + number_of_arguments_c);
std::cerr << arguments_cxx.size() << '\n';
for(const auto& a : arguments_cxx)
std::cerr << a << ' ';
#include <iostream>
#include <cmath>
int main()
{
for(auto n = 0; n < 100; ++n)
{
float t = float(n) / 100;
float f = 2.f;
float a = 4.f * std::floor(t * f) - 2.f * std::floor(2.f * t * f) + 1.f;
#include <memory>
template<class T_derived, class T_base = void>
class enable_shared_from_this_wrap: public T_base
{
public:
std::shared_ptr<T_derived> shared_from_this()
{ return std::static_pointer_cast<T_derived>(T_base::shared_from_this_wrap()); }
std::shared_ptr<T_derived const> shared_from_this() const
@usagi
usagi / test.cxx
Last active August 29, 2015 13:57
how to make: Python3.3 C++ module
// std::cout のためにC++標準ライブラリー iostream を使用。
#include <iostream>
// std::runtime_error のためにC++標準ライブラリー stdexcept を使用。
#include <stdexcept>
// Pythonバインディングのために /usr/include/python3.3/Ptyhon.h を使用。
#include <Python.h>
// C++の無名名前空間で定義するよ
namespace
@usagi
usagi / make_shared.cxx
Created April 7, 2014 06:34
make_shared
#include <iostream>
#include <memory>
#include <stdexcept>
template <class T, class... T_params>
auto make_shared(T_params&&... params) -> std::shared_ptr<T>
{ return std::shared_ptr<T>(new T(params...)); }
class A
{
#include <memory>
template<class T_derived, class T_base = void>
class enable_shared_from_this_wrap: public T_base
{
public:
std::shared_ptr<T_derived> shared_from_this()
{ return std::static_pointer_cast<T_derived>(T_base::shared_from_this_wrap()); }
std::shared_ptr<T_derived const> shared_from_this() const