Skip to content

Instantly share code, notes, and snippets.

View chen3feng's full-sized avatar

CHEN Feng chen3feng

View GitHub Profile
@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) \
@chen3feng
chen3feng / merge_mp3.py
Created February 8, 2024 08:01
Merge MP3 files in archive packages
#!/usr/bin/env python3
import glob
import os
import shutil
import subprocess
import sys
import rarfile
@chen3feng
chen3feng / named_struct.py
Last active December 10, 2020 04:49
NamedStruct, a combinationof struct and namedtuple in python, make code more readable
"""
NamedStruct, a combinationof struct and namedtuple in python, make code more readable.
You can access the fields by name rather than index.
"""
from __future__ import print_function
import struct
from collections import namedtuple
@chen3feng
chen3feng / copy_file_in_zip.py
Last active May 30, 2020 10:40
Copy files inside a zip into another zip file without uncompress it ahead, improve the speed,
#!/usr/bin/env python
"""
Copy files inside a zip into another zip file without uncompress it ahead, improve the speed,
"""
import zipfile
def zipfile_get_entry(source, name):
#!/usr/bin/env python
import os
import sys
import re
import heapq
import subprocess
TOP_N=100
MIN_ALLOC_BYTE=10*1024