Skip to content

Instantly share code, notes, and snippets.

View carbonrobot's full-sized avatar

Charlie Brown carbonrobot

View GitHub Profile
void Main() // Paste this in LINQPad for easiest use
{
Foo a = new Foo();
a.Bar += (s,e) => Console.WriteLine("Start");
AddHandler(a, "Hello");
AddHandler(a, "Hello");
a.DoBar(); // I want this to print Hello, not Hello Hello. How? <-------- QUESTION
}
void Main() // Paste this in LINQPad for easiest use
{
Foo a = new Foo();
AddHandler(a, "Hello");
AddHandler(a, "Hello");
a.DoBar(); // I want this to print Hello, not Hello Hello. How? <-------- QUESTION
}
void AddHandler(Foo obj, string msg)
{
@carbonrobot
carbonrobot / resign.js
Last active August 29, 2015 14:15
How to write your resignation
After ___[1]___,
I have decided to leave ___[0]___ in order to ___[2]___.
While this was not an easy decision for me, ___[3]___.
I have ___[4]___ my time here and will___[5]___.
___[0]___ has been ___[6]___ and I will always ___[7]___.
I look forward to___[8]___ and wish you all ___[9]___.
Until ___[10]___,
I bid you all adieu.
// Type: System.Drawing.Point
// Assembly: System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// MVID: 197EE30F-EB0D-4311-9EFC-B3622162A2BB
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Drawing.dll
using System;
using System.ComponentModel;
using System.Globalization;
using System.Runtime;
using System.Runtime.InteropServices;
@carbonrobot
carbonrobot / linqpadtest.cs
Created February 11, 2015 20:03
Unit testing in Linqpad
public interface IRunner { void Execute(); }
// Add any unit tests by implementing IRunner and Linqpad will run it
public class UserTest_1 : IRunner
{
public void Execute()
{
Debug.WriteLine("Beginning test");
var x = 4 + 5;
public class BaseViewModel : INotifyPropertyChanged
{
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propertyName)
{
var handler = this.PropertyChanged;
if (handler != null)
public class Junk {
public string UnicornName {get; set;}
public string UnicornCity {get; set;}
public string FoodName {get; set;}
}
public class Unicorn {
public string Name {get;set;}
public string City {get;set;}
public IList<MagicFood> Food {get; set;}
}
@carbonrobot
carbonrobot / 1_usage.cs
Last active August 29, 2015 14:09
Aggregate Service Boundary
// Here we inject the specific data provider and logger
// We can easlity swap these out for unit testing, and during runtime they can be injected with any DI framework
// The important takeaway is that the PatientService defines it's dependencies and they must be injected.
// This ensures there are no 'magic' dependencies that we dont know about outside of the constructor.
var data = new Core.Data.SqlDataProvider();
var logging = new Core.Services.LoggingService();
var service = new Core.Services.PatientService(dataProvider, logging);
// In the Core.Models assembly, we could manipulate objects to our hearts content, having very granular control
// The service is our aggregate boundary to the business objects that we allow our application to work with
@carbonrobot
carbonrobot / UTCDateTimeModelBinder.cs
Last active August 29, 2015 14:08
UTCDateTimeModelBinder
public class UtcDateTime
{
public UtcDateTime()
{
}
/// <summary>
/// Gets or sets the UTC DateTime. To get a local datetime, use the ToLocal() method.
/// </summary>
public DateTime DateTime { get; set; }
@carbonrobot
carbonrobot / objects.js
Created October 27, 2014 18:37
Objects
// defining an object using JSON (javascript object syntax)
var person = {
name: 'John',
age: 21
};
// Later, if I want to SET a property
person.name = 'Mike';
// Or, I might want to GET a property