Skip to content

Instantly share code, notes, and snippets.

@gmanny
gmanny / resolve_type_arguments.py
Created August 5, 2022 10:07
Python generic type argument resolution
def resolve_type_argument(query_type: type, target_type: type | GenericAlias, argument: TypeVar) -> type | TypeVar:
"Resolves a given TypeVar for a generic type `query_type` when supplied by `target_type`"
type_params = query_type.__parameters__
type_arguments = resolve_type_arguments(query_type, target_type)
params_to_args = {key: value for (key, value) in zip(type_params, type_arguments)}
return params_to_args[argument]
@gmanny
gmanny / AdditionalSetup.cs
Created October 31, 2020 17:37
Dark Mode for RoslynPad
using System;
using System.IO;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using Microsoft.CodeAnalysis;
using RoslynPad.Editor;
using WpfAppCommon;
namespace Namespace
@gmanny
gmanny / OptionJsonConverter.cs
Last active May 17, 2022 15:54
JsonConverter for LanguageExt.Option which serializes empty Options as nulls.
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Reflection;
using LanguageExt;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public class OptionJsonConverter : JsonConverter
{
@gmanny
gmanny / goinst.sh
Last active August 29, 2015 14:19 — forked from jmervine/goinst.sh
#!/usr/bin/env bash
#
# Example usage:
#
# $ VERSION=1.3 sudo ./goinst.sh
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
@gmanny
gmanny / AlignableWrapPanel.cs
Created November 13, 2013 15:11
WrapPanel that respects HorizontalAlignment of its children, and fallbacks on the HorizontalContentAlignment property, when child doesn't have the alignment. Base upon this answer: http://stackoverflow.com/a/7747002
public class AlignableWrapPanel : Panel
{
public HorizontalAlignment HorizontalContentAlignment
{
get { return (HorizontalAlignment)GetValue(HorizontalContentAlignmentProperty); }
set { SetValue(HorizontalContentAlignmentProperty, value); }
}
public static readonly DependencyProperty HorizontalContentAlignmentProperty =
DependencyProperty.Register("HorizontalContentAlignment", typeof(HorizontalAlignment), typeof(AlignableWrapPanel), new FrameworkPropertyMetadata(HorizontalAlignment.Left, FrameworkPropertyMetadataOptions.AffectsArrange));