Skip to content

Instantly share code, notes, and snippets.

@SLaks
SLaks / DesignerThemeDictionary.cs
Created December 22, 2013 02:28
Trying to create a design-time ResourceDictionary of VS theme colors
using System;
using System.Collections;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Microsoft.Internal.VisualStudio.PlatformUI;
using Microsoft.Internal.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Platform.WindowManagement;
using Microsoft.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.Shell;
@SLaks
SLaks / SourceParser.cs
Created December 22, 2013 03:36
Parses PDBs from http://referencesource.microsoft.com/netframework.aspx and extracts source files to findable locations
//const string OriginalPath = @"C:\Users\SSL\Development\RefSrc\Source";
const string PDBPath = @"C:\Users\SSL\Development\Symbols\RefSrc\Symbols";
const string OriginalPath = @"C:\Users\SSL\Development\Symbols\RefSrc\Source\.NET 4.5\4.6.0.0";
const string TargetPath = @"C:\Users\SSL\Development\3rd-Party Source\Microsoft\.Net 4.5.1";
const string ErrorLog = TargetPath + @"\Errors.log";
static readonly Regex GoodLine = new Regex(@"^[a-zA-Z0-9\\:]{5}");
void Main() {
var pdbs = from file in Directory.EnumerateFiles(PDBPath, "*.pdb", SearchOption.AllDirectories)
group file by Path.GetFileName(file) into g
select g.OrderByDescending(p => new FileInfo(p).Length).First();
@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;
@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 / 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 / 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 / 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 / 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 / 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 / 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()