Skip to content

Instantly share code, notes, and snippets.

@robfe
robfe / QrCodeElement.cs
Created November 9, 2011 22:20
WPF templated control for QrCode.codeplex.com
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Gma.QrCodeNet.Encoding;
namespace Gma.QrCodeNet.Wpf
{
public class QrCodeElement : Control
@robfe
robfe / ShadowBorder.xaml
Created May 6, 2011 15:31
Fancy curvy shadow style for a ContentControl
<Style x:Key="ShadowBorder" TargetType="ContentControl">
<Setter Property="Foreground" Value="#FF000000"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="VerticalContentAlignment" Value="Top"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContentControl">
<Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<Grid Margin="2,1,2,-3" RenderTransformOrigin="0.5,0">
<Grid.RenderTransform>
@robfe
robfe / hgignore.txt
Created March 31, 2011 21:05
My .NET centric hgignore defaults
glob:Debug
glob:*.user
glob:_ReSharper*
glob:*.cachefile
glob:*.suo
glob:~$*
glob:*.tmp
glob:*/bin/*
glob:*/obj/*
glob:*.orig
@robfe
robfe / NodeList.cs
Created March 6, 2011 22:58
A lock-free, thread-safe RX IScheduler that runs as part of an XNA game loop
public class NodeList<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>> where TKey : IComparable<TKey>
{
readonly Node start = new Node(default(TKey), default(TValue));
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
for (Node n = start.GetNext(); n != null; n = n.GetNext())
{
yield return new KeyValuePair<TKey, TValue>(n.key, n.value);
}
@robfe
robfe / XamlMinify.cs
Created March 4, 2011 17:37
Method to compress XAML: Removes comments, whitespace, and mc:Ignorable components
static string Minimize(XDocument document)
{
//take out the comments
document.DescendantNodes().OfType<XComment>().Remove();
//take out the mc:ignorables
XNamespace mc = "http://schemas.openxmlformats.org/markup-compatibility/2006";
var ignorable = document.Root.Attribute(mc + "Ignorable");
if (ignorable != null)
{
@robfe
robfe / AgCodeTimer.cs
Created March 1, 2011 11:26
Silverlight compatible version of https://gist.github.com/460096
public class CodeTimer : IDisposable
{
readonly string message;
readonly DateTime start;
public CodeTimer(string message)
{
this.message = message;
start = DateTime.UtcNow;
}
@robfe
robfe / Resources.tt
Created February 27, 2011 16:49
Strongly typed access to Content files for XNA
<#@ template language="C#" hostspecific="True" debug="True" #>
<#@ import namespace="System.IO"#>
<#@ import namespace="System.Linq"#>
<#@ import namespace="System.Collections.Generic"#>
<#@ import namespace="System.Runtime.Remoting.Messaging" #>
<#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>
<#@ assembly name="System.Core.dll"#>
<#@ output extension=".Generated.cs" #>
<#
@robfe
robfe / VirtualContentPresenter.cs
Created February 3, 2011 09:50
Helps you to keep the number of visuals in your visual tree down
/// <summary>
/// Easy way to switch between no content template and some content template in silverlight
/// Helps you to keep the number of visuals in your visual tree down.
/// </summary>
public class VirtualContentPresenter : ContentPresenter
{
public static readonly DependencyProperty VirtualContentTemplateProperty = DependencyProperty.Register("VirtualContentTemplate",
typeof(DataTemplate),
typeof(VirtualContentPresenter),
new PropertyMetadata(null, (o, args) => ((VirtualContentPresenter) o).VirtualContentPropertyChanged()));
@robfe
robfe / ObservableExtensions.tt
Created November 29, 2010 10:17
T4 template to generate some useful N-Tuple overloads of common System.Reactive extension methods
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ output extension="Generated.cs" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Runtime.Remoting.Messaging" #>
<#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>
using System;
using System.Linq;
using System.Reactive;
@robfe
robfe / CsProjReferencesToDot.cs
Created October 27, 2010 14:39
Analyses all the csproj files in a directory and generates a dot (www.graphviz.com) graph of the project references, including silverlight application references
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace ReferenceReader
{