Skip to content

Instantly share code, notes, and snippets.

View hsytkm's full-sized avatar
💪
Our ultimate goal is to make a living doing development, right?

thinva hsytkm

💪
Our ultimate goal is to make a living doing development, right?
View GitHub Profile
@hsytkm
hsytkm / Program.cs
Created April 14, 2024 12:47
Memcopy Benchmark
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
BenchmarkRunner.Run<MemoryCopyBenchmark>();
[MemoryDiagnoser]
public class MemoryCopyBenchmark
{
@hsytkm
hsytkm / Program.cs
Created February 24, 2024 01:52
WPF image speed benchmark.
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.IO;
using System.Windows.Media.Imaging;
BenchmarkRunner.Run<WpfBitmapSourceBenchmark>();
public class WpfBitmapSourceBenchmark
{
[Params(@"img100x100.bmp", @"img1000x1000.bmp")]
@hsytkm
hsytkm / lswin.bat
Created February 24, 2024 01:40
Command to display file names with windows sorting rules
@echo off
setlocal
set BAT_PATH=%~f0
powershell -NoProfile -Command "& {$cscode=[regex]::Split([IO.File]::ReadAllText($env:BAT_PATH,[Text.Encoding]::UTF8),':EndBatch')[2]; Add-Type -TypeDefinition $cscode -Language CSharp; [CSBatch.Program]::Main($Args);}" %*
endlocal
exit /b
:EndBatch
using System;
using System.IO;
@hsytkm
hsytkm / Program.cs
Created January 20, 2024 04:00
Create 16bit pgm/ppm images
using System.Text;
File.WriteAllText("_p2_16b.pgm", CreateP2_16b());
File.WriteAllText("_p3_16b_gray.ppm", CreateP3_Gray16b());
File.WriteAllText("_p3_16b_red.ppm", CreateP3_Red16b());
File.WriteAllText("_p3_16b_green_blue.ppm", CreateP3_GreenBlue16b());
File.WriteAllBytes("_p5_16b.pgm", CreateP5_16b());
File.WriteAllBytes("_p6_16b_red.pgm", CreateP6_Red16b());
File.WriteAllBytes("_p6_16b_green_blue.pgm", CreateP6_GreenBlue16b());
@hsytkm
hsytkm / Overlay.cs
Created October 28, 2023 09:46
Memory-Mapped Files and Overlaid Structs
// [Memory-Mapped Files and Overlaid Structs](https://blog.stephencleary.com/2023/09/memory-mapped-files-overlaid-structs.html)
// [Padding for Overlaid Structs](https://blog.stephencleary.com/2023/10/padding-for-overlaid-structs.html)
using System;
using System.Buffers.Binary;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Runtime.CompilerServices;
using FileStream file = new(
# 図形を検出します。
from pathlib import Path
import numpy as np
import cv2
IMAGE_WINDOW_TITLE = 'preview'
#-------------------------------------------------------------------
file_path = Path(__file__).parent / 'shapes.png'
@hsytkm
hsytkm / TrueInvariantCulture.cs
Last active July 17, 2023 02:04
TrueInvariantCulture
// https://github.com/ufcpp-live/UfcppLiveAgenda/issues/73#issuecomment-1595764176
using System.Globalization;
using System.Runtime.CompilerServices;
Console.WriteLine(DateTime.Now);
// source generator で強制的に足せば…
static class Initialier
{
@hsytkm
hsytkm / Owner.cs
Created May 23, 2023 21:33
C# Owner Belongings
namespace ConsoleApp1;
public interface IBelonging<T>
where T : IBelonging<T>
{
static abstract Owner<T> Create();
}
public readonly record struct Owner<T> : IDisposable
where T : IBelonging<T>
@hsytkm
hsytkm / YesNo.cs
Created May 20, 2023 09:43
Express Yes and No clearly.
Console.WriteLine(new Dialog().GetResult());
var message = new Confirm().GetResult().IsYes ? "Deleted" : "Canceled";
Console.WriteLine(message);
struct Dialog
{
public YesNo<Dialog> GetResult() => YesNo<Dialog>.Yes;
}
@hsytkm
hsytkm / Program.cs
Created November 13, 2022 14:21
Load dll
// https://remix-yh.net/1324/
using System.Reflection;
var plugin = GetExternalPlugin("ClassLibrary1.dll");
Console.WriteLine(plugin?.GetMessage() ?? "null");
static IPlugin? GetExternalPlugin(string filename)
{
static Type? GetTargetImplementedType<T>(Assembly assembly)
{