Skip to content

Instantly share code, notes, and snippets.

@JamieMason
JamieMason / group-objects-by-property.md
Created Sep 14, 2018
Group Array of JavaScript Objects by Key or Property Value
View group-objects-by-property.md

Group Array of JavaScript Objects by Key or Property Value

Implementation

const groupBy = key => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = obj[key];
    objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
    return objectsByKeyValue;
@kenegozi
kenegozi / XunitConsoleForwarder.cs
Created Jun 25, 2017
Capturing console output in Xunit 2 tests
View XunitConsoleForwarder.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Xunit.Abstractions;
namespace MagicalUnicorns {
public class XunitConsoleForwarder : TextWriter {
private readonly ITestOutputHelper output;
@alexlau811
alexlau811 / ExtendedPageRenderer.cs
Created Feb 22, 2015
Move toolbar items with priority = 0 to LeftBarButtonItems on iOS with Xamarin Forms. Originally written by Murally at http://forums.xamarin.com/discussion/21004/navigation-bar-left-toolbar-button
View ExtendedPageRenderer.cs
[assembly: ExportRenderer(typeof(ContentPage), typeof(ExtendedPageRenderer))]
public class ExtendedPageRenderer : PageRenderer
{
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
var contentPage = this.Element as ContentPage;
if (contentPage == null || NavigationController == null)
@micahlmartin
micahlmartin / gist:4261551
Created Dec 11, 2012
Convert anonymous object to dictionary
View gist:4261551
public static IDictionary<string, object> ToDictionary(this object values)
{
var dict = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
if (values != null)
{
foreach (PropertyDescriptor propertyDescriptor in TypeDescriptor.GetProperties(values))
{
object obj = propertyDescriptor.GetValue(values);
dict.Add(propertyDescriptor.Name, obj);