Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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
{
create table #space ([table] nvarchar(255), [column] nvarchar(255) not null, [bytes] bigint null);
declare @sql varchar(max) = ''
declare @tablepattern as varchar(255) = '%'
declare @exclusionpattern as varchar(255) = ''
select @sql = @sql + 'insert into #space select ''' + t.name + ''', ''' + c.name + ''', sum(datalength([' + c.name + '])) as bytes from [' + t.name + '];'
from sys.columns c
inner join sys.tables t on c.object_id = t.object_id
inner join sys.schemas s on t.schema_id = s.schema_id
@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;&