Skip to content

Instantly share code, notes, and snippets.

Avatar

Alexander Shvedov controlflow

View GitHub Profile
@RazmikDev
RazmikDev / JetProfile.ps1
Last active Nov 29, 2015
PS profile for ReSharper developers (should replace $profile)
View JetProfile.ps1
# =====================================================================================================================
# Power Plan Management
# ---------------------------------------------------------------------------------------------------------------------
$powerPlans = powercfg -l
$highPerformancePowerPlan = $powerPlans | %{ if ($_.contains("High performance")) { $_.split()[3] }}
$balancedPowerPlan = $powerPlans | %{ if ($_.contains("Balanced")) { $_.split()[3] }}
$powerSaverPowerPlan = $powerPlans | %{ if ($_.contains("Power saver")) {$_.split()[3] }}
$currentPowerPlan = $(powercfg -getactivescheme).split()[3]
function Get-Plan
@Porges
Porges / typedtaglessfinal.cs
Created Jun 17, 2014
Encoding open recursion in C#: not recommended
View typedtaglessfinal.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TypedTaglessFinal
{
View gist:0a8ccbb56e9bbe0714a7
D:\test>csc /o SlowDelegates01.cs
Microsoft (R) Visual C# Compiler version 4.0.30319.34209
for Microsoft (R) .NET Framework 4.5
Copyright (C) Microsoft Corporation. All rights reserved.
D:\test>SlowDelegates01.exe
1 => 00:00:00.0159245
2 => 00:00:00.0147080
3 => 00:00:00.0145497
@controlflow
controlflow / gist:11d6360ea827164aaa1e
Last active Aug 29, 2015
C# 6.0 declaration expressions
View gist:11d6360ea827164aaa1e
// CA "To declaration statement"
{
var t = F(out var x);
// =>
int x;
var t = F(out x);
}
@controlflow
controlflow / gist:9996185
Last active Jan 10, 2018
C# 6.0 null-safe member access/method/indexer call use cases
View gist:9996185
nullness inspection
{
a?.M();
a.F(); // <= possible NRE
a?.M(a != null); // <= expression always true
}
inspection "Redundant null-propagation"
{
var a = new A();
@SLaks
SLaks / UltimateEvil.cs
Last active Aug 29, 2015
Run this code as 32 bit and 64 bit, and explain why it crashes on 32-bit
View UltimateEvil.cs
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()
View gist:8563908
using System;
using System.Runtime.InteropServices;
class Program
{
static void Main()
{
dynamic calc = Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid(148736, 0, 0, 192, 0, 0, 0, 0, 0, 0, 70)));
Console.WriteLine(calc.Evaluate("2+3*5"));
}
View gist:8530850
using System;
class Base
{
private string x = "x".Print();
}
class Derived : Base
{
private string y = "y".Print();
View gist:8444468
using System;
unsafe struct S
{
public void* ptr;
public object obj;
static void Main()
{
S s = default(S);
View gist:8427915
using System;
using N; // This using directive is unused, but cannot be simply removed
static class C
{
static void Ex(this string x) { }
static void Foo(Action<string> x, int y) { }
static void Foo(Action<string> x, string y) { }
static void Foo(Action<string> x, object y) { }
static void Foo(Action<int> x, int y) { }