Skip to content

Instantly share code, notes, and snippets.

View yamamaya's full-sized avatar

YAMANEKO yamamaya

View GitHub Profile
@yamamaya
yamamaya / How to resolve MSB3277.csproj
Last active March 2, 2026 12:41
How to resolve MSB3277 happen with WebView2
<Target Name="_removeUnusedWebView2" BeforeTargets="ResolveAssemblyReferences">
<ItemGroup>
<Reference Remove="@(Reference->WithMetadataValue('FileName', 'Microsoft.Web.WebView2.WinForms'))" Condition="'$(UseWindowsForms)' != 'true'" />
<Reference Remove="@(Reference->WithMetadataValue('FileName', 'Microsoft.Web.WebView2.Wpf'))" Condition="'$(UseWpf)' != 'true'" />
</ItemGroup>
</Target>
@yamamaya
yamamaya / DI_practice1_http.cs
Created February 20, 2026 12:18
DIの練習・HTTPクライアントの実装
using System.Net.Sockets;
using System.Text;
// DIの練習として、HTTPクライアントを実装する。
// DI(Dependency Injection)とは、クラスが必要とする依存関係を外部から注入することで、クラスの柔軟性とテスト容易性を向上させる設計パターンである。
// この例では、WebFetcherクラスがHTTPプロトコルを使用してウェブページを取得するための依存関係を注入する。
// WebFetcherはIProtocolに依存しているが、具体的なプロトコルの実装には依存していない。
// 更に、Http11ProtocolはITransportに依存しているが、具体的なトランスポートの実装には依存していない。
// これにより、具体的な実装との結合度が低くなり、柔軟性とテスト容易性が向上する。
@yamamaya
yamamaya / Median9.c
Created December 17, 2025 20:04
Get median from 9 elements by sorting network.
#define SWAP(a, b) if (arr[a] > arr[b]) { uint8_t tmp = arr[a]; arr[a] = arr[b]; arr[b] = tmp; }
uint8_t Median9(uint8_t arr[9]) {
SWAP(0, 1);
SWAP(1, 2);
SWAP(0, 1);
SWAP(3, 4);
SWAP(4, 5);
SWAP(3, 4);
SWAP(6, 7);
@yamamaya
yamamaya / SortingNetwork.c
Last active January 15, 2026 18:12
Sorting network for 9 elements
#define SWAP(a, b) if (arr[a] > arr[b]) { uint8_t tmp = arr[a]; arr[a] = arr[b]; arr[b] = tmp; }
// Sorting network for 9 elements (25 steps)
void SortingNetwork9(uint8_t *arr) {
SWAP(0, 1);
SWAP(3, 4);
SWAP(6, 7);
SWAP(1, 2);
SWAP(4, 5);
SWAP(7, 8);
@yamamaya
yamamaya / SemaphoreSlimLock.cs
Created October 8, 2025 11:22
A lightweight lock wrapper that allows SemaphoreSlim to be used with the using pattern.
using System.Diagnostics;
namespace OaktreeLab.Utils.Common {
/// <summary>
/// A lightweight lock wrapper that allows <see cref="SemaphoreSlim"/> to be used with the <c>using</c> pattern.
/// </summary>
[DebuggerStepThrough]
public sealed class SemaphoreSlimLock : IDisposable {
private readonly SemaphoreSlim _semaphore;
private bool _disposed;
namespace OaktreeLab.Utils.Common {
/// <summary>
/// Synchronous version of IProgress
/// </summary>
/// <typeparam name="T"></typeparam>
public sealed class SynchronousProgress<T> : IProgress<T> {
private readonly SynchronizationContext? _context;
private readonly Action<T> _handler;
public SynchronousProgress( Action<T> handler ) {
@yamamaya
yamamaya / WindowsPathChecker.cs
Created September 2, 2025 12:43
WindowsPathChecker - A simple console application to check the validity of paths
//***********************************************************************
// WindowsPathChecker
// A simple console application to check
// the validity of paths in the Windows PATH environment variable.
//***********************************************************************
namespace WindowsPathChecker {
internal class Program {
static void Main( string[] args ) {
// Get the value of the PATH environment variable
@yamamaya
yamamaya / TextBoxExtensions.cs
Created July 17, 2025 08:31
Gets the rectangle of the caret in the TextBox
using Microsoft.UI.Xaml.Controls;
using Windows.Foundation;
namespace OaktreeLab.Utils.WinUI3 {
/// <summary>
/// Class that provides extension methods for TextBox.
/// </summary>
public static class TextBoxExtensions {
/// <summary>
/// Gets the rectangle of the caret in the TextBox.
using System;
using System.Runtime.InteropServices;
namespace OaktreeLab.Utils {
internal class DisplayHelper {
public static uint GetRefreshRate( IntPtr hWnd ) {
IntPtr hmonitor = MonitorFromWindow( hWnd, MONITOR_DEFAULTTONEAREST );
MONITORINFOEXW monitorInfo = new MONITORINFOEXW();
monitorInfo.cbSize = (uint)Marshal.SizeOf<MONITORINFOEXW>();
GetMonitorInfoW( hmonitor, ref monitorInfo );
@yamamaya
yamamaya / remove clear posts buttons.js
Last active September 30, 2023 03:48
Remove "Clear posts" buttons from X pro (aka TweetDeck)
Array.prototype.slice.call( document.getElementsByTagName( 'path' ) )
.filter( obj => obj.getAttribute( 'd' ).indexOf( 'M22 19v2h-7.5l2-2H22zM3.35 14.232c-.97.977-.97 2.559 0 3.536L6.59' ) == 0 )
.map( obj => obj.parentElement.parentElement.parentElement.parentElement )
.forEach( obj => obj.style.display = "none" )