Skip to content

Instantly share code, notes, and snippets.

View qwertie's full-sized avatar

David Piepgrass qwertie

View GitHub Profile
@qwertie
qwertie / CharCategories.html
Last active October 12, 2023 09:42
Table of all Unicode characters by category
<!doctype html>
<html>
<head>
<style>
p { font-family: serif; }
table {
border-collapse:collapse;
}
table td, table td {
vertical-align: top;
@qwertie
qwertie / DateTimePicker.xaml
Last active June 5, 2023 18:31
C# DateTimePicker for WPF
<UserControl x:Class="DTPicker.DateTimePicker"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DTPicker"
xmlns:wpftc="clr-namespace:Microsoft.Windows.Controls;assembly=WPFToolkit"
mc:Ignorable="d"><!--Uses Calendar in WPFToolkit.dll,
see http://wpf.codeplex.com/releases/view/40535-->
<UserControl.Resources>
@qwertie
qwertie / InternalList.cs
Last active June 28, 2021 03:05
InternalList<T>, the low-level List<T> (standalone version: does not require Loyc.Essentials.dll, is compatible with .NET 3.5)
// from Loyc.Essentials.dll. Licence: MIT
namespace Loyc.Collections.Impl
{
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Linq;
/// <summary>A compact auto-enlarging array structure that is intended to be
@qwertie
qwertie / SimpleTimer.cs
Created September 25, 2013 21:36
A fast, simple alternative to System.Diagnostics.Stopwatch based on Environment.TickCount. Its resolution is typically 10-16 ms.
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace Loyc
{
/// <summary>
/// A fast, simple timer class with a more convenient interface than
/// System.Diagnostics.Stopwatch. Its resolution is typically 10-16 ms.
@qwertie
qwertie / dep.snippet
Created January 20, 2012 20:02
C# code snippets for using UpdateControls
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>dep</Title>
<Shortcut>dep</Shortcut>
<Description>Code snippet to help you make properties based on 'Dependent&lt;T&gt;', an Update Controls class that represents a value computed based on one or more Independents. Note: in most cases you should just write a normal property instead of using Dependent&lt;T&gt;. Dependent&lt;T&gt; is useful to cache the result of a computation when the value of the property is expensive to compute.</Description>
<Author>David Piepgrass</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
@qwertie
qwertie / ValueConverters.cs
Created January 20, 2012 18:21
ValueConverter + MarkupExtension in one
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Markup;
using System.Globalization;
using System.Windows.Data;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
function whatAmI(thing: string|RegExp|null|number[]|Date) {
if (thing instanceof RegExp || typeof thing === "string") {
// Here, TypeScript knows that thing is RegExp|string
if (typeof thing !== "string")
console.log("Ahh, so it's a RegExp: " + thing.toString());
else
console.log("It's a string of length " + thing.length);
} else {
// Here, TypeScript knows that thing is null|number|Date
if (thing == null)
// Type parameters can have default values,
// so `var t: BTree` means `var t: BTree<any,any>`
export class BTree<K=any, V=any>
{
// Root node (key-value pairs are stored in here)
private _root: BNode<K, V>;
// Total number of items in the collection
_size: number = 0;
// Maximum number of items in a single node
_maxNodeSize: number;
interface IBox {
readonly width: number;
readonly height: number;
}
interface IArea {
readonly area: number;
}
class PrivateBox {
constructor(private width: number, private height: number) {}
area() { return this.width * this.height; }
}
let x = new PrivateBox(4, 5);
console.log(x.area()); // OK
console.log(x.width); // ERROR: 'width' is private and only
// accessible within class 'PrivateBox'.