Skip to content

Instantly share code, notes, and snippets.

@ngbrown
ngbrown / ArrayHelpers.cs
Created June 18, 2010 15:56
C# Extension Methods
namespace Helpers
{
using System;
/// <summary>
/// A static class of extension methods for <see cref="Array"/>.
/// </summary>
public static class ArrayHelpers
{
/// <summary>
@ngbrown
ngbrown / RandData.cs
Created June 18, 2010 16:14
C# UnitTest Helpers
namespace UnitTestHelpers
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/// <summary>
/// Provides random test data
/// </summary>
@ngbrown
ngbrown / ScanSum.cs
Created June 19, 2010 17:03
Examples of using TextScanner
namespace ScanSum
{
using System;
using System.Globalization;
using System.IO;
using TextScanner;
internal class ScanSum
{
@ngbrown
ngbrown / JetBrains.ExternalAnnotations.xsd
Created August 13, 2011 01:47
Started to define a basic XSD schema for JetBrains external annotations.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="JetBrains.ExternalAnnotations" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:annotation>
<xs:documentation>
<![CDATA[
Usage: You only need to add the following to the assembly element:
<assembly name="Assembly.Name"
xsi:noNamespaceSchemaLocation="http://jetbrains.com/schema/JetBrains.ExternalAnnotations.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
]]>
@ngbrown
ngbrown / WideCharToMultiByteTest.c
Created April 23, 2012 01:06
Demonstrates Windows reading past the source string when using WideCharToMultiByte.
// WideCharToMultiByteTest.c : Demonstrates Windows reading past the source string
// when using WideCharToMultiByte.
// The source problem uses UNICODE_STRING, so it may not be null terminated.
//
#define _WIN32_WINNT 0x400
#include <WinSDKVer.h>
#include <stdio.h>
#include <tchar.h>
@ngbrown
ngbrown / strstartswith.h
Created July 3, 2012 17:52
string starts with
#ifndef STRSTARTSWITH_H_
#define STRSTARTSWITH_H_
// From http://blogs.msdn.com/b/the1/archive/2004/05/07/128242.aspx
#ifndef __GNUC__
template <typename T, size_t N>
char ( &_ArraySizeHelper( T (&array)[N] ))[N];
#define countof(array) (sizeof(_ArraySizeHelper(array)))
#else
@ngbrown
ngbrown / AlphanumComparatorFast.cs
Created October 5, 2012 20:07
Alphanumeric compariter using Linq and an EnumerableComparer.
namespace Utilities
{
using System.Collections;
using System.Collections.Generic;
/// <remarks>
/// From http://www.dotnetperls.com/alphanumeric-sorting
/// </remarks>
public class AlphanumComparatorFast : IComparer<string>, IComparer
{
@ngbrown
ngbrown / GridViewSort.cs
Created October 5, 2012 20:26
Wpf helpers.
namespace Extenders
{
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Documents;
/// <summary>
@ngbrown
ngbrown / WhenGivenAttribute.cs
Created November 9, 2012 19:52
It would be nice if SpecFlow accepted custom attributes based off of StepDefinitionBaseAttribute
namespace StepDefinitions
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using TechTalk.SpecFlow;
using TechTalk.SpecFlow.Assist;
@ngbrown
ngbrown / TileCanvas.cs
Last active December 19, 2015 08:19 — forked from robfe/TileCanvas.cs
TileCanvas updated to be more efficient with adding and removing tiled images.
public class TileCanvas : Canvas
{
public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register(
"ImageSource",
typeof(ImageSource),
typeof(TileCanvas),
new PropertyMetadata(null, ImageSourceChanged));
private Size lastActualSize;