Skip to content

Instantly share code, notes, and snippets.

@chen3feng
chen3feng / README.md
Last active May 13, 2026 00:58
Merge a Tencent Working merge request via REST API (Python, stdlib only, dry-run by default)

merge_mr.py

A tiny, dependency-free Python script to merge a Tencent Working (腾讯工蜂) merge request from the command line, since the web UI's "Merge" button has no first-class CLI counterpart.

Why

@chen3feng
chen3feng / fix_fullwidth_punct.py
Created April 25, 2026 17:18
Replace full-width (CJK) punctuation with ASCII in Markdown, skipping code blocks and inline code.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Replace full-width (CJK) punctuation with ASCII equivalents in Markdown.
Intended for English Markdown documents that accidentally contain stray
full-width punctuation copy-pasted from a Chinese source, without
disturbing code blocks or inline code spans.
Features
--------
@chen3feng
chen3feng / struct_to_map.go
Created August 28, 2025 02:58
Struct to map in Go
import (
"reflect"
"strings"
"gopkg.in/yaml.v3"
)
// StructToMap converts a struct to a map[string]any recursively.
func StructToMap(s any, tagKey string) map[string]any {
out := make(map[string]any)
import ctypes
import struct
import sys
from ctypes import wintypes
def cpuid(leaf: int, subleaf: int = 0) -> tuple[int, int, int, int]:
# Define VirtualAlloc and VirtualFree
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
@chen3feng
chen3feng / resquota.py
Last active July 11, 2025 02:27
Get CPU and Memory Quota
import os
import glob
import platform
import subprocess
def get_physical_cpu_cores():
plat = platform.system()
if plat == 'Linux':
return get_physical_cpu_cores_linux()
@chen3feng
chen3feng / gdbdasmfilt
Last active June 7, 2024 06:47
GDB Disassembled code filter
#!/bin/bash
sed -E -e "s/^(=>)?\s+0x[a-z0-9]+\s+//g" -e "s/(<\+[0-9]+>:\s+)(\w+\s+)0x[0-9a-f]+ </\1\2</g" "$@"
@echo off
setlocal
rem Check if the script is running with admin privileges
net session >nul 2>&1
if %errorlevel% neq 0 (
echo This script requires administrator privileges. Please run it as an administrator.
goto :END
)
@chen3feng
chen3feng / msvc_weak.cpp
Created March 28, 2024 04:01
Weak symbol in VC
#include <stdio.h>
extern const char * pWeakValue;
static const char * pDefaultWeakValue = "nullptr";
// #pragma comment(linker, "/alternatename:_pWeakValue=_pDefaultWeakValue")
#define DEFINE_WEAK(Type, Name) \
extern Type Name; \
static Type Name##Default; \
__pragma(warning(push)) \
@chen3feng
chen3feng / weak.cpp
Created March 21, 2024 03:20
Weak symbol in MSVC
#include <stdio.h>
#define DEFINE_WEAK_VARIABLE(Type, Name) \
extern "C" Type Name; \
extern "C" Type Name##Default; \
__pragma(comment(linker, "/alternatename:" #Name "=" #Name "Default")) \
extern "C" Type Name##Default \
#define DEFINE_WEAK_FUNCTION(Type, Name, Params) \
extern "C" Type Name Params; \
@chen3feng
chen3feng / has_member.cpp
Created March 8, 2024 07:49
Test a c++ class has member function
#include <iostream>
#include <string>
#include <type_traits>
// Primary template with a static assertion
// for a meaningful error message
// if it ever gets instantiated.
// We could leave it undefined if we didn't care.
#define DEFINE_HAS_METHOD(TraitsName, MethodName) \