Skip to content

Instantly share code, notes, and snippets.

View rosasurfer's full-sized avatar
💭
a Foo walks into a bar...

Peter Walther rosasurfer

💭
a Foo walks into a bar...
View GitHub Profile
@rosasurfer
rosasurfer / string-conversion.cpp
Last active March 23, 2025 11:03
Encoding conversion in C++
// Convert a UTF-16 string to an ANSI string.
std::string utf16ToAnsi(const std::wstring &wstr) {
size_type length = wstr.size();
int bufSize = WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, &wstr[0], length, NULL, 0, NULL, NULL);
std::string strTo(bufSize + 1, 0);
WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK, &wstr[0], length, &strTo[0], bufSize, NULL, NULL);
return strTo;
}
// Convert a UTF-16 string to an UTF-8 string.
@rosasurfer
rosasurfer / DateTimeConversionAndStrfTime.cpp
Created August 7, 2022 08:01 — forked from t-mat/DateTimeConversionAndStrfTime.cpp
WIN32 : Date/Time conversion and strftime
#include <windows.h>
#include <time.h>
#include <stdio.h>
#include <stdint.h>
// http://www.programmingforums.org/post45492.html
static const int64_t EPOCH_DIFF = 0x019DB1DED53E8000LL; // 116444736000000000 nsecs
static const int RATE_DIFF = 10000000; // 100 nsecs
time_t tmToUnixTime(const struct tm& stm) {
#include <SDKDDKVer.h>
#include <Windows.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
int shmem_size = 16; // 16byte
HANDLE shmem = INVALID_HANDLE_VALUE;
HANDLE mutex = INVALID_HANDLE_VALUE;
@rosasurfer
rosasurfer / ca.md
Created December 19, 2021 09:26 — forked from soarez/ca.md
How to setup your own CA with OpenSSL

How to setup your own CA with OpenSSL

For educational reasons I've decided to create my own CA. Here is what I learned.

First things first

Lets get some context first.