Skip to content

Instantly share code, notes, and snippets.

@odalet
odalet / GetBitmapFromHBitmap.cs
Created February 12, 2022 16:28
HBitmap -> WPF BitmapSource -> Avalonia Bitmap
// First attempt
public static Bitmap GetBitmapFromHBitmap_1(IntPtr nativeHBitmap)
{
var bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(
nativeHBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
// There were missing parentheses here (they are important because this is integer arithmetic.
// Also worth noting, the code below only supports 32bpp images. In this case, stride
// is always equal to width, so a micro-optim would be to not compute the stride.
var stride = 4 * ((bitmapSource.PixelWidth * bitmapSource.Format.BitsPerPixel + 31) / 32);
@odalet
odalet / RoundedRectangleExtension.cs
Last active January 23, 2022 15:33
Create a rounded rectangle path with ImageSharp
#if !IMAGESHARP_V2
using System;
using System.Collections.Generic;
using System.Numerics;
#endif
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing;
namespace RoundedRectangleTest
{
using System;
using System.Runtime.InteropServices;
// https://stackoverflow.com/questions/66002667/pinvoking-user32-dll-setwindowcompositionattribute-via-powershell
public static class NativeMethods
{
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
@odalet
odalet / LambdaTricks.cs
Last active July 3, 2020 09:15
Lambda Tricks
using System;
using System.Linq;
namespace Rextester
{
// See https://csharp.2000things.com/tag/captured-variable/
internal static class Program
{
public static void Main(string[] args)
{
@odalet
odalet / sync_docker_time.ps1
Last active April 8, 2020 08:37 — forked from FilipChalupa/sync_docker_time.ps1
Synchronize your Docker date/time with the host clock - Mitigates https://github.com/docker/for-win/issues/4526
# NB: "Time Synchronization" is "Synchronisation date/heure" in French
$principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
if (-Not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host "Elevated privileges are required."
Start-Process -FilePath "powershell" -ArgumentList "$('-File ""')$(Get-Location)$('\')$($MyInvocation.MyCommand.Name)$('""')" -Verb runAs
exit
}
Write-Host "--- Synchronizing your docker time ---"
@odalet
odalet / gist:d32560f89f0c1a5c9ad1
Created January 17, 2016 19:05 — forked from lontivero/gist:593fc51f1208555112e0
Generates Markdown from VS XML documentation file
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
namespace GithubWikiDoc
{
@odalet
odalet / TestInternedStrings.cs
Created July 22, 2015 06:51
Demonstrates compile-time string constants are interned in C#, and side-effects when using direct memory access to those strings.
using System;
namespace ConsoleApplication1
{
internal class Program
{
private static void Main(string[] args)
{
var s1 = "Immutable String";
var s2 = "Immutable String";
@odalet
odalet / VS2012ToolStripRenderer.cs
Created December 5, 2013 15:17
dockpanelsuite 3.0 VS2012 Style: adding upper-case top-level menu items to the demo app. This code should be added to DockSample\VS2012ToolStripRenderer.cs
/// <summary>
/// Gets or sets a value indicating whether top-level menu items should be rendered upper case or not.
/// </summary>
/// <remarks>
/// Setting this property to <c>true</c> helps in simulating a VS2012/2013 style.
/// </remarks>
public bool EnableUpperTopLevelCaseMenuItems { get; set; }
protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
@odalet
odalet / certs-xp-en.msc
Created October 8, 2013 06:12
certs-xp-en.msc
<?xml version="1.0"?>
<MMC_ConsoleFile ConsoleVersion="3.0" ProgramMode="Author">
<ConsoleFileID>{549E388B-04AD-48CA-B7AC-4A781F265215}</ConsoleFileID>
<FrameState ShowStatusBar="true">
<WindowPlacement ShowCommand="SW_SHOWNORMAL">
<Point Name="MinPosition" X="-1" Y="-1"/>
<Point Name="MaxPosition" X="-1" Y="-1"/>
<Rectangle Name="NormalPosition" Top="145" Bottom="761" Left="110" Right="1129"/>
</WindowPlacement>
</FrameState>
@odalet
odalet / certs-xp-fr.msc
Last active December 24, 2015 16:29
certs-xp-fr.msc
<?xml version="1.0"?>
<MMC_ConsoleFile ConsoleVersion="3.0" ProgramMode="Author">
<ConsoleFileID>{01801879-32DE-4F21-9E1C-497141CCAD41}</ConsoleFileID>
<FrameState ShowStatusBar="true">
<WindowPlacement ShowCommand="SW_SHOWNORMAL">
<Point Name="MinPosition" X="-1" Y="-1"/>
<Point Name="MaxPosition" X="-1" Y="-1"/>
<Rectangle Name="NormalPosition" Top="203" Bottom="945" Left="154" Right="1414"/>
</WindowPlacement>
</FrameState>