Skip to content

Instantly share code, notes, and snippets.

View cameronsjo's full-sized avatar

Cameron Sjo cameronsjo

View GitHub Profile
@cameronsjo
cameronsjo / gist:06e435e298f6a873d8518cd4d1a64127
Created August 10, 2016 20:18 — forked from rarous/gist:3529050
Generate MetaProj file from solution
$env:MSBuildEmitSolution=1
msbuild FooBar.sln /t:ValidateSolutionConfiguration
$env:MSBuildEmitSolution=0
async Task Main()
{
var checkoutQueue = new System.Collections.Concurrent.BlockingCollection<string>(new ConcurrentQueue<string>());
var searchQueue = new System.Collections.Concurrent.BlockingCollection<string>(new ConcurrentQueue<string>());
var queues = new
{
Checkout = checkoutQueue,
Search = searchQueue
};
public static string PrettyPrintXml(this string xml)
{
using (var stream = new MemoryStream())
using (var writer = new XmlTextWriter(stream, Encoding.Unicode))
{
var document = new XmlDocument();
// Load the XmlDocument with the XML.
document.LoadXml(xml);
writer.Formatting = Formatting.Indented;
public IEnumerable<string> GetRanges(IEnumerable<int> values)
{
// Get the distinct sorted values.
var sorted = values.Distinct()
.OrderBy(v => v)
.ToArray();
// We use a hashset, because it's the fastest way to see if a value has already been consumed.
var used = new HashSet<int>();
var output = new List<string>();
using System;
using System.Collections;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Http;
using System.Web.Http.Controllers;
namespace Filters
public static DateTime Truncate(this DateTime date, DateTimeResolution resolution = DateTimeResolution.Hour)
{
switch (resolution)
{
case DateTimeResolution.Year:
return new DateTime(date.Year, 1, 1);
case DateTimeResolution.Month:
return new DateTime(date.Year, date.Month, 1);
/// <summary>
/// Compares an object against two other objects (upper and lower bound objects) to see if the value is between them.
/// </summary>
/// <typeparam name="T">Type of the object</typeparam>
/// <param name="obj">Object for value to be compared against.</param>
/// <param name="lower">Lower bound of the comparison</param>
/// <param name="upper">Upper bound of the comparison</param>
/// <param name="options">Options for performing the between</param>
/// <returns>Returns true if the value is between the two bounds.</returns>
public static bool Between<T>(this T obj, T lower, T upper, BetweenOptions options = BetweenOptions.Default) where T : IComparable<T>
public static Dictionary<TKey, TValue> ToReverseDictionary<TModel, TKey, TValue>(this IEnumerable<TModel> collection,
Func<TModel, IEnumerable<TKey>> keySelector,
Func<TModel, TValue> valueSelector)
{
var dictionary = new Dictionary<TKey,TValue>();
foreach (var item in collection)
{
var value = valueSelector.Invoke(item);
<Query Kind="Program" />
void Main()
{
var file = FileIO.GetFile();
var assembly = Assembly.LoadFile(file);
var types = new Dictionary<int, dynamic>();
public static double StdDev<T>(this IEnumerable<T> list, Func<T, double> values)
{
// Reference: http://stackoverflow.com/questions/2253874/linq-equivalent-for-standard-deviation
// Reference: http://warrenseen.com/blog/2006/03/13/how-to-calculate-standard-deviation/
var mean = 0.0;
var sum = 0.0;
var stdDev = 0.0;
var n = 0;
foreach (var value in list.Select(values))