Skip to content

Instantly share code, notes, and snippets.

@smailliwcs
smailliwcs / Forms.xaml
Last active Sep 22, 2020
Pixel-perfect WPF forms
View Forms.xaml
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="CheckBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CheckBox}">
<Border Padding="0,6,0,5">
<Grid x:Name="templateRoot" Background="Transparent" SnapsToDevicePixels="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
@smailliwcs
smailliwcs / gradient.plt
Last active Sep 22, 2020
Gradients in gnuplot
View gradient.plt
set terminal png size 640,480
set output 'gradient.png'
set xrange [-5:5]
set yrange [-5:5]
set cbrange [0:1]
unset colorbox
unset key
set palette gray negative
set object 1 rectangle from 1,-10 to 10,10 behind fillcolor rgb 'black' fillstyle noborder
plot '< python gradient.py -x -1 1 -10 10 64' with image
@smailliwcs
smailliwcs / output.png
Last active Sep 22, 2020
GIMP script: script-fu-highlight
@smailliwcs
smailliwcs / IntRangeArg.py
Created Sep 22, 2020
Integer range command-line arguments in Python
View IntRangeArg.py
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 Sep 22, 2020
Disabling hot corners in GNOME
View extension.js
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 Sep 22, 2020
Selecting text on keyboard navigation in WPF
View App.cs
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 Sep 22, 2020
Clearable WPF radio buttons
View ClearableRadioButton.cs
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 Sep 22, 2020
Mutually exclusive WPF checkboxes
View MainWindow.xaml
<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}">
View BufferedTraceListener.cs
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 Sep 22, 2020
Logging SQL queries in ADO.NET
View LoggingCommand.cs
using System.Data;
public class LoggingCommand : IDbCommand
{
private static void Log(string message)
{
// ...
}
private IDbCommand @base;
You can’t perform that action at this time.