Skip to content

Instantly share code, notes, and snippets.

View aienabled's full-sized avatar

Vladimir Kozlov aienabled

View GitHub Profile
@aienabled
aienabled / AvoidUnityVisualStudioSolutionRegeneration.cs
Last active December 28, 2015 07:03
Avoid (re)generation of the Unity VisualStudio solution file for Unity 5.2+
using SyntaxTree.VisualStudio.Unity.Bridge.Configuration;
using UnityEditor;
/// <summary>
/// Avoid (re)generation of the solution file
/// Unfortunately this settings is hidden since Unity 5.2 (when UnityVS was integrated into VS)
/// HOW TO USE: place into your Assets/Editor folder.
/// https://gist.github.com/aienabled/7f6f3f453042ef905ffd
/// </summary>
[InitializeOnLoad]
@aienabled
aienabled / RoslynWpfToNoesisPreprocessor.cs
Created February 16, 2017 06:15
Preprocessor to make C# code for WPF compatible with NoesisGUI (replace System.Windows namespaces)
public static SyntaxNode ProcessSyntaxTree(
SyntaxTree syntaxTree,
ConcurrentStack<Diagnostic> syntaxTreeProcessingMessages)
{
var replacementsDict = new Dictionary<SyntaxNode, SyntaxNode>(0);
var root = (CompilationUnitSyntax)syntaxTree.GetRoot();
foreach (var usingNode in root.DescendantNodes().OfType<UsingDirectiveSyntax>())
{
var ns = usingNode.Name.GetText().ToString();
@aienabled
aienabled / C# 7.0 ReSharper improvements.md
Last active March 8, 2017 11:47
C# 7.0 pattern matching rewriter for ReSharper (search and replace with pattern, automatic replace)

C# 7.0 brings many syntax improvements and features. One of the most valuable is the new pattern matching syntax. Usually it's used with switch blocks but it has another great use with if conditions. Currently there are no auto-replacement or auto-suggestion for that case in ReSharper yet (at current version 2017.1 EAP 2), but we could easily add it. But first let's consider the problem and improvements C# 7.0 brings us.

Pattern matching at if statement with is operator

For example, consider this code:

if (obj is FooType)
{
 var fooObj = (FooType)obj;
@aienabled
aienabled / Convert-ToPackageReference.ps1
Last active October 12, 2017 04:56 — forked from a4099181/Convert-ToPackageReference.ps1
Converts packages.config into PackageReference at *.csproj project file. Requires XSLT stylesheet available as second file in the gist.
Function Convert-ToPackageReference
{
Param ( [Parameter( Mandatory, ValueFromPipeline )][String] $inputUri,
[String] $stylesheetUri = "https://gist.githubusercontent.com/a4099181/074a6c3dd524ea0d343382137492399c/raw/e2cd1bc88671bb1435569ba9ab1835994aa91725/Convert-ToPackageReference.xsl",
[String] $resultsFile = [System.IO.Path]::GetTempFileName() )
Process {
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform
$xslt.Load( $stylesheetUri )
$xslt.Transform( $inputUri, $resultsFile )
// see https://www.gamasutra.com/blogs/ScottLembcke/20180404/316046/Improved_Lerp_Smoothing.php
public static double LerpWithDeltaTime(double a, double b, double deltaTime, double rate)
{
return Lerp(b, a, Math.Pow(2, -rate * deltaTime));
}
// see https://www.gamasutra.com/blogs/ScottLembcke/20180404/316046/Improved_Lerp_Smoothing.php
public static float LerpWithDeltaTime(float a, float b, float deltaTime, float rate)
{
return Lerp(b, a, Math.Pow(2, -rate * deltaTime));
namespace NoesisGUI.MonoGameWrapper.Helpers.DeviceState
{
using System;
using SharpDX.Direct3D;
using SharpDX.Direct3D11;
using SharpDX.DXGI;
using SharpDX.Mathematics.Interop;
using Buffer = SharpDX.Direct3D11.Buffer;
using Device = SharpDX.Direct3D11.Device;
@aienabled
aienabled / EqualityBenchmark.cs
Last active January 7, 2021 13:26
A C# console program to microbenchmark equality methods. It confirms that there is NO performance difference with `ReferenceEquals` and `==` operator for reference type (class).
using BenchmarkDotNet.Attributes;
public class EqualityBenchmark
{
private const int NumberOfComparisons = 100000;
[Benchmark]
public string EqualityWithOperator()
{
var a = new Foo();
@aienabled
aienabled / TaskThreadSynchronizer.cs
Created April 18, 2023 15:28
C# single-threaded task execution
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
public static class TaskThreadSynchronizer
{
private static readonly object objLock = new();
private static readonly ConcurrentQueue<BaseQueuedTask> queue = new();