Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / ApiDocumentor.cs
Created November 16, 2011 11:41
Documents the webget and webinvoke methods of a ServiceContract
[TestClass]
public class ApiDocumentor
{
[TestMethod]
public void PrintApiMethods()
{
var methods = from m in typeof(Api).GetMethods()
let url = GetUrl(m)
where url != null
@robfe
robfe / AppBarButtons.tt
Created January 8, 2012 23:46
t4 template for strong access to all your AppBarButtons in a wp7 Page
<#@ template language="C#" hostspecific="True" debug="false" #>
<#@ import namespace="System.IO"#>
<#@ import namespace="System.Linq"#>
<#@ import namespace="System.Xml.Linq"#>
<#@ import namespace="System.Collections.Generic"#>
<#@ import namespace="System.Runtime.Remoting.Messaging"#>
<#@ import namespace="Microsoft.VisualStudio.TextTemplating"#>
<#@ assembly name="System.Core.dll"#>
<#@ assembly name="System.Xml.Linq.dll"#>
<#@ assembly name="System.Xml.dll"#>
@robfe
robfe / SquaresToPolygonGenerator.cs
Created May 10, 2012 09:28
Takes a 2d array of bools (representing squares on a grid) and gives you the polygon that wraps those squares
/// <summary>
/// C# port of http://raksy.dyndns.org/cycle_collection.py via http://stackoverflow.com/questions/8946563/add-square-to-polygon-composed-of-squares
/// </summary>
static class SquaresToPolygonGenerator
{
static readonly Coordinate[] directions = new[]
{
Coordinate.West,
Coordinate.South,
Coordinate.East,
@robfe
robfe / TileCanvas.cs
Created June 27, 2012 21:05
Tilebrush equivalent for WinRT XAML apps.
public class TileCanvas : Canvas
{
public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(TileCanvas), new PropertyMetadata(null, ImageSourceChanged));
private Size lastActualSize;
public TileCanvas()
{
LayoutUpdated += OnLayoutUpdated;
}