Skip to content

Instantly share code, notes, and snippets.

@nigel-sampson
nigel-sampson / gist:e49bb93d75e452b65d08
Last active December 6, 2015 20:58
UWP workaround
<Pivot ItemsSource="{Binding Items}"
SelectedItem="{Binding ActiveItem, Mode=TwoWay}"
HeaderTemplate="{StaticResource PivotHeaderTemplate}"
ItemContainerStyle="{StaticResource PivotItemContainerStyle}">
<Pivot.ItemTemplate>
<DataTemplate>
<ContentControl cm:View.Model="{Binding}"/>
</DataTemplate>
</Pivot.ItemTemplate>
</Pivot>
@nigel-sampson
nigel-sampson / gist:221d49b939cad48a1fe2
Created March 3, 2015 19:22
Kmeans implementation in F#
namespace KMeans.Core
module Clustering =
type Distance<'a> = 'a -> 'a -> float
type Recenter<'a> = 'a list -> 'a
let sample n (xs : 'a list) =
let step = xs.Length / n
match step with
@nigel-sampson
nigel-sampson / gist:db65e0355b428ded315b
Created November 24, 2014 02:25
Non scrolling combo box
<ComboBox
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
ScrollViewer.HorizontalScrollMode="Disabled"
ScrollViewer.VerticalScrollMode="Disabled">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
@nigel-sampson
nigel-sampson / App.xaml
Created October 15, 2014 19:53
Spectrum Demo
<Application
x:Class="Spectrum.Demo.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:convereters="using:Spectrum.Universal.Converters">
<Application.Resources>
<convereters:ComplimentConverter x:Key="Compliment" />
<convereters:ShiftLightnessConverter x:Key="ShiftLightness" />
public class OAuthCredentialsStore : ICredentialStore
{
private const string ClientId = "<redacted>";
private const string ClientSecret = "<redacted>";
private readonly IGitHubClient _gitHubClient;
public OAuthCredentialsStore()
{
_gitHubClient = new GitHubClient(new ProductHeaderValue("HubBug", "0.0.0.1"))
{
@nigel-sampson
nigel-sampson / gist:8566230
Created January 22, 2014 19:57
Octokit OAuth Token Ruest
var gitHubClient = new GitHubClient(new ProductHeaderValue("Test App", "0.0.0.1"))
{
Credentials = Credentials.Anonymous
};
var content = new FormUrlEncodedContent(new Dictionary<string, string>
{
{"client_id", ClientId },
{"client_secret", ClientSecret },
{"code", responseParameters["code"] },
@nigel-sampson
nigel-sampson / gist:5536817
Created May 7, 2013 22:51
Insert IList<T>
[TestMethod]
public async Task CanInsertInterfaces()
{
BlobCache.ApplicationName = "RepoTests";
IList<string> strings = new List<string> { "foo", "bar", "baz" }; // fails
// var = new List<string> { "foo", "bar", "baz" }; // passes
await BlobCache.LocalMachine.InsertObject("strings", strings);
@nigel-sampson
nigel-sampson / gist:5536332
Created May 7, 2013 21:33
WP8 Local Machine Weirdness
var projects = await GetProjectsAsync();
await BlobCache.LocalMachine.InsertObject("projects", projects);
var test = await BlobCache.LocalMachine.GetOrCreateObject("projects", () => new List<Project>());
if (projects.Count != test.Count)
throw new InvalidOperationException("Hmmm");
create_task(FileIO::ReadTextAsync(file)).then([this, file](task<String^> task)
{
try
{
String^ fileContent = task.get();
OutputTextBlock->Text = "The following text was read from '" + file->Name + "':\n\n" + fileContent;
}
catch(COMException^ ex)
{
rootPage->HandleFileNotFoundException(ex);
@nigel-sampson
nigel-sampson / gist:4760113
Created February 12, 2013 03:49
Collecting pointer moved and only want points once the pointer has moved a certain amount.
private void OnLoaded(object sender, RoutedEventArgs args)
{
var pointerMoved = Observable.FromEventPattern<PointerEventHandler, PointerRoutedEventArgs>(h => PathRoot.PointerMoved += h, h => PathRoot.PointerMoved -= h).Select(e => e.EventArgs);
var pointerInContact = pointerMoved.Where(p => p.Pointer.IsInContact);
var points = pointerInContact.Select(p => p.GetCurrentPoint(PathRoot)).Select(p => new Vector2((float) p.Position.X, (float) p.Position.Y));
var previousPoints = points.Skip(1);
var deltas = points.Zip(previousPoints, (current, previous) => new Vector2Delta { Point = current, Delta = current - previous });
var scannedDeltas = deltas.Scan(new Vector2Delta { Point = Vector2.Zero, Delta = Vector2.Zero }, ScanSignificantDeleta);