Skip to content

Instantly share code, notes, and snippets.

View ehei1's full-sized avatar
πŸ‚

ehei ehei1

πŸ‚
  • Korea
View GitHub Profile
@ehei1
ehei1 / decoding.py
Last active May 8, 2025 08:23
convert euc-kr strings to unicode
with open(input_file_path, 'rb') as f:
buffer = bytearray()
while True:
read_buffer = f.read(1000)
if not read_buffer:
break
buffer += read_buffer
while True:
end = buffer.find(b'\n')
@ehei1
ehei1 / copy_files.py
Created March 8, 2024 08:31
move every 10 files to enumerated folders
import os
import shutil
base_dir =R'C:\Users\ehei2\Downloads\musics'
files = os.listdir(base_dir)
files = sorted(files)
step = 10
for file_idx in range(0, len(files), step):
@ehei1
ehei1 / compare_enum.cpp
Created September 22, 2023 01:03
compare two enums
#include <regex>
template<typename T, T t>
std::string enum_to_string()
{
// if you get __FUNCSIG__ on linux, it's different from Windows
constexpr auto pPattern = R"(__cdecl enum_to_string<[\s\w\:]+,([\s\w]+\:\:)*(\w+)>)";
std::regex regex{ pPattern };
std::cmatch match;
auto pText = __FUNCSIG__;
template<typename>
struct is_array
{
static constexpr bool value = {};
};
template<typename T, size_t SIZE>
struct is_array<T[SIZE]>
{
static constexpr bool value = true;
@ehei1
ehei1 / AnsiToUTF8.cpp
Created June 15, 2023 16:18
convert multibyte to unicode
TEST_METHOD(TestEncoding)
{
constexpr auto ansi = "μš°ν•˜ν•˜ν•˜";
constexpr auto unicode = L"μš°ν•˜ν•˜ν•˜";
auto length = static_cast<int>(strlen(ansi));
auto size = ::MultiByteToWideChar(CP_ACP, {}, ansi, length, {}, {});
std::wstring buffer;
buffer.resize(size);
@ehei1
ehei1 / AtomicityChecker.cpp
Created June 13, 2023 16:40
Simple thread safety checker
class AtomicityChecker
{
public:
AtomicityChecker()
{
if (m_threadId) {
throw std::runtime_error("The other thread intruded during invocation");
}
m_threadId = ::GetCurrentThreadId();
}
@ehei1
ehei1 / toUTF8.cpp
Created June 7, 2023 14:38
How to display multi bytes string for ImGUI
// It can run on Windows only because of CT2W
std::string sTitle{ "ν•˜ν•˜ν•˜" };
auto sName = CT2W( sTitle.c_str() );
auto nNameLength = wcslen( sName );
auto nLength = ImTextCountUtf8BytesFromStr( sName, sName + nNameLength ) + 1;
std::string sBuffer( " ", nLength );
ImTextStrToUtf8( sBuffer.data(), sBuffer.length(), sName, sName + nNameLength );
ImGui::Text( sBuffer.c_str() );
/*
* It converts string to time like YY.MM.DD hh:mm:ss.
* You can omit time string.
*/
FILETIME ConvertToFileTime( LPCWSTR lpszDate )
{
std::wregex regex{ LR"((\d+).(\d+).(\d+)\s?(\d+)?(:\d+)?(:\d+)?)" };
std::wcmatch matches;
if ( !std::regex_match( lpszDate, matches, regex ) ) {
struct Foo
{
int i, j;
bool operator<( int v ) const
{
return this->i < v;
}
bool operator>( int v ) const
/*
simple usage of Slim Reader Writer lock
*/
#include <algorithm>
#include <atomic>
#include <chrono>
#include <format>
#include <iostream>
#include <mutex>
#include <thread>