Skip to content

Instantly share code, notes, and snippets.

@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
@cobysy
cobysy / SqlDependencyPermissions.sql
Last active September 12, 2019 00:48
Minimum Database Permissions Required for SqlDependency
GRANT CREATE PROCEDURE TO [SqlUser];
GRANT CREATE SERVICE TO [SqlUser];
GRANT CREATE QUEUE TO [SqlUser];
GRANT REFERENCES ON CONTRACT::[http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification] TO [SqlUser];
GRANT SUBSCRIBE QUERY NOTIFICATIONS TO [SqlUser];
GRANT CONTROL ON SCHEMA::[dbo] TO [SqlUser];
GRANT IMPERSONATE ON USER::DBO TO [SqlUser];
-- This acually works
-- https://social.msdn.microsoft.com/Forums/sqlserver/en-US/bd195da8-93b2-43c6-8f59-674f5fb9d618/cannot-find-the-queue-sqlquerynotificationserviceguid?forum=sqlservicebroker&prof=required
@cobysy
cobysy / disablewindowsnarrator.reg
Created April 2, 2016 21:01
Disable Windows narrator
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\narrator.exe]
"Debugger"="%1"
@cobysy
cobysy / Deploy dacpac with Powershell on Build vNext.ps1
Last active August 5, 2019 19:52
Deploy dacpac with Powershell on Build vNext
#
# Powershell script that deploys the dacpac to (localdb)\MSSQLLocalDB that the integration tests can run against.
#
$dbname = "xxx"
$dacpacname = "xxx.dacpac"
# Locate dacpac
$dacpac = gci -Recurse -Filter "$dacpacname" -ErrorAction SilentlyContinue | Select -First 1
[AttributeUsage(AttributeTargets.Method)]
public class ValidationActionFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
{
InnerOnActionExecuting(actionContext);
var modelState = actionContext.ModelState;
if (modelState.IsValid)
@cobysy
cobysy / JS-LINQ.js
Created December 18, 2015 15:17 — forked from DanDiplo/JS-LINQ.js
JavaScript equivalents of some common C# LINQ methods. To help me remember!
// JS array equivalents to C# LINQ methods - by Dan B.
// Here's a simple array of "person" objects
var people = [
{ name: "John", age: 20 },
{ name: "Mary", age: 35 },
{ name: "Arthur", age: 78 },
{ name: "Mike", age: 27 },
{ name: "Judy", age: 42 },
{ name: "Tim", age: 8 }
@cobysy
cobysy / jscpd
Last active September 17, 2015 21:15
jscpd options for c#
fix by adding following line
-------------
options.exclude = options.exclude.split ','
in cli.coffee
(Windows path: C:\Users\xxx\AppData\Roaming\npm\node_modules\jscpd\src\cli\)
jscpd -g csharp -o report.txt --exclude **/*.Designer.cs,**/XsdGeneratedClasses.cs