Posts

Showing posts from August, 2012

C# Enumerable Split before running Parallel code

[Test] public void SplitWithParallel() { var list = new List< int >( new int [] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}); list.Split(4).AsParallel().ForAll(x => x.ForEach(y => Console.WriteLine(y) /*or run a query*/ )); } public static class Extensions { public static IEnumerable<IEnumerable<T>> Split<T>( this IEnumerable<T> list, int parts) { int i = 0; var splits = from item in list group item by i++%parts into part select part.AsEnumerable(); return splits; } public static void ForEach<T>( this IEnumerable<T> source, Action<T> action) { foreach (var item in source) { action(item); } } }

Remote Desktop Connection Manager

Remote Desktop Connection Manager “RDCMan manages multiple remote desktop connections. It is useful for managing server labs or large server farms where you need regular access to each machine such as automated checkin systems and data centers. It is similar to the built-in MMC Remote Desktops snap-in, but more flexible.”

C# LINQ Pivot

public void TestLinqPivot() { var before = new []{ new {Ticker=" FB ", Type=" BID ", Value=1}, new {Ticker=" FB ", Type=" ASK ", Value=11}, new {Ticker=" IBM ", Type=" BID ", Value=2}, new {Ticker=" IBM ", Type=" ASK ", Value=22} }; Console.WriteLine(" Ticker,Type,Value "); foreach (var item in before) { Console.WriteLine(" {0},{1},{2} ", item.Ticker, item.Type, item.Value); } var after = before.GroupBy(x => x.Ticker).Select( x => new { Ticker = x.Key, BID = x.Where(y => y.Type.Equals(" BID ")).Sum(y => y.Value), ASK = x.Where(y => y.Type.Equals(" ASK ")).Sum(y => y.Value) }); Console.WriteLine(); Console.WriteLine(" Ticker,BID,ASK "); foreach (var item in after) { Console.WriteLine(" {0},{1},{2} ", ite