Monday, November 15, 2021

UltraEdit regular expressions

Swap 2 words separated by whitespaces


Find what: (\w+)(\s+)(\w+)
Replace with: $3$2$1


Before:
0x01 HID_USAGE_GENERIC_POINTER
0x02 HID_USAGE_GENERIC_MOUSE
0x04 HID_USAGE_GENERIC_JOYSTICK
0x05 HID_USAGE_GENERIC_GAMEPAD
0x06 HID_USAGE_GENERIC_KEYBOARD
0x07 HID_USAGE_GENERIC_KEYPAD
0x08 HID_USAGE_GENERIC_MULTI_AXIS_CONTROLLER

After:
HID_USAGE_GENERIC_POINTER 0x01
HID_USAGE_GENERIC_MOUSE 0x02
HID_USAGE_GENERIC_JOYSTICK 0x04
HID_USAGE_GENERIC_GAMEPAD 0x05
HID_USAGE_GENERIC_KEYBOARD 0x06
HID_USAGE_GENERIC_KEYPAD 0x07
HID_USAGE_GENERIC_MULTI_AXIS_CONTROLLER 0x08

Monday, April 26, 2021

Keenetic routers

Wednesday, April 14, 2021

Print Raspberry Pi CPU and GPU temperature

cpu1=$(</sys/class/thermal/thermal_zone0/temp)
cpu2=$(echo "scale=1;$cpu1/1000" | bc)

gpu1=$(/opt/vc/bin/vcgencmd measure_temp)
gpu2=$(echo $gpu1 | tr -dc '.,0-9')

echo "$(date +'%d.%m.%Y %H:%M:%S') @ $(hostname)"

echo "CPU: $cpu2"
echo "GPU: $gpu2"

Wednesday, September 16, 2020

Disable Windows Defender Real-time protection from the command line

Why? Because it significantly slows down Visual Studio build process.

PowerShell

Get the current status:

(Get-MpPreference).DisableRealtimeMonitoring

Disable Real-time protection (requires admin rights):

Set-MpPreference -DisableRealtimeMonitoring $true

Command line

Get the current status:

powershell (Get-MpPreference).DisableRealtimeMonitoring

Disable Real-time protection (requires admin rights):

powershell Set-MpPreference -DisableRealtimeMonitoring $true

Wednesday, June 5, 2019

ImageSharp: convert Image to System.Drawing.Bitmap and back

See also on GitHub Gist

namespace Vurdalakov
{
    using System;
    using System.IO;

    using SixLabors.ImageSharp;
    using SixLabors.ImageSharp.Advanced;
    using SixLabors.ImageSharp.Formats.Png;
    using SixLabors.ImageSharp.PixelFormats;

    public static class ImageSharpExtensions
    {
        public static System.Drawing.Bitmap ToBitmap<TPixel>(this Image<TPixel> image) where TPixel : unmanaged, IPixel<TPixel>
        {
            using (var memoryStream = new MemoryStream())
            {
                var imageEncoder = image.GetConfiguration().ImageFormatsManager.FindEncoder(PngFormat.Instance);
                image.Save(memoryStream, imageEncoder);

                memoryStream.Seek(0, SeekOrigin.Begin);

                return new System.Drawing.Bitmap(memoryStream);
            }
        }

        public static Image<TPixel> ToImageSharpImage<TPixel>(this System.Drawing.Bitmap bitmap) where TPixel : unmanaged, IPixel<TPixel>
        {
            using (var memoryStream = new MemoryStream())
            {
                bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Png);

                memoryStream.Seek(0, SeekOrigin.Begin);

                return Image.Load<TPixel>(memoryStream);
            }
        }
    }
}