Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Diagnostics;
using System.IO;
namespace Stuff
{
public static class FileUtilities
{
/// <summary>
/// Will attempt to create the path for a file if it doesn't exist
using System;
using System.Collections.Generic;
namespace StructDesigner.Runtime.Extensions
{
public static class RegisterExtensions
{
/// <summary>
/// Converts an array of registers into a byte array.
/// </summary>
@rquackenbush
rquackenbush / Encapsulate.cs
Created June 6, 2017 18:12
Resharper hasn't seen fit to implement the "encapsulate multiple fields" feature. This is a hacktastic way to encapsulate read only properties.
using System.Linq;
using System.Text;
using System.Windows;
namespace Encapsulate
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow
@rquackenbush
rquackenbush / X509ChainDetails.cs
Created June 30, 2017 15:23
Outputs info on an 509 chain
foreach (var item in chain.ChainElements)
{
_output.WriteLine($"{item.Certificate.SubjectName.Name}");
foreach (var status in item.ChainElementStatus)
{
_output.WriteLine($" {status.Status}: {status.StatusInformation}");
}
}
@rquackenbush
rquackenbush / SizeLimitingStream.cs
Created October 27, 2017 16:14
SizeLimitingStream
using System;
using System.IO;
namespace CaptiveAire.Scada.Module.Base
{
/// <summary>
/// A stream that limits the length of the source stream. This is a fast forward only stream. No seeking allowed.
/// </summary>
public class SizeLimitingStream : Stream
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using CaptiveAire.Scada.Module.Base.Extensions;
namespace CaptiveAire.Scada.Module.Base
{
/// <summary>
/// Treats multiple files as a single stream. Designed to be used on a large file that was downloaded in chunks.
@rquackenbush
rquackenbush / ArrayExtensions.cs
Created October 27, 2017 16:16
Hex formatter
using System.Text;
namespace CaptiveAire.Scada.Module.Base.Extensions
{
public static class ArrayExtensions
{
public static string ToHex(this byte[] bytes, bool upperCase = false)
{
StringBuilder result = new StringBuilder(bytes.Length * 2);
using System;
using System.Collections.Generic;
namespace CaptiveAire.Scada.Module.Base.Extensions
{
public static class IEnumerableExtensions
{
public static int? IndexOfOrNull<T>(this IEnumerable<T> items, Func<T, bool> func)
{
int index = 0;
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Xml.XPath;
using System.Linq;
using System.Text;
namespace CsProjectMigrator
private void LogMonoVersion()
{
try
{
Process process = new Process
{
StartInfo =
{
FileName = "mono",
Arguments = "--version",