Skip to content

Instantly share code, notes, and snippets.

Avatar
🏁

Wes Higbee g0t4

🏁
View GitHub Profile
@g0t4
g0t4 / links.md
Last active May 10, 2021
Starting Point Files for Jenkins2 Getting Started course
View links.md
@hickford
hickford / group-adjacent-by.cs
Created Apr 1, 2012
GroupAdjacentBy method for .NET in C#
View group-adjacent-by.cs
public static class LINQExtensions
{
public static IEnumerable<IGrouping<TKey, TElement>> GroupAdjacentBy<TElement, TKey>(this IEnumerable<TElement> source, Func<TElement, TKey> keySelector, IEqualityComparer<TKey> comparer=null)
{
comparer = comparer ?? EqualityComparer<TKey>.Default;
List<TElement> elements = null;
TKey key = default(TKey);
TKey lastKey = default(TKey);
foreach (var x in source)
{
@hickford
hickford / buffer-until-calm.cs
Created Mar 29, 2012
BufferUntilCalm method for .NET's Reactive Extensions
View buffer-until-calm.cs
public static class ObservableExtensions
{
/// <summary>
/// Group observable sequence into buffers separated by periods of calm
/// </summary>
/// <param name="source">Observable to buffer</param>
/// <param name="calmDuration">Duration of calm after which to close buffer</param>
/// <param name="maxCount">Max size to buffer before returning</param>
/// <param name="maxDuration">Max duration to buffer before returning</param>
public static IObservable<IList<T>> BufferUntilCalm<T>(this IObservable<T> source, TimeSpan calmDuration, Int32? maxCount=null, TimeSpan? maxDuration = null)