Skip to content

Instantly share code, notes, and snippets.

View dotMorten's full-sized avatar
:octocat:

Morten Nielsen dotMorten

:octocat:
View GitHub Profile
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.UI.Core;
using Windows.UI.Xaml.Data;
namespace UniversalTestApp
@dotMorten
dotMorten / Program.cs
Created August 25, 2017 21:47
Slow webserver response test
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace TimeoutTestApp
{
@dotMorten
dotMorten / Program.cs
Last active December 8, 2016 20:08
Simple Iotivity Server and Light Resource created using .NET calling into the Iotivity C-API
using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
namespace SimpleServerNet
{
class Program
{
private static CancellationTokenSource ct;
@dotMorten
dotMorten / XMLDocumentationStripper.cs
Last active September 14, 2016 17:54
Optimizes XML Doc for intellisense by stripping out internals and remarks from the XML doc
using Mono.Cecil;
using Mono.Cecil.Rocks;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
namespace ConsoleApplication1
{
class Program
{
@dotMorten
dotMorten / MainPage-snippet.xaml
Last active June 23, 2016 21:35
StaggeredGrid
<ItemsControl x:Name="items" Grid.RowSpan="3" ItemsSource="{x:Bind Data}" Background="LightGray">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<local:StaggeredGridPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Margin="5" Background="{Binding Brush}" Height="{Binding Height}">
<TextBlock Text="{Binding Name}" HorizontalAlignment="Center" VerticalAlignment="Center" />
@dotMorten
dotMorten / ObservableCollection2.cs
Created November 26, 2015 20:36
Observable Collection supporting range adds efficiently without causing a lot of UI updates
public class ObservableCollection2<T> : ObservableCollection<T>
{
public void AddRange(IEnumerable<T> items)
{
InsertRange(Count, items);
}
public void InsertRange(int index, IEnumerable<T> items)
{
int count = 0;
foreach(var item in items)
/**
* Smartenit ZHBT-2
*
* Copyright 2015 Morten Nielsen
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@dotMorten
dotMorten / .NET Native build errors
Created September 22, 2015 21:18
Has anyone ever seen errors like this?
4>c:\source\Tests\UnitTests.Universal\sg.exe : warning : SG0002 : Cannot generate serialization code for type 'System.Globalization.CompareInfo'
4>c:\source\Tests\UnitTests.Universal\sg.exe : warning : SG0002 : Cannot generate serialization code for type 'System.Globalization.CultureData'
4>c:\source\Tests\UnitTests.Universal\sg.exe : warning : SG0002 : Cannot generate serialization code for type 'System.Globalization.TextInfo'
4>c:\source\Tests\UnitTests.Universal\sg.exe : warning : SG0002 : Cannot generate serialization code for type 'MyProjectNameSpace.MyTypeHere'
4>c:\source\Tests\UnitTests.Universal\sg.exe : warning : SG0002 : Cannot generate serialization code for type 'MyProjectNameSpace.MyTypeHere'
4>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(886,5): error : System.ArgumentNullException: Value cannot be null.
4>C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\IlcInternals.targets(886,5): error : Parameter name: key
4>C:\Program Files (x86)\MSBuild\Micro
@dotMorten
dotMorten / MainPage.xaml
Created September 4, 2015 22:31
Logical DPI and scale changes all of a sudden
<Page
x:Class="App2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
@dotMorten
dotMorten / RenderCode
Last active October 23, 2015 06:36
XamlRenderingBackgroundTask snippets
internal class GraphTile
{
public static Task CreateTileGraphAsync(Data data, int width, int height, string filename)
{
return RenderAndSaveToFileAsync(GetVisual(data, width, height), (uint)width, (uint)height, filename);
}
public static Task CreateTileGraphAsync(Data data, int width, int height, IRandomAccessStream stream)
{
return RenderAndSaveToStreamAsync(GetVisual(data, width, height), (uint)width, (uint)height, stream);
}