Skip to content

Instantly share code, notes, and snippets.

@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\"
@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 / UltimateEvil.cs
Last active August 29, 2015 13:56
Run this code as 32 bit and 64 bit, and explain why it crashes on 32-bit
using System;
using System.ComponentModel;
using System.Linq;
class Program {
static void Main(string[] args) {
Console.WriteLine("Attributes: " + typeof(Program)
.GetMembers()
.SelectMany(m => m.GetCustomAttributes(true))
.Count()
@SLaks
SLaks / C.cs
Last active August 29, 2015 13:56
VS Bug
using System;
class C {
[MyAttribute]
static void Main(string[] args) {
Console.WriteLine("In Main()");
Console.ReadKey();
}
}
class MyAttribute : Attribute {
@SLaks
SLaks / Notes.md
Created February 17, 2014 04:10
VB Language Service Notes

Microsoft.VisualBasic.SourceFile.GetSymbolAtPosition() - used by Call Hierachy GetPeekSymbolOrNavigationLocationAtPosition() - Peek only? Microsoft.VisualBasic.Editor.ITextBufferExtensions.MaybeGetSourceFileData

Steal Microsoft.VisualBasic.Help.SymbolKeywordFormatter?

@SLaks
SLaks / Duplicate.cs
Last active August 29, 2015 13:56
RQName Inconsistency
void M<X, Y>(X a, Y b) { }
void M<Y, X>(X a, Y b) { }
//Meth(Agg(AggName(S,TypeVarCnt(0))),MethName(M),TypeVarCnt(2),Params(Param(TyVar(X)),Param(TyVar(Y))))
//Meth(Agg(AggName(S,TypeVarCnt(0))),MethName(M),TypeVarCnt(2),Params(Param(TyVar(X)),Param(TyVar(Y))))
//M:S.M``2(``0,``1)
//M:S.M``2(``1,``0)
@SLaks
SLaks / gist:8732804
Created January 31, 2014 14:15
VBCS Coupled Types
System_Object,
System_Enum,
System_MulticastDelegate,
System_Delegate,
System_ValueType,
System_Void,
System_Boolean,
System_Char,
System_SByte,
System_Byte,
@SLaks
SLaks / Boxing.cs
Created January 19, 2014 14:59
Non-boxing generic conversions
static void Main()
{
Console.WriteLine(X<int>.GetValue());
Console.WriteLine(X<long>.GetValue());
}
static class X<T> {
static int IntValue = 42;
static long LongValue = 64;
@SLaks
SLaks / Answer.cs
Created January 9, 2014 22:07
>(<
class X
{
void M<T>() { var x = (M<T>) < new X(); }
public static int operator <(Action a, X x) { return 0; }
public static int operator >(Action a, X x) { return 0; }
}
@SLaks
SLaks / Euler-14.cs
Last active January 1, 2016 18:48
How not to use LINQ to solve Project Euler #14
// http://projecteuler.net/problem=14
Enumerable.Range(1, 1000000).Select(s =>
Enumerable.Repeat(new List<long>(32) { s }, 1)
.First(list =>
Enumerable.Range(0, Int32.MaxValue)
.TakeWhile(i => list.Last() > 1)
.Aggregate(0, (index, unused) => {
list.Add(list.Last() % 2 == 0 ? list.Last() / 2 : 3 * list.Last() + 1);
return 0;