Skip to content

Instantly share code, notes, and snippets.

View Fireforge's full-sized avatar

David Salter Fireforge

View GitHub Profile
@Fireforge
Fireforge / Sequential.cs
Created December 13, 2016 23:49
A Sequential.Invoke function to use as a baseline for Parallel.Invoke performance test
public static class Sequential
{
public static void Invoke(params System.Action[] actions)
{
foreach (var a in actions)
a.Invoke();
}
}
@Fireforge
Fireforge / push.ps1
Last active December 16, 2016 22:17
Nuget push script, more advanced
#
# push.ps1
#
# Push all Nuget packages to Artifactory if the package version has been updated. Checks to make sure that there was not a
# previous push of the same version using Git tags.
##### USER PARAMETERS
param (
[string[]]$csproj_list = $(gci *.csproj),
[string]$source = "artifactory-vt",
@Fireforge
Fireforge / C# Marshal Extensions
Created July 7, 2016 20:58
Useful extensions to the Marshal utilities in C#
public static class MarshalExt
{
// Only needed for .NET 4.5 and earlier
public static T PtrToStructure<T>(IntPtr ptr)
{
return (T)Marshal.PtrToStructure(ptr, typeof(T));
}
public static T[] PtrToStructureArray<T>(IntPtr ptr, int count)
{
@Fireforge
Fireforge / HTTPListener AddAddress
Created April 12, 2016 21:07
Using netsh to add the URL used by HTTPListener
/// <summary>
/// Reserve the URL we'll be using for this session for a given user on a given domain
/// Source: http://stackoverflow.com/questions/14962334/httplistenerexception-access-denied-for-non-admins on Oct 09, 2014
/// </summary>
/// <param name="address">URL (something like http://<ip_address>:<port>/)</param>
/// <param name="domain">Domain name (the current one is from Environment.UserDomainName)</param>
/// <param name="user">User name (the current one is from Environment.UserName)</param>
public static void AddAddress(this HttpListener listener, string address, string domain, string user)
{
string args = string.Format(@"http add urlacl url={0}", address) + " user=\"" + domain + "\\" + user + "\"";
@Fireforge
Fireforge / IEnumerableContinuous.cs
Created March 3, 2016 15:58
Simple IEnumerable functions to find continuous sections
/// <summary>
/// Finds sections of the given IEnumerable<bool> that are continuously true
/// </summary>
/// <param name="src">Any IEnumerable<bool></param>
/// <returns>An IEnumerable<Tuple<int, int> where each pair represents the start and end index that is continuously true</returns>
private IEnumerable<Tuple<int, int>> FindContinuousTrue(IEnumerable<bool> src)
{
var res = new Collection<Tuple<int, int>>();
var srclist = src.ToList();
@Fireforge
Fireforge / push.ps1
Last active January 27, 2016 21:48
Nuget Package push Powershell script
#
# push.ps1
#
# A simple script to package and push a Nuget package from a Visual Studio C# project.
# `nuget.exe` must be on the path or otherwise available to the script (Package Manager Console)
Set-Location -Path $PSScriptRoot
# project parameters
$projname = "MyProject"
@Fireforge
Fireforge / push_replace.ps1
Last active October 25, 2019 18:59
Nuget Package push Powershell script with debug/release specific files
#
# push_replace.ps1
#
# This script is designed to produce customized release and debug nupkgs from a Visual Studio C# project. This is especially useful
# for nupkgs that include native DLLs that are different depending upon debug or release mode.
#
# How to use:
# In your .nuspec file in the <files> section, add the following line:
# <file src="$filelist$" target="lib\native" />
# That line is set to go to lib\native because this script was made for handling native DLLs, but that target can be anything.
@Fireforge
Fireforge / C# Resource Accessing Static Functions
Last active December 14, 2016 15:35
A class of helpful static functions for accessing files in the Resources folder in various ways
public class AssemblyResources
{
public static bool ResourceExists(string resourceName)
{
return Assembly.GetExecutingAssembly().GetManifestResourceNames().Contains(GetResourcePath(resourceName));
}
public static string GetResourcePath(string resourceName) => $"{Assembly.GetExecutingAssembly().GetName().Name}.Resources.{resourceName}";
public static Stream GetStream(string resourceName)
@Fireforge
Fireforge / INotifyPropertyChanged Boilerplate
Last active September 6, 2017 15:48
Caliburn.Micro compliant PropChangedBase - https://dotnetfiddle.net/Fsiq61
// C# 6.0 and up:
public class PropertyChangedBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged = delegate { };
protected void NotifyOfPropertyChange(string name)
{
PropertyChanged(this, new PropertyChangedEventArgs(name));
}
}
@Fireforge
Fireforge / INotifyPropertyChanged Boilerplate
Last active August 29, 2015 14:11
Intelligent boilerplate for INotifyPropertyChanged, mostly taken from http://stackoverflow.com/a/1316417
#region INotifyPropertyChanged Boilerplate
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string propname)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propname));
}