Skip to content

Instantly share code, notes, and snippets.

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.
@yamamaya
yamamaya / TransparentCover.cs
Last active January 5, 2022 07:41
Transparent cover to prevent mouse operation in Windows Forms application.
using System;
using System.Windows.Forms;
namespace OaktreeLab.Utils {
public class TransparentCover : Panel {
private const int WS_EX_TRANSPARENT = 0x00000020;
protected override CreateParams CreateParams {
get {
CreateParams param = base.CreateParams;
@yamamaya
yamamaya / addRGB555.c
Created August 2, 2021 05:21
Add RGB555 colors together with "software packed" method
#include <stdint.h>
uint16_t addRGB555( uint16_t color1, uint16_t color2 ) {
uint16_t c;
c = ( ( ( color1 & color2 ) << 1 ) + ( ( color1 ^ color2 ) & 0x7bde ) ) & 0x8420;
c = ( ( c >> 5 ) + 0x3def ) ^ 0x3def;
return( ( color1 + color2 - c ) | c );
}
// testbench
@yamamaya
yamamaya / addRGB565.c
Created August 2, 2021 05:17
Add RGB565 colors together with "software packed" method
#include <stdint.h>
uint16_t addRGB565( uint16_t color1, uint16_t color2 ) {
uint16_t c;
c = ( ( color1 & color2 ) + ( ( ( color1 ^ color2 ) & 0xf7de ) >> 1)) & 0x8410;
c = ( ( ( ( ( c + 0xfbdf0 ) ) >> 5 ) & 0xfbff ) + 0x200 ) ^ 0x7bef;
return (color1 + color2 - c) | c;
}
@yamamaya
yamamaya / blendRGB555.c
Created August 2, 2021 05:03
Blend RGB555 colors together with "software packed" method
#include <stdint.h>
uint16_t blendRGB555( uint16_t color1, uint16_t color2 ) {
return( (color1 & color2) + (((color1 ^ color2) & 0x7bde) >> 1) );
}
// testbench
#include <stdio.h>
#define R_bits 5