Skip to content

Instantly share code, notes, and snippets.

View RichardD2's full-sized avatar

Richard Deeming RichardD2

View GitHub Profile
@RichardD2
RichardD2 / Rss10FeedFormatter.cs
Last active August 29, 2015 14:11
An RSS feed formatter which supports parsing v0.91 format feeds.
/*
* An RSS feed formatter which supports parsing v0.91 format feeds.
*
* Based on:
* http://referencesource.microsoft.com/#System.ServiceModel/System/ServiceModel/Syndication/Rss20FeedFormatter.cs
*/
using System;
using System.Collections.Generic;
using System.Globalization;
@RichardD2
RichardD2 / gist:ef4ee339ce3dcc10264b
Last active August 29, 2015 14:13
WPF Aero Glass Effect
internal static class SafeNativeMethods
{
[DllImport("dwmapi", SetLastError = true)]
private static extern int DwmIsCompositionEnabled([MarshalAs(UnmanagedType.Bool)] out bool isEnabled);
public static bool SafeDwmIsCompositionEnabled()
{
bool result = false;
if (Environment.OSVersion.Version.Major >= 6)
{
@RichardD2
RichardD2 / ComparerExtensions.cs
Created June 17, 2015 15:17
Extension methods for working with IComparer<T> classes.
using System;
using System.Collections.Generic;
namespace NBS.Core.Collections.Generic
{
public static class ComparerExtensions
{
private sealed class ReverseComparer<T> : IComparer<T>
{
public readonly IComparer<T> Original;
@RichardD2
RichardD2 / AsyncThrottle.cs
Last active November 10, 2016 18:56
Async throttle, inspired by code from Stephen Toub's blog - http://blogs.msdn.com/b/pfxteam/
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
public sealed class Throttle
{
private readonly Queue<TaskCompletionSource<IDisposable>> _waiters = new Queue<TaskCompletionSource<IDisposable>>();
private readonly WaitCallback _releaseCoreCallback;
private readonly Task<IDisposable> _releaserTask;
@RichardD2
RichardD2 / MorrisList.cs
Created December 1, 2017 14:00
Morris Sequence
using System;
using System.Collections.Generic;
namespace Morris
{
public sealed class MorrisList : IEnumerable<byte>
{
private sealed class MorrisNode
{
public const int Size = 80000;
@RichardD2
RichardD2 / HtmlElementAttributeTagHelper.cs
Last active June 27, 2018 17:25
ASP.NET Core TagHelper to load element attributes from ViewData.
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Razor.TagHelpers;
namespace AspNetCore.Helpers
{
[HtmlTargetElement(Attributes = ViewBagKeyAttributeName)]
public class HtmlElementAttributeTagHelper : TagHelper
public sealed class AsIsBundleOrderer : IBundleOrderer
{
private AsIsBundleOrderer()
{
}
public static IBundleOrderer Instance { get; } = new AsIsBundleOrderer();
public IEnumerable<BundleFile> OrderFiles(BundleContext context, IEnumerable<BundleFile> files) => files;
}
@RichardD2
RichardD2 / XmlDefaultNamespaceExtensions.cs
Created November 8, 2018 11:26
XLinq extension methods to select elements using the default namespace of the container.
using System;
using System.Collections.Generic;
using System.Linq;
namespace System.Xml.Linq
{
public static class XmlDefaultNamespaceExtensions
{
public static IEnumerable<XElement> DescendantsNs(this XElement container, string name)
=> container.Descendants(container.Name.Namespace + name);
@RichardD2
RichardD2 / SmtpClientExtensions.cs
Last active January 28, 2019 10:35 — forked from mattbenic/SmtpClientExtensions.cs
Extension method to have SmtpClient's SendMailAsync respond to a CancellationToken
using System;
using System.ComponentModel;
using System.Net.Mail;
using System.Threading;
using System.Threading.Tasks;
public static class SmtpClientExtensions
{
/// <summary>
/// Sends the specified message to an SMTP server for delivery as an asynchronous operation.
@RichardD2
RichardD2 / DaylightHours.cs
Last active January 7, 2020 09:49
Sunrise / Sunset calculation
using System;
using System.Diagnostics;
namespace Trinet.Core
{
/// <summary>
/// Represents the time of sunrise and sunset for a date and location.
/// </summary>
/// <remarks>
/// <para>The calculated times have a precision of approximately three mintes.