Skip to content

Instantly share code, notes, and snippets.

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 / 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 / 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 / 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 / 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 / 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 / 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)