Skip to content

Instantly share code, notes, and snippets.

View fekberg's full-sized avatar

Filip Ekberg fekberg

View GitHub Profile
@fekberg
fekberg / Pattern Matching in C# 8.0
Created March 19, 2020 13:31
Pattern Matching.cs
using System;
using System.Drawing;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
namespace Recrusive_Patterns
{
class Program
{
ERROR [2018-05-14 09:46:20Z]:ERROR [2018-05-14 09:46:20Z]: MSBuild property evaluation failed: [Microsoft.Build.Utilities.ToolLocationHelper]::GetPathToStandardLibraries($(TargetFrameworkIdentifier), $(TargetFrameworkVersion), $(TargetFrameworkProfile), $(PlatformTarget), $(TargetFrameworkRootPath))
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'Microsoft.Build.Collections.MSBuildNameIgnoreCaseComparer' threw an exception. ---> System.EntryPointNotFoundException: GetSystemInfo
at (wrapper managed-to-native) Microsoft.Build.Shared.NativeMethodsShared.GetSystemInfo(Microsoft.Build.Shared.NativeMethodsShared/SYSTEM_INFO&)
at Microsoft.Build.Shared.NativeMethodsShared+SystemIn
@fekberg
fekberg / SOS_Morse.cs
Created December 12, 2013 02:16
Here's how you do SOS Morse Code in C#.
var sequence = Enumerable.Range(0, 3).ToList();
while(true) {
sequence.ForEach(e => Console.Beep(650, 100));
Thread.Sleep(200);
sequence.ForEach(e => Console.Beep(650, 400));
Thread.Sleep(200);
@fekberg
fekberg / UpgradeMEM
Last active December 20, 2015 16:09
Shell script used to increase/decrease memory on my server
#!/bin/bash
# This cronjob runs at least once a minute and will check if the usage of RAM is more than 75%
# if it is more than 75% it sends me an e-mail and invokes the API. API call removed from the example.
# When the percentage left after a possible decrease is 70& then it decreases the RAM to that level
TOTAL=`free | grep Mem: | awk '{print $2}'`
USED=`free | grep Mem: | awk '{print $3}'`
INCREASE=$(((TOTAL/1024)+512));
// http://channel9.msdn.com/Events/Build/2013/4-329
int N = 1000;
var A = new int[N,N];
var B = new int[N, N];
var C = new int[N, N];
var random = new Random();
for(int x = 0; x < N; x++)
{
for(int y = 0; y < N; y++)
@fekberg
fekberg / gist:5137441
Created March 11, 2013 20:27
Deadlock example with async/await
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
namespace DeadlockExample
{
/// <summary>
/// Interaction logic for MainWindow.xaml
@fekberg
fekberg / FekbergBlogFeed.js
Created February 4, 2013 14:46
Share links to my 5 latest articles published on my blog!
<script src="http://feeds.feedburner.com/fekberg?format=sigpro" type="text/javascript" ></script>
<noscript>
<p>Subscribe to RSS headline updates from: <a href="http://feeds.feedburner.com/fekberg"></a><br/>
Powered by FeedBurner</p>
</noscript>
--- Using temporary list --
GetList:
IL_0000: nop
IL_0001: newobj System.Collections.Generic.List<System.String>..ctor
IL_0006: stloc.0
IL_0007: nop
IL_0008: ldarg.0
IL_0009: ldfld UserQuery._names
IL_000E: callvirt System.Collections.Generic.IEnumerable<System.String>.GetEnumerator
IL_0013: stloc.3
@fekberg
fekberg / Listing 10.15.cs
Created September 17, 2012 19:34
Listing 10.15
public IEnumerable<CodeIssue> GetIssues(IDocument document, CommonSyntaxNode node, CancellationToken cancellationToken)
{
if (node.GetType() != typeof(LocalDeclarationStatementSyntax)) return null;
var localDeclaration = (LocalDeclarationStatementSyntax)node;
var semanticModel = document.GetSemanticModel(cancellationToken);
var containingBlock = localDeclaration.FirstAncestorOrSelf<BlockSyntax>();
if (containingBlock == null) return null;
var dataFlowAnalysis = semanticModel.AnalyzeDataFlow(containingBlock);
var variable = localDeclaration.Declaration.Variables.First();
@fekberg
fekberg / Listing 10.12.cs
Created September 17, 2012 19:30
Listing 10.12
var dataFlowAnalysis = semanticModel.AnalyzeDataFlow(containingBlock);
var variable = localDeclaration.Declaration.Variables.First();
var symbol = semanticModel.GetDeclaredSymbol(variable);