Skip to content

Instantly share code, notes, and snippets.

View yamamaya's full-sized avatar

YAMANEKO yamamaya

View GitHub Profile
@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" )
@yamamaya
yamamaya / M5-SwitchBotTH.ino
Created May 28, 2023 05:54
Experimental code to acquire data from SwitchBot Thermometer/Hygrometer by M5Stack.
#include <M5Stack.h>
#include <BLEDevice.h>
static BLEUUID SWITCHBOT_ServiceDataUUID( "0000fd3d-0000-1000-8000-00805f9b34fb" );
#define SWITCHBOT_CompanyID 0x0969
#define SWITCHBOT_DeviceType 'T'
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) {
Serial.print("BLE Advertised Device found: ");
@yamamaya
yamamaya / QCAD EasyToSee theme.md
Last active April 27, 2023 10:44
QCAD EasyToSee theme

This theme changes all fonts of textboxes including command-line and history to Consolas.

  1. Create "EasyToSee" folder in "Program files\QCAD\themes".
  2. Then, copy this "stylesheet.css" into it.
  3. Launch QCAD, change the theme to EasyToSee and restart.
@yamamaya
yamamaya / .gitignore
Last active March 27, 2023 08:14
gitignore for MPLAB X projects with MCC
*.X/.ca/
*.X/.generated_files/
*.X/build/
*.X/debug/
*.X/dist/
*.X/nbproject/*
!*.X/nbproject/configurations.xml
!*.X/nbproject/project.xml
@yamamaya
yamamaya / How to dedicate a CPU core.md
Last active June 13, 2022 05:24
Dedicate a cpu core to specified thread, in Raspberry Pi.
  1. At first, run this command by superuser. This will assign CPU cores other than #3 for all processes. But it will cause some errors, I'm not sure it is really perfect.
    ps -e -o pid= | sudo xargs -n 1 taskset -p -a 0xFFFFFFF7 2> /dev/null > /dev/null
  1. And then, run those codes in your program. This will assign CPU core #3 exclusively for the thread.