Skip to content

Instantly share code, notes, and snippets.

@lingxd
lingxd / lam2fp.cpp
Created June 14, 2023 09:55 — forked from supplient/lam2fp.cpp
C++ lambda expression => C-style function pointer
// Source: https://stackoverflow.com/a/48368508/17132546
// Entry template
// extract the lambda's operaor() function signature
template <class F, class T=F>
struct lambda_traits: lambda_traits<decltype(&std::remove_reference<F>::type::operator()), F>
{};
// For mutable lambda, See https://en.cppreference.com/w/cpp/language/lambda
// mutable lambda's operator() is not const,
@lingxd
lingxd / enableNetworkSinker.cmake
Last active October 17, 2022 08:32 — forked from EvanLyu732/enableNetworkSinker.cmake
spdlog.hpp.in corresponding cmake macro
# Parameter:
# LOG MODULE: folder name
# BIND_PORT: network sinker register port
# SEND_PORT: network sinker publish port
macro(enable_logging LOG_MODULE BIND_PORT SEND_PORT)
if(NOT spdlog_FOUND)
find_package(spdlog REQUIRED)
endif()
if(NOT Boost_FOUND)
@lingxd
lingxd / .clang-format
Last active December 1, 2023 10:31
cpp format
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -4 # -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
@lingxd
lingxd / .config
Created August 16, 2022 08:38
~/.config/terminator/config
[global_config]
focus = system
title_transmit_bg_color = "#d30102"
suppress_multiple_term_dialog = True
[keybindings]
[profiles]
[[default]]
background_color = "#2D2D2D"
background_darkness = 0.85
cursor_color = "#2D2D2D"
@lingxd
lingxd / .c
Created August 9, 2022 07:06
capture_raw_frames.c
#include <errno.h>
#include <fcntl.h>
#include <linux/videodev2.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <opencv2/core/core.hpp>
@lingxd
lingxd / to_base64.cpp
Created June 8, 2022 09:18
C++ to base64
#include <boost/archive/iterators/binary_from_base64.hpp>
#include <boost/archive/iterators/base64_from_binary.hpp>
#include <boost/archive/iterators/transform_width.hpp>
#include <utility>
#include <memory>
#include <string>
#include <vector>
std::string to_base64(const std::vector<uint8_t>& buffer) {
@lingxd
lingxd / delete_log.sh
Created April 22, 2022 08:38
Linux根据磁盘空间占用情况进行清空固定的日志
#!bin/bash
disk_use=`df -h / | head -2 | tail -1 | awk -F" " '{print $5}' | awk -F% '{print $1}'`
if [ $disk_use -gt 80 ]
then
# Delete log files older than 3 days
find /home/hokori/logs/ -mtime +3 -type d -exec rm -rf {} \;
else
# Delete log files older than 7 days