Skip to content

Instantly share code, notes, and snippets.

View andersonimes's full-sized avatar

Anderson Imes andersonimes

  • Google
  • Seattle, WA
View GitHub Profile
@andersonimes
andersonimes / gist:645567
Created October 25, 2010 19:31
Testing posting XAML
<ItemsControl ItemsSource="{Binding StuffThatIsCool}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding WhyCool}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<ItemsControl Grid.IsSharedSizeScope="True">
<ItemsControl.ItemTemplate>
<DataTemplate DataType="HeaderedContentControl">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="Labels" />
<ColumnDefinition SharedSizeGroup="Inputs" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Header}" />
<ContentControl Grid.Column="1" Content="{Binding Content}" />
@andersonimes
andersonimes / gist:645999
Created October 25, 2010 23:18
Determining Design Mode from Attached Properties
private bool IsDesignMode {
get {
DependencyProperty isDesignModeProperty = (DependencyProperty)AppDomain.CurrentDomain.GetData(“IsDesignModeProperty”);
return isDesignModeProperty == null ? false : true.Equals(isDesignModeProperty.GetValue(this));
}
}
@andersonimes
andersonimes / gist:646021
Created October 25, 2010 23:35
Styling the Thumb in a Silverlight Slider
<Grid>
<Grid.Resources>
<Style x:Key="ThumbStyle1" TargetType="Thumb">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Thumb">
<Grid >
<Path Data="M13.832941,48.001114 L-0.00066526519,15.584446 L-0.1685528,3.1627214 L46.375076,3.1882343 L46.59383,15.594595 L33.375225,48.063122 z" Fill="#FF6D6D74" Margin="-0.668,2.662,0.906,-0.562" Stretch="Fill" Stroke="Black" UseLayoutRounding="False"/>
</Grid>
</ControlTemplate>
@andersonimes
andersonimes / anagram_mono.cs
Created April 15, 2012 04:53
Anagram finder in C# (Mono)
public static void Main (string[] args)
{
var words = System.IO.File.ReadAllLines("/usr/share/dict/words");
var anagramLookup = words.ToLookup(MakeAnagramKey);
var anagrams = anagramLookup[MakeAnagramKey("pots")];
Console.WriteLine(string.Join(Environment.NewLine, anagrams.ToArray()));
}
@andersonimes
andersonimes / gist:2490459
Created April 25, 2012 15:09
Property Code Snippet for ReactiveUI
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Reactive Property</Title>
<Shortcut>propr</Shortcut>
<Description>Creates a property that calls RaiseAndSetIfChanged</Description>
<Author>Anderson Imes</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
@andersonimes
andersonimes / gist:2568262
Created May 1, 2012 14:22
[LINQ]Chunk Operator
/// <summary>
/// Break a list of items into chunks of a specific size
/// </summary>
public static IEnumerable<IEnumerable<T>> Chunk<T>(this IEnumerable<T> source, int chunksize)
{
while (source.Any())
{
yield return source.Take(chunksize);
source = source.Skip(chunksize);
}
@andersonimes
andersonimes / LimitedConcurrencyScheduler.cs
Created May 1, 2012 22:50
[Tasks][Threading]Limited Concurrency Task Scheduler
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace MaryKay.Threading
{
/// <summary>
/// Provides a task scheduler that ensures a maximum concurrency level while
@andersonimes
andersonimes / ObservableMixins.cs
Created May 10, 2012 23:06
[Rx]Extensions for tagging an event stream. Useful for when you need to combine two observables and can't use anonymous types
public static class ObservableMixins
{
public static IObservable<ObjectTag<T, V>> Tag<T, V>(this IObservable<V> sequenceToTag, T tag)
{
return sequenceToTag.Tag(_ => tag);
}
public static IObservable<ObjectTag<T, V>> Tag<T, V>(this IObservable<V> sequenceToTag, Func<V, T> tagFunction)
{
return sequenceToTag.Select(v => new ObjectTag<T, V>(tagFunction(v), v));
@andersonimes
andersonimes / ReactiveFileWatcher.cs
Created June 28, 2012 18:01
[Rx][IO]File System notification throttling via Reactive Extensions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Dynamic;
using System.Reflection;
using System.Reactive.Linq;
using Rxx;
using System.IO;
namespace ConsoleApplication17