Skip to content

Instantly share code, notes, and snippets.

View coolxv's full-sized avatar
🏠
Working from home

coolxv coolxv

🏠
Working from home
  • Dalian, China
View GitHub Profile
@coolxv
coolxv / box_filter.c
Created October 7, 2024 12:16
obs plugins
#include <obs-module.h>
#include <obs-source.h>
#include <obs.h>
#include <util/platform.h>
#define REG_LIMIT 180
#define GREEN_LIMIT 75
#define BLUE_LIMIT 75
#define CHANNEL_NUM 4
#define DECLARE_HAS_CLASS_MEMBER(NAME) \
template<typename T, typename... Args> \
struct has_member_##NAME { \
template<typename U> \
constexpr static auto check(const void*)-> \
decltype(std::declval<U>().NAME(std::declval<Args>()...), std::true_type()); \
\
template<typename U> \
constexpr static std::false_type check(...); \
\
#include <iostream>
#include <tuple>
// 基本结构:终止递归的空结构
template<typename... Args>
struct MyStruct;
// 递归结构:每次处理一个参数
template<typename First, typename... Rest>
struct MyStruct<First, Rest...> : MyStruct<Rest...> {
#include <iostream>
#include <vector>
#include <memory>
#include <functional> // 用于 std::function
template<typename T>
class CircularQueue {
public:
CircularQueue(size_t capacity)
: capacity_(capacity), front_(0), rear_(0), size_(0) {
@coolxv
coolxv / template.cpp
Created August 30, 2024 07:26 — forked from leopoldcambier/template.cpp
Chaining functions using C++ templates
#include<tuple>
#include<iostream>
#include<string>
// Returns the Tin of the first element
template<typename... Trs>
struct Tin_list
{
using type = typename std::tuple_element<0, std::tuple<Trs...>>::type::Tin_type;
};
#include <iostream>
#include <tuple>
// 基准情况: 展开变量定义
template <typename T>
void defineVariables(T&& value) {
T variable = std::forward<T>(value);
std::cout << "Variable defined: " << variable << std::endl;
}
template<class F1, class... Fs>
struct overload : F1, overload<Fs...>
{
using F1::operator();
using overload<Fs...>::operator();
overload(F1 f1, Fs... fs) : F1(f1), overload<Fs...>(fs...) {}
};
template<class F1>
struct overload<F1> : F1
@coolxv
coolxv / select_function_by_type.cpp
Last active August 22, 2024 12:41
select function by type
#include <iostream>
#include <type_traits>
// 函数模板 - 整数类型的实现
template<typename T>
typename std::enable_if<std::is_integral<T>::value, T>::type
processValue(T value) {
std::cout << "Processing an integer: " << value << std::endl;
return value + 1; // 对整数加1
}
@coolxv
coolxv / convert-time-format-2.cpp
Last active June 6, 2024 14:24
convert 6-Jun-2024 time format to 20240606 time format
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <ctime>
#include <map>
// 函数:将月份缩写转换为数字
int monthToNumber(const std::string& month) {
static std::map<std::string, int> monthMap = {
@coolxv
coolxv / 00_readme.md
Created July 20, 2022 00:56 — forked from p4bl0-/00_readme.md
A complete compiler for a simple language (in less than 150 LoC)

This project is a tiny compiler for a very simple language consisting of boolean expression.

The language has two constants: 1 for true and 0 for false, and 4 logic gates: ! (not), & (and), | (or), and ^ (xor).

It can also use parentheses to manage priorities.

Here is its grammar in BNF format:

expr ::= "0" | "1"