Skip to content

Instantly share code, notes, and snippets.

@SLaks
SLaks / C#.cs
Created March 17, 2014 17:18
Zip(...array, cb)
int[] arr1 = { 1, 2, 3 };
int[] arr2 = { 4, 5, 6 };
var result = Enumerable.Zip(arr1, arr2, (a, b) => a + b);
// 5, 7, 9
@SLaks
SLaks / Reference-DLLs.ps1
Created March 24, 2014 23:54
Rename a group of assemblies together
$names =
"Microsoft.VisualStudio.VisualBasic.LanguageService",
"Microsoft.VisualBasic.Editor",
"Microsoft.VisualBasic.LanguageService",
"Microsoft.VisualStudio.CSharp.Services.Language",
"Microsoft.VisualStudio.CSharp.Services.Language.Interop"
$regex = "(" + (($names | ForEach-Object {[System.Text.RegularExpressions.Regex]::Escape($_)}) -join '|') + ")"
$sourceFolder = "...\Ref12\References\v10.0\"
InvalidOperationException, no message, apparently because m_value.CastToReferenceValue() returned null.
> Microsoft.VisualStudio.VIL.Host.dll!Microsoft.VisualStudio.VIL.DebuggerHost.MemoryManager2.VirtualAddress2.WriteReference(Ilrun.Slot value) Unknown
Microsoft.VisualStudio.VIL.Host.dll!Microsoft.VisualStudio.VIL.VisualStudioHost.InspectionFrame.SetVariableValue(Microsoft.VisualStudio.VIL.DebuggerHost.CorValue lVal, Ilrun.Slot rVal) Unknown
Microsoft.VisualStudio.VIL.Host.dll!Microsoft.VisualStudio.VIL.VisualStudioHost.InspectionFrame.SaveModifiedVariables() Unknown
Microsoft.VisualStudio.VIL.Host.dll!Microsoft.VisualStudio.VIL.VisualStudioHost.Interpreter.InterpretInspectionQuery(Microsoft.VisualStudio.Debugger.Evaluation.DkmInspectionContext inspectionContext, Microsoft.VisualStudio.Debugger.CallStack.DkmStackWalkFrame frame, Microsoft.VisualStudio.Debugger.Metadata.Assembly queryAssembly, string expression, string queryClassName, string queryMethodName, Microsoft.VisualStudio.VIL.VisualStudioHost.
@SLaks
SLaks / ReflectionUtils.cs
Created October 28, 2014 02:58
Creates a shim to make an object implement a compatible interface
using System;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using Sigil.NonGeneric;
namespace VSThemeBrowser.VisualStudio {
static class ReflectionUtils {
static readonly AssemblyBuilder assembly = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName("RoslynETAHost"), AssemblyBuilderAccess.Run);
static readonly ModuleBuilder module = assembly.DefineDynamicModule(assembly.GetName().Name);
@SLaks
SLaks / gist:acbf0addcfe07d65ab19
Created October 29, 2014 13:55
Internal Roslyn Exports
Microsoft.CodeAnalysis.Editor.CSharp.EventHookup.IHACK_EventHookupDismissalOnBufferChangePreventerService Microsoft.CodeAnalysis.CSharp.EditorFeatures
Microsoft.CodeAnalysis.Editor.ISignatureHelpProvider Microsoft.CodeAnalysis.EditorFeatures
Microsoft.CodeAnalysis.Editor.IQuickInfoProvider Microsoft.CodeAnalysis.EditorFeatures
Microsoft.CodeAnalysis.Editor.IHighlighter Microsoft.CodeAnalysis.EditorFeatures
Microsoft.CodeAnalysis.Editor.ICommandHandler Microsoft.CodeAnalysis.EditorFeatures
Microsoft.CodeAnalysis.Editor.IBraceMatcher Microsoft.CodeAnalysis.EditorFeatures
Microsoft.CodeAnalysis.Editor.ITextBufferAssociatedViewService Microsoft.CodeAnalysis.EditorFeatures
Microsoft.CodeAnalysis.Editor.ITodoListProvider Microsoft.CodeAnalysis.EditorFeatures
Microsoft.CodeAnalysis.Editor.IPreviewFactoryService Microsoft.CodeAnalysis.EditorFeatures
Microsoft.CodeAnalysis.Editor.Implementation.Outlining.OutliningTaggerProvider Microsoft.CodeAnalysis.EditorFeatures
MoveNext: True
MoveNext: False
MoveNext: True
MoveNext: False
@SLaks
SLaks / 1st YCombinate.cs
Last active August 29, 2015 14:13
LINQ Y Combinator
static void Main() {
var fibonacci = from fib in YCombinate<ulong, ulong>.Definition
select n => n < 2 ? 1 : fib(n - 1) + fib(n - 2);
Console.WriteLine(fibonacci(5));
}
delegate TDelegate Recursive<TDelegate>(TDelegate r);
static class YCombinate<TArg, TReturn> {
public static class Definition {
public static Func<TArg, TReturn> Select(Recursive<Func<TArg, TReturn>> definition) {
@SLaks
SLaks / gist:2e12bd5871c66e417579
Last active August 29, 2015 14:16
Stack trace for settings sync error
System.ArgumentException: The string is empty.
Parameter name: prefix
> Microsoft.Internal.VisualStudio.Shell.Validate.IsNotEmpty(string s, string paramName) Unknown
Microsoft.VisualStudio.Services.Settings.DiskStringStorage.NamesStartingWithInternal(string prefix) Unknown
Microsoft.VisualStudio.Services.Settings.DiskStringStorage.LogExceptions<T>(string name, System.Func<string, T> func, Microsoft.VisualStudio.Settings.Telemetry.SettingScenario scenario, Microsoft.VisualStudio.Settings.Telemetry.SettingAction action, T defaultValue) Unknown
Microsoft.VisualStudio.Services.Settings.DiskStringStorage.NamesStartingWith(string prefix) Unknown
Microsoft.VisualStudio.Services.Settings.DelegatingStringStorage.NamesStartingWith.AnonymousMethod__1(Microsoft.VisualStudio.Settings.IStringStorage v) Unknown
System.Linq.Enumerable.<SelectManyIterator>d__8<TSource, TResult>.MoveNext() Unknown
@SLaks
SLaks / gist:e43f3d534e6f0171d99f
Created March 20, 2015 03:01
Roslyn Debugger Error
Error Evaluation of method System.Collections.Immutable.ImmutableHashSetDebuggerProxy`1[Microsoft.VisualStudio.Composition.RuntimeComposition+RuntimePart].get_Contents() requires use of the static field System.Collections.Immutable.AllocFreeConcurrentStack`1[System.Collections.Immutable.SecurePooledObject`1[System.Collections.Generic.Stack`1[System.Collections.Immutable.RefAsValueType`1[System.Collections.Immutable.SortedInt32KeyNode`1[System.Collections.Immutable.ImmutableHashSet`1+HashBucket[Microsoft.VisualStudio.Composition.RuntimeComposition+RuntimePart]]]]]].stack, which is not available in this context.
@SLaks
SLaks / Snippets.js
Created January 5, 2021 18:19
Console Snippets to manipulate YouTube Music playlists in bulk
// First, load jQuery:
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
////////////////////////////////////////////////////////////////////////////
// Remove all disliked songs:
for (const el of $('ytmusic-responsive-list-item-renderer:has([like-status="DISLIKE"])').get()) {
el.dispatchEvent(new MouseEvent('contextmenu'));