Skip to content

Instantly share code, notes, and snippets.

@cobysy
cobysy / TextFileEncodingDetector.cs
Created August 14, 2017 14:40 — forked from TaoK/TextFileEncodingDetector.cs
Simple class to automatically detect text file encoding, with English-biased "best guess" heuristic based on byte patterns in the absence of BOM.
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
namespace KlerksSoft
{
public static class TextFileEncodingDetector
{
/*
@cobysy
cobysy / AutoFixture-notes.cs
Created June 26, 2017 00:28
AutoFixture notes
// In order to inject dependencies through constructor parameters,
// use greedy constructor selection (versus modest constructor query/ModestConstructorQuery)
// http://blog.ploeh.dk/2011/04/19/ConstructorstrategiesforAutoFixture/
//
// OmitAutoProperties to stop it from mocking out properties
// See https://github.com/AutoFixture/AutoFixture/issues/320 for combo of GreedyConstructorQuery and OmitAutoProperties
AutoFixture.Customize<T>(c => c.FromFactory(new MethodInvoker(new GreedyConstructorQuery())).OmitAutoProperties());
// Trace construction of objects
AutoFixture.Behaviors.Add(new TracingBehavior());
@cobysy
cobysy / Cadence Pyramid Workout.md
Last active April 23, 2017 02:51
Cadence Pyramid Workout

Warm-up 10 minutes. Build up from easy to a steady pace for a few minutes.

Cadence pyramids Do the following progression two to three times with 10 minutes of easy/steady riding in between:

  • 100 r.p.m.
  • 105 r.p.m.
  • 110 r.p.m.
  • 115 r.p.m.
  • 120 r.p.m.
@cobysy
cobysy / how-to-delete-b2c-tenant.txt
Last active June 30, 2016 08:39
not-able-to-delete-b2c-tenant?
https://social.msdn.microsoft.com/Forums/azure/en-US/afbfb7b3-92c9-4af6-9128-ba96795de5a6/not-able-to-delete-b2c-tenant?forum=WindowsAzureAD
Please follow the following steps:
Create Temporary Admin Account
1. Open a browser and login to https://manage.windowsazure.com
2. In the left hand menu navigate to Active Directory, and select your directory
3. Click Users and Groups > Add User
4. Create this user with a username of [email protected] and be sure to grant this user the role Global Administrator
@cobysy
cobysy / GUIDE TIL PÅKLÆDNING - CYKLING.md
Created May 8, 2016 21:55
GUIDE TIL PÅKLÆDNING - CYKLING

GUIDE TIL PÅKLÆDNING - CYKLING

OM "GUIDE TIL PÅKLÆDNING" Denne guide er til dig, der er lidt usikker på, hvordan man skal klæde sig på til en tur på raceren i efteråret og de tidlige vintermåneder. Får man for lidt tøj på kan turen næsten være ødelagt inden man kommer i gang og får man for meget tøj på føler man sig som en svedende russer i en sauna. Læs med og få styr på temperaturen og udstyret!

  • 20 GRADER Solen skinner, der er kun svag vind og du skal ud med klubben og vise farverne frem. Korte bukser, korte ærmer og måske lidt løse ærmer, til når du triller hjemad. Et lille regnslag i baglommen hvis du rammer en sommerbyge, men ellers er solcreme det vigtigste element.
@cobysy
cobysy / PermissionsAttribute.cs
Created April 29, 2016 19:39
Custom AuthorizeAttribute to auth swagger
/// <summary>
/// PermissionsAttribute class
/// </summary>
public class PermissionsAttribute : AuthorizeAttribute
{
/// <summary>
/// Gets called on authorization
/// </summary>
/// <param name="actionContext"></param>
public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
@cobysy
cobysy / Example.cs
Created April 23, 2016 15:25
Generic C# Resource Pool that manages a synchronized access of (theoretically) infinite callers of a restricted count of resource items.
// ==========================================================
// The real resource
class InternalResource {
public void DoSomething() { }
}
// ==========================================================
// The external wrapper returned to the consumer
class MyResource : IDisposable {
private PoolItem<InternalResource> _poolItem;
@cobysy
cobysy / ExampleDTO.cs
Last active April 20, 2016 11:09
DynamicObject that is serializable
public class DTO : SerializableDynamicObject
{
[Required]
public DTOEventType EventType
{
get { return GetValue<DTOEventType>(nameof(EventType)); }
set { SetValue(nameof(EventType), value); }
}
}
@cobysy
cobysy / Automocking dependencies in unit tests for C# with AutoFixture.cs
Created April 16, 2016 23:31
Automocking dependencies in unit tests for C# with AutoFixture
[Fact]
public void WithAutoFixture()
{
var fixture = new Fixture();
fixture.Customize(new AutoMoqCustomization()); // set up automocking
var dependency1stub = fixture.Freeze<Mock<IDependecy1>>();
var dependency2mock = fixture.Freeze<Mock<IDependecy2>>();
dependency1stub.Setup(x => x.SomeQuery()).Returns(2);
@cobysy
cobysy / gist:b1f3e363de58cec5e22f96a063d92e9d
Created April 15, 2016 22:33
Delete git branch in VSTS
Delete a Git branch both locally and remotely
To delete any branch from VSO, you have to enable Alternate Authentication Credentials
Open VSO web browser.
Click on your name in the top right
Click on My Profile
Click on Credentials
Configure Alternate Authentication Credentials
Now open Visual Studio
Connect VSO.
Click on Team Explorer