Skip to content

Instantly share code, notes, and snippets.

View CodingOctocat's full-sized avatar
:shipit:
默默无闻地摸鱼

CodingNinja CodingOctocat

:shipit:
默默无闻地摸鱼
View GitHub Profile
using System;
using System.Threading.Tasks;
/// <summary>
/// <see href="https://www.devleader.ca/2023/02/14/async-eventhandlers-a-simple-safety-net-to-the-rescue/">Async EventHandlers – A Simple Safety Net To The Rescue</see>
/// </summary>
public static class AsyncEventHandlers
{
public static EventHandler<TArgs> TryAsync<TArgs>(
Func<object?, TArgs, Task> callback,
@CodingOctocat
CodingOctocat / AttachableForStyleBehavior.cs
Last active April 13, 2025 11:28
AttachableForStyleBehavior
public class AttachableForStyleBehavior<TComponent, TBehavior> : Behavior<TComponent>
where TComponent : DependencyObject
where TBehavior : AttachableForStyleBehavior<TComponent, TBehavior>, new()
{
public static readonly DependencyProperty IsEnabledForStyleProperty =
DependencyProperty.RegisterAttached(
"IsEnabledForStyle",
typeof(bool),
typeof(AttachableForStyleBehavior<TComponent, TBehavior>),
new FrameworkPropertyMetadata(false, OnIsEnabledForStyleChanged));
@CodingOctocat
CodingOctocat / DeferredContent.cs
Created March 27, 2025 11:09
WPF/DeferredContent
using System;
using System.Windows;
using System.Windows.Controls;
/// <summary>
/// <see href="https://stackoverflow.com/a/26543731/4380178">Deferred loading of XAML</see>
/// </summary>
public class DeferredContent : ContentPresenter
{
@CodingOctocat
CodingOctocat / DashedBorder.cs
Created March 27, 2025 11:08
WPF/DashedBorder
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Shapes;
/// <summary>
/// <see href="https://stackoverflow.com/a/72138376/4380178">How can I achieve a dashed or dotted border in WPF?</see>
/// </summary>
@CodingOctocat
CodingOctocat / xlutils.py
Created August 29, 2022 13:48
openpyxl utils.
import re
from enum import Enum
from typing import Union, Optional
from openpyxl.cell.cell import Cell, MergedCell
from openpyxl.worksheet.cell_range import CellRange
from openpyxl.worksheet.worksheet import Worksheet
class Direction(Enum):
@CodingOctocat
CodingOctocat / xlconverter.py
Last active July 24, 2024 03:24
xls2xlsx or xlsx2xls.
import os
from enum import Enum
import win32com.client as win32
class Overwrite(Enum):
ASK = 0
ALWAYS = 1
NEVER = 2
@CodingOctocat
CodingOctocat / DebounceDispatcher.cs
Last active March 16, 2025 06:30
Debounce Dispatcher.
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Threading;
/// <summary>
/// Debounce Dispatcher.
/// <para>
/// forked from: <seealso href="https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/main/Microsoft.Toolkit.Uwp/Extensions/DispatcherQueueTimerExtensions.cs">Microsoft.Toolkit.Uwp.Extensions.DispatcherQueueTimerExtensions</seealso>.
@CodingOctocat
CodingOctocat / ISubtitle.cs
Last active May 8, 2022 03:38
Speech-to-Subtitle (word-level timestamp) code snippet based on MS Azure Speech.
/// <summary>
/// 表示一条包含基本要素的字幕。
/// </summary>
public interface ISubtitle
{
/// <summary>
/// 获取或设置字幕的开始时间。
/// </summary>
public TimeSpan Begin { get; set; }