Skip to content

Instantly share code, notes, and snippets.

View fekberg's full-sized avatar

Filip Ekberg fekberg

View GitHub Profile
@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
// 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 / 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));
@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 / FancyDictionary.cs
Last active August 29, 2015 13:56
Dictionary implementation
void Main()
{
var values = new List<string>();
var dict = new FancyDictionary<string, string>();
var insertWatch = new Stopwatch();
for(int i = 0; i < 3000; i++)
{
var entry = Guid.NewGuid().ToString();
values.Add(entry);
@fekberg
fekberg / DepthFirstSearch.cs
Last active August 29, 2015 13:56
Depth First Search
void Main()
{
// Define all the vertices in the graph
var a = new Vertex<string>{ Value = "A" };
var b = new Vertex<string>{ Value = "B" };
var c = new Vertex<string>{ Value = "C" };
var d = new Vertex<string>{ Value = "D" };
var e = new Vertex<string>{ Value = "E" };
var f = new Vertex<string>{ Value = "F" };
var g = new Vertex<string>{ Value = "G" };
@fekberg
fekberg / Ensure.That.Performance
Created June 4, 2014 23:23
Performance test for Ensure.That
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EnsureThat.Performance
{
class Program
using System.IO;
using System.Linq;
namespace CopyToOneDrive
{
internal class Program
{
private const string _destination = @"C:\Users\YourUserName\OneDrive\Camera Roll";
private const string _source = @"D:\Camera Roll Backup\";
@fekberg
fekberg / deadlock.cs
Last active August 29, 2015 14:17
U NO DEADLOCK?!
/* Android - DOES NOT DEADLOCK */
Task.Run(() =>{
Thread.Sleep(2000);
RunOnUiThread(() => { });
}).Wait();
/* iOS - DEADLOCKS */
Task.Run(() =>{
Thread.Sleep(2000);
InvokeOnMainThread(() => { });
```
And finally, I am proving ownership of the github account by posting this as a gist.
### My publicly-auditable identity:
https://keybase.io/fekberg
### From the command line: