Skip to content

Instantly share code, notes, and snippets.

@vurdalakov
vurdalakov / GetTimeFormatEx.cs
Last active Apr 13, 2021
Format the current local system time using the preferences set in the regional and language options portion of Control Panel
View GetTimeFormatEx.cs
namespace Vurdalakov
{
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
public static class DateTimeApi
{
public static String GetCurrentTimeString(Boolean shortTime)
@vurdalakov
vurdalakov / QueryDosDevice.cs
Created Mar 31, 2021
Get list of MS-DOS devices and their mappings using QueryDosDevice function
View QueryDosDevice.cs
namespace Vurdalakov
{
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
class Program
{
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
@vurdalakov
vurdalakov / CurrentUser.cs
Created Oct 28, 2020
C#: Does current user have local admin rights
View CurrentUser.cs
namespace Vurdalakov
{
using System;
using System.Security.Principal;
public static class CurrentUser
{
public static Boolean IsAdministrator()
{
using (var windowsIdentity = WindowsIdentity.GetCurrent())
@vurdalakov
vurdalakov / ImageSharpExtensions.cs
Last active May 31, 2021
SixLabors.ImageSharp extensions: convert Image<TPixel> to byte array and System.Drawing.Bitmap etc.
View ImageSharpExtensions.cs
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;
@vurdalakov
vurdalakov / AdobeSdkString.h
Last active Mar 22, 2019
[C++] Helper class for working with ADOBESDK_String
View AdobeSdkString.h
#pragma once
#include <string>
class AdobeSdkString
{
ADOBESDK_StringSuite1* _stringSuite;
ADOBESDK_String _string;
BOOL _dispose;
@vurdalakov
vurdalakov / RemoveTableElementByKey.lua
Created Mar 28, 2018
[Lua] Remove (and return) a table element by its key
View RemoveTableElementByKey.lua
-- 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 / KeyboardLayouts.cs
Created Mar 14, 2018
Working with keyboard layouts on Windows in C# (ActivateKeyboardLayout/GetKeyboardLayout/GetKeyboardLayoutList)
View KeyboardLayouts.cs
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 / Info.lua
Created Mar 8, 2018
Lightroom plugin template
View Info.lua
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 / increment.bat
Last active May 27, 2021
Automatically increment version number in Arduino IDE
View increment.bat
@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 / fileio.h
Created Oct 6, 2016
Read to and write from a binary file
View fileio.h
#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)
{