Skip to content

Instantly share code, notes, and snippets.

View mizrael's full-sized avatar
😼
my cat owns the keyboard.

David Guida mizrael

😼
my cat owns the keyboard.
View GitHub Profile
var sw = new Stopwatch();
sw.Start();
Foo();
sw.Stop();
// now just log the results somewhere
@mizrael
mizrael / ComplexBuilderUsage.cs
Created July 13, 2018 09:53
Complex builder pattern usage
var builder = new Builder();
builder.WithSomeProperty(42);
// ...throw some business logic here...
builder.WithSomeOtherProperty(computedValue);
// ...some other logic here too...
@mizrael
mizrael / ImmutableBuilder.cs
Last active September 19, 2018 11:24
Immutable Builder Pattern in C#
public class Vehicle {
private Vehicle(string model, int wheelsCount){
this.Model = model;
this.WheelsCount = wheelsCount;
}
public string Model { get; }
public int WheelsCount { get; }
public VehicleBuilder {
@mizrael
mizrael / feature-gating-strategy.ts
Created March 6, 2018 18:19
Feature Gating - check the gates
export class Foo implements IFoo{
constructor(private readonly barStrategy:()=>void){}
public bar(){
this.barStrategy();
}
};
// composition root
const featureService:IFeatureService = new FeatureService(),
strategy1 = ():void =>{ /*...strategy 1...*/ },
@mizrael
mizrael / feature-gating-service.ts
Created March 6, 2018 18:14
Feature Gating - check the gates
interface IFeatureService{
isEnabled(featureName:string):boolean;
}
export class Foo implements IFoo{
constructor(private readonly featureService:IFeatureService){}
public bar(){
if(this.featureService.isEnabled("feature-x")){
/*.......*/
@mizrael
mizrael / feature-gating-static-config.ts
Created March 6, 2018 10:57
Feature Gating - check the gates
interface IFoo{
bar():void;
}
interface FlagsConfig{
featureX:boolean;
}
export class Foo implements IFoo{
constructor(private readonly flagsConfig:FlagsConfig){}
@mizrael
mizrael / feature-gating-example3.js
Last active February 26, 2018 10:43
Feature Gating
function compute_stuff(){
/*...*/
if(checkFeatureIsOn("foo_feature")){
new_amazing_shiny_never_used_function();
}else{
old_tested_reliable_and_lovely_function();
}
/*...*/
}
@mizrael
mizrael / feature-gating-example1.js
Last active February 26, 2018 10:30
Feature gating
function compute_stuff(){
/*...*/
old_tested_reliable_and_lovely_function();
/*...*/
}
@mizrael
mizrael / DbContextExtensions.cs
Created January 26, 2018 14:13
reset the entities state on a Entity Framework Db Context
public static class DbContextExtensions
{
public static void Reset(this DbContext context)
{
var entries = context.ChangeTracker
.Entries()
.Where(e => e.State != EntityState.Unchanged)
.ToArray();
foreach (var entry in entries)
@mizrael
mizrael / NLogUsage.cs
Last active October 6, 2017 20:29
NLog basic initialization
public class MyAwesomeClass{
private static readonly NLog.Logger _logger;
static MyAwesomeClass(){
_logger = NLog.LogManager.GetCurrentClassLogger();
}
}