Skip to content

Instantly share code, notes, and snippets.

View CarterLi's full-sized avatar
😀

Carter Li CarterLi

😀
  • PRC
  • 15:20 (UTC +08:00)
View GitHub Profile
@CarterLi
CarterLi / HighRes_WaitForSingleObject.c
Created July 26, 2026 02:28
HighRes_WaitForSingleObject
/**
* @brief 高精度等待单个对象
* @param hTarget 目标对象 (如 Event, Semaphore)
* @param hHRTimer 预先创建的高分辨率 Waitable Timer (用于复用,避免频繁创建 Handle)
* @param timeout_ms 超时时间 (毫秒)
* @return WAIT_OBJECT_0 (目标触发) 或 WAIT_TIMEOUT (超时)
*/
DWORD HighRes_WaitForSingleObject(HANDLE hTarget, HANDLE hHRTimer, DWORD timeout_ms) {
// 1. 设置高分辨率 Timer (负值表示相对时间,单位 100ns)
// 调用 SetWaitableTimer 会自动取消之前的倒计时,并将 Timer 置为 Non-Signaled 状态
@CarterLi
CarterLi / opaque-struct.md
Created May 29, 2025 07:25
Opaque Structs and ABI Compatibility

Modifying members of an opaque struct (reordering, removing, etc.) doesn't break the Application Binary Interface (ABI), which is crucial for maintaining forward compatibility.

The Problem: Non-Opaque Structs

Consider this non-opaque struct definition:

typedef struct MyStruct {
    int i;     // 4 bytes
    float f;   // 4 bytes
#include <unistd.h>
#include <stdbool.h>
#include <assert.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/wait.h>
#include <sys/poll.h>
@CarterLi
CarterLi / MediaInfo.cpp
Last active June 10, 2024 11:25
GlobalSystemMediaTransportControlsSessionManager
#include <winrt/windows.media.control.h>
#include <winrt/windows.media.playback.h>
#include <winrt/Windows.Foundation.h>
#include <stdio.h>
int main()
{
using namespace winrt::Windows::Media;
setlocale(LC_ALL, ".UTF8");
const str = ` -h, --help <?command>: Show this message, or help for a specific command
-v, --version: Show the version of fastfetch
--list-config-paths: List search paths of config files
--list-data-paths: List search paths of presets and logos
--list-logos: List available logos
--list-modules: List available modules
--list-presets: List presets fastfetch knows about; they can be loaded with --load-config (+)
--list-features: List the supported features fastfetch was compiled with (mainly for development)
--print-logos: Print available logos
--print-config-system: Print the default system config
@CarterLi
CarterLi / pipewire.c
Last active October 13, 2023 03:14
Pipewire: enum audio devices
// -lpipewire-0.3
#include <common/library.h>
#include <pipewire/pipewire.h>
#include <util/stringUtils.h>
struct roundtrip_data {
int pending;
struct pw_main_loop *loop;
@CarterLi
CarterLi / init.vim
Created October 29, 2021 15:53
nvimrc
if &shell =~# 'fish$'
set shell=sh
endif
set termguicolors
call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-sensible'
Plug 'mhinz/vim-startify'
Plug 'lambdalisue/battery.vim'
@CarterLi
CarterLi / counter-animation.md
Last active September 23, 2020 08:22
Counter Animation Using Pure CSS
@CarterLi
CarterLi / test_signalfd.c
Last active May 19, 2022 14:07
A simple test case for liburing, and a working example for epoll
#include <liburing.h>
#include <libaio.h>
#include <unistd.h>
#include <sys/signalfd.h>
#include <sys/epoll.h>
#include <sys/poll.h>
#include <stdio.h>
int setup_signal() {
sigset_t mask;