Skip to content

Instantly share code, notes, and snippets.

@jtheisen
jtheisen / NannyPanel.cs
Created January 11, 2014 23:36
A panel that passes size recommendations to, but not from, children.
using System.Windows;
using System.Windows.Controls;
namespace MonkeyBusters
{
public class NannyPanel : Panel
{
protected override Size ArrangeOverride(Size finalSize)
{
foreach (var child in Children)
@jtheisen
jtheisen / TextBoxImmediateUpdateBehavior.cs
Created January 11, 2014 23:39
A behavior making a TextBox update the source on every key press.
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;
namespace MonkeyBusters
{
// This behavior allows for TextBoxes which can't be tabbed away from - and would thus
// never update their source. They do update on key release now, which is not
// right away as it would be if the TextChanged event was used.
@jtheisen
jtheisen / ObservableDependencyValue.cs
Created January 11, 2014 23:34
Programmatic type-safe bindings
using System;
using System.Linq.Expressions;
using System.Windows;
using System.Windows.Data;
namespace MonkeyBusters
{
public static class ObservableDependencyValue
{
public static ObservableDependencyValue<T> Create<T>(Expression<Func<T>> expr, BindingMode mode = BindingMode.OneWay)
@jtheisen
jtheisen / VisibilityConverter.cs
Created January 11, 2014 23:37
Xaml's most popular converter.
using System;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel;
namespace MonkeyBusters
{
public class VisibilityConverter : IValueConverter
{
public Boolean TrueIsVisible { get; set; }
@jtheisen
jtheisen / Stegman.cs
Last active January 4, 2016 01:19
The Stegman PNG Encoder
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO;
@jtheisen
jtheisen / SafeMvcUrls.cs
Created November 3, 2014 16:10
Name- and type-safe ASP.NET MVC url creation
using System;
using System.Linq.Expressions;
using System.Reflection;
using System.Web.Mvc;
using System.Web.Routing;
namespace MonkeyBusters.Web.Mvc
{
public static class SafeMvcUrls
{
@jtheisen
jtheisen / GlimpseServiceLocator.cs
Last active July 19, 2016 13:24
A ServiceLocator for Glimpse to improve startup time. *Doesn't work yet*!
using Glimpse.Core.Framework;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
namespace My
{
public class TypeRepository
msbuild /p:DeployOnBuild=true /p:PublishProfile=Staging /p:Password=agkamed /p:AllowUntrustedCertificate=true
<?xml version="1.0" encoding="utf-16"?>
<ShowPlanXML xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="1.2" Build="12.0.2000.8" xmlns="http://schemas.microsoft.com/sqlserver/2004/07/showplan">
<BatchSequence>
<Batch>
<Statements>
<StmtSimple StatementCompId="1" StatementEstRows="1" StatementId="1" StatementOptmLevel="FULL" CardinalityEstimationModelVersion="120" StatementSubTreeCost="241.548" StatementText="SELECT TOP 1&#xD;&#xA; [Project1].[C1] AS [C1], &#xD;&#xA; [Project1].[Id] AS [Id], &#xD;&#xA; [Project1].[SupplierNumber] AS [SupplierNumber], &#xD;&#xA; [Project1].[ArticleNumber] AS [ArticleNumber], &#xD;&#xA; [Project1].[ArticleName] AS [ArticleName]&#xD;&#xA; FROM ( SELECT &#xD;&#xA; [Extent1].[SupplierNumber] AS [SupplierNumber], &#xD;&#xA; [Extent1].[ArticleNumber] AS [ArticleNumber], &#xD;&#xA; [Extent1].[Id] AS [Id], &#xD;&#xA; [Extent1].[ArticleName] AS [ArticleName], &#xD;&
@jtheisen
jtheisen / benchmark.cs
Created September 15, 2016 13:24
Value type generic performance benchmark
void Main()
{
var t1 = DateTime.Now;
TestGeneric(new GenericComparer<Int32>());
var t2 = DateTime.Now;
TestGeneral(new GenericComparer<Int32>());
var t3 = DateTime.Now;
TestGeneric(Comparer<Int32>.Default);
var t4 = DateTime.Now;
TestGeneral(Comparer<Int32>.Default);