This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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__; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AtomicityChecker | |
{ | |
public: | |
AtomicityChecker() | |
{ | |
if (m_threadId) { | |
throw std::runtime_error("The other thread intruded during invocation"); | |
} | |
m_threadId = ::GetCurrentThreadId(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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 ) ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Foo | |
{ | |
int i, j; | |
bool operator<( int v ) const | |
{ | |
return this->i < v; | |
} | |
bool operator>( int v ) const |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
simple usage of Slim Reader Writer lock | |
*/ | |
#include <algorithm> | |
#include <atomic> | |
#include <chrono> | |
#include <format> | |
#include <iostream> | |
#include <mutex> | |
#include <thread> |
NewerOlder