Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@vurdalakov
vurdalakov / strings.h
Created September 30, 2016 02:26
std::string to std::wstring conversion (and vice versa) using Windows API
#pragma once
#include <windows.h>
#include <string>
inline std::wstring multi2wide(const std::string& str, UINT codePage = CP_THREAD_ACP)
{
if (str.empty())
{
return std::wstring();
@vurdalakov
vurdalakov / strings.h
Created October 6, 2016 08:16
Convert binary array to hex string
#pragma once
#include <windows.h>
#include <string>
// Converts a binary array to a hex string.
inline std::string bin2hex(unsigned char* buffer, int bufferSize)
{
std::string hex;
hex.reserve(bufferSize * 2 + 1);
@vurdalakov
vurdalakov / strings.h
Created October 6, 2016 08:18
Convert hex string to binary array
#pragma once
#include <windows.h>
#include <string>
// Helper functuion used by hex2bin() function.
inline int hex2byte(char c)
{
if ((c >= '0') && (c <= '9'))
{
@vurdalakov
vurdalakov / fileio.h
Created October 6, 2016 08:20
Read to and write from a binary file
#include <stdio.h>
// Reads binary file and returns its content in a byte array.
// NOTE: it's caller responsibility to free returned array with "delete[]".
inline unsigned char* readFile(const char* fileName, long* fileSizeToReturn)
{
// open file
FILE* file = fopen(fileName, "rb");
if (NULL == file)
{
@vurdalakov
vurdalakov / increment.bat
Last active January 9, 2022 20:13
Automatically increment version number in Arduino IDE
@echo off
echo ----------------------------------------------- increment.bat script -----------------------------------------------
rem ========================================================================================
rem == This script automatically increments build number in "version.h" file.
rem == Instructions and more information:
rem == http://codeblog.vurdalakov.net/2017/04/autoincrement-build-number-in-arduino-ide.html
rem ========================================================================================
setlocal
@vurdalakov
vurdalakov / Info.lua
Created March 8, 2018 09:27
Lightroom plugin template
return {
LrSdkVersion = 6.0,
LrSdkMinimumVersion = 6.0,
LrToolkitIdentifier = 'net.vurdalakov.lightroomplugintemplate',
LrPluginName = 'Lightroom Plugin Template',
LrExportMenuItems = {
title = "Show Lightroom &version",
file = "LightroomPluginTemplate.lua",
enabledWhen = "photosSelected"
}
@vurdalakov
vurdalakov / KeyboardLayouts.cs
Created March 14, 2018 14:27
Working with keyboard layouts on Windows in C# (ActivateKeyboardLayout/GetKeyboardLayout/GetKeyboardLayoutList)
namespace Vurdalakov
{
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.InteropServices;
public class KeyboardLayout
@vurdalakov
vurdalakov / RemoveTableElementByKey.lua
Created March 28, 2018 06:42
[Lua] Remove (and return) a table element by its key
-- Removes (and returns) a table element by its key, moving down other elements to close space and decrementing the size of the array
function table.removeKey(table, key)
local element = table[key]
table[key] = nil
return element
end
-- Test
printf = function(s, ...) return io.write(s:format(...)) end
@vurdalakov
vurdalakov / AdobeSdkString.h
Last active March 22, 2019 07:01
[C++] Helper class for working with ADOBESDK_String
#pragma once
#include <string>
class AdobeSdkString
{
ADOBESDK_StringSuite1* _stringSuite;
ADOBESDK_String _string;
BOOL _dispose;
@vurdalakov
vurdalakov / ImageSharpExtensions.cs
Last active May 20, 2023 11:18
SixLabors.ImageSharp extensions: convert Image<TPixel> to byte array and System.Drawing.Bitmap etc.
namespace Vurdalakov
{
using System;
using System.IO;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.PixelFormats;