Skip to content

Instantly share code, notes, and snippets.

@smailliwcs
smailliwcs / SystemColors.md
Last active October 14, 2021 14:55
Descriptions for WPF's system colors
Name Description
ActiveBorder Color of the active window's border
ActiveCaption Background color of the active window's title bar
ActiveCaptionText Color of the text in the active window's title bar
AppWorkspace Color of the application workspace
Control Face color of a three-dimensional display element
ControlDark Shadow color of a three-dimensional display element
ControlDarkDark Dark shadow color of a three-dimensional display element
ControlLight Light color of a three-dimensional display element
@smailliwcs
smailliwcs / IntRangeArg.py
Created September 22, 2020 15:26
Integer range command-line arguments in Python
import argparse
class IntRangeArg:
def __init__(self, start=None, stop=None):
assert start is None or stop is None or start < stop
self.start = start
self.stop = stop
def __contains__(self, value):
@smailliwcs
smailliwcs / extension.js
Created September 22, 2020 15:26
Disabling hot corners in GNOME
const LM = imports.ui.main.layoutManager;
let _updateHotCorners;
function _noop() { }
function _destroyHotCorners() {
LM.hotCorners.forEach(corner => {
if (corner) {
corner.destroy();
@smailliwcs
smailliwcs / App.cs
Created September 22, 2020 15:26
Selecting text on keyboard navigation in WPF
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
RegisterClassHandlers();
@smailliwcs
smailliwcs / ClearableRadioButton.cs
Created September 22, 2020 15:26
Clearable WPF radio buttons
using System.Windows.Controls;
public class ClearableRadioButton : RadioButton
{
protected override void OnClick()
{
bool? wasChecked = IsChecked;
base.OnClick();
if (wasChecked.GetValueOrDefault())
{
@smailliwcs
smailliwcs / MainWindow.xaml
Created September 22, 2020 15:26
Mutually exclusive WPF checkboxes
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<CheckBox IsChecked="{Binding A}">
<i:Interaction.Behaviors>
<local:UncheckOnSignalBehavior Signal="{Binding None}" />
</i:Interaction.Behaviors>
Option A
</CheckBox>
<CheckBox IsChecked="{Binding B}">
@smailliwcs
smailliwcs / BufferedTraceListener.cs
Created September 22, 2020 15:26
Buffering a TraceListener
using System;
using System.Diagnostics;
using System.Text;
using System.Threading;
public class BufferedTraceListener : TraceListener
{
private SynchronizationContext context;
private StringBuilder buffer;
private object bufferLock;
@smailliwcs
smailliwcs / LoggingCommand.cs
Created September 22, 2020 15:26
Logging SQL queries in ADO.NET
using System.Data;
public class LoggingCommand : IDbCommand
{
private static void Log(string message)
{
// ...
}
private IDbCommand @base;
@smailliwcs
smailliwcs / TwoWayDictionary.cs
Created September 22, 2020 15:26
Two-way dictionaries
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class TwoWayDictionary<T1, T2> : ICollection<Tuple<T1, T2>>
{
private static Tuple<T1, T2> ToTuple(T1 item1, T2 item2)
{
return Tuple.Create(item1, item2);
@smailliwcs
smailliwcs / InterlockedBoolean.cs
Created September 22, 2020 15:26
Interlocked Booleans
using System;
using System.Threading;
public class InterlockedBoolean
{
private int value;
public bool Value
{
get { return Convert.ToBoolean(value); }