Skip to content

Instantly share code, notes, and snippets.

View marukrap's full-sized avatar
🏠
Working from home

Maru marukrap

🏠
Working from home
  • South Korea
View GitHub Profile
@marukrap
marukrap / Unicode.cpp
Last active January 20, 2022 15:50
Unicode Encoding Conversions (Win32)
// https://msdn.microsoft.com/en-us/magazine/mt763237.aspx
#include <Windows.h>
std::wstring ansiToUtf16(const std::string& ansi)
{
const int utf16Length = MultiByteToWideChar(CP_ACP, MB_COMPOSITE, ansi.data(), ansi.length(), nullptr, 0);
std::wstring utf16(utf16Length, L'\0');
MultiByteToWideChar(CP_ACP, MB_COMPOSITE, ansi.data(), ansi.length(), &utf16[0], utf16Length);
@marukrap
marukrap / Bin2c.cpp
Last active February 20, 2018 16:59
Convert Binary Files to C Arrays
// Usage: drag and drop files on the executable
#include <string>
#include <algorithm> // replace
#include <fstream>
#include <iomanip>
int main(int argc, char* argv[])
{
for (int i = 1; i < argc; ++i)
@marukrap
marukrap / Color.cpp
Last active December 1, 2022 22:18
Simple Color Conversions between RGB and HSL/HSV
// https://en.wikipedia.org/wiki/HSL_and_HSV
#include <SFML/Graphics/Color.hpp>
#include <tuple>
#include <algorithm> // min, max
// HSL/HSV
// H Hue component, range: [0.f, 360.f)
// S Saturation component, range: [0.f, 1.f)