Skip to content

Instantly share code, notes, and snippets.

View carbonrobot's full-sized avatar

Charlie Brown carbonrobot

View GitHub Profile
@carbonrobot
carbonrobot / linqpad.cs
Last active August 29, 2015 13:56
Crypto Checksums for URL Expiration
// this is a linqpad script
// dependencies: bCrypt.Net
void Main()
{
var id = "DOCID123456789";
var token = GenerateToken(id);
var match = DecryptToken(token);
Console.WriteLine(match);
}
public partial class Category(){
public Category(){}
// THESE COME FROM LINQ CLASS
//public int Id { get; set; }
//public string Name { get; set; }
}
public class CategoryService{
public CategoryService(){}
@carbonrobot
carbonrobot / rightClick.directive.js
Created October 15, 2014 19:29
Angular Right Click Directive
(function () {
/*
* @name ngRightClick
* @type Directive
* @desc Binds the right click to a javascript function by using the ng-right-click attribute
*/
function ngRightClick($parse) {
return function (scope, element, attrs) {
@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
@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 / 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
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;}
}
public class BaseViewModel : INotifyPropertyChanged
{
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propertyName)
{
var handler = this.PropertyChanged;
if (handler != null)
@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;
// 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;