Skip to content

Instantly share code, notes, and snippets.

View KerryRitter's full-sized avatar

Kerry Ritter KerryRitter

View GitHub Profile
@KerryRitter
KerryRitter / gist:729665eb346c4b6bc5cb
Created March 25, 2015 19:24
EntityRelationshipMap
public static void EntityRelationshipMap<T, K>(this ICollection<T> startingCollection, ICollection<T> newCollection,
Func<T, K> selector )
{
var newItemCompareValues = newCollection.Select(selector);
var existingItemCompareValues = startingCollection.Select(selector);
var alternativeTitlesToRemove = startingCollection.Where(at => !newItemCompareValues.Contains(selector(at)));
var alternativeTitlesToAdd = newCollection.Where(at => !existingItemCompareValues.Contains(selector(at)));
foreach (var alternativeTitleToRemove in alternativeTitlesToRemove)
@KerryRitter
KerryRitter / SimpleAzureUploader.cs
Created April 15, 2015 18:03
SimpleAzureUploader is a simple provider to upload files to non-encrypted assets.
/// <summary>
/// This class uploads files to Azure.
/// </summary>
public class SimpleAzureUploader
{
private readonly CloudMediaContext _context;
/// <summary>
/// Initializes a new instance of the <see cref="SimpleAzureUploader"/> class.
@KerryRitter
KerryRitter / SilverlightWebClientExample.cs
Created April 15, 2015 18:13
SilverlightWebClient Example
var requestParameters = new Dictionary
{
{"param1", "value1"},
{"param2", "value2"},
};
var webClient = new SilverlightWebClient();
string response = webClient.UploadValues(new Uri("[uri to post to]"), requestParameters);
var webClient2 = new SilverlightWebClient();
@KerryRitter
KerryRitter / gist:1de4f773391a77214942
Last active September 13, 2016 18:49
AsMockDbSet extension for IEnumerables
public static Mock<DbSet<T>> AsMockDbSet<T>(this IEnumerable<T> data) where T : class
{
var mockSet = new Mock<DbSet<T>>();
var queryable = data.AsQueryable();
mockSet.As<IQueryable<T>>().Setup(m => m.Provider).Returns(() => queryable.Provider);
mockSet.As<IQueryable<T>>().Setup(m => m.Expression).Returns(() => queryable.Expression);
mockSet.As<IQueryable<T>>().Setup(m => m.ElementType).Returns(() => queryable.ElementType);
mockSet.As<IQueryable<T>>().Setup(m => m.GetEnumerator()).Returns(() => queryable.GetEnumerator());
@KerryRitter
KerryRitter / gist:941988c958cf75a6216b
Created June 2, 2015 13:47
Log4Net file logging setup through C#
private static void SetupLogging()
{
var logFolder = GetSetting("LogFolder", @"c:\logs");
var logFile = GetSetting("LogFile", @"c:\logs\MyLog.txt");
if (!Directory.Exists(logFolder))
{
Directory.CreateDirectory(logFolder);
}
var hierarchy = (Hierarchy) LogManager.GetRepository();
hierarchy.Root.RemoveAllAppenders(); /*Remove any other appenders*/
@KerryRitter
KerryRitter / GitRepositoryManager.cs
Created August 26, 2015 21:08
A simple manager class using LibGit2Sharp to interact with a remote Git repository
using System;
using System.IO;
using System.Linq;
using LibGit2Sharp;
namespace GitDeploy
{
public class GitRepositoryManager
{
private readonly string _repoSource;
@KerryRitter
KerryRitter / confirmByTypingDirective.js
Created September 10, 2015 20:16
Confirm-by-typing Directive
/**
* This directive asks the user for a Yes/No confirmation, and then requires the user to type a value to confirm the action.
*
* Usage:
<button confirm-by-typing confirm-action="deleteSite(site)" confirm-value="{{site.Path}}" alert-message="Are you sure you want to delete '{{site.Name}}'?" modal-title="Are you sure you want to delete '{{site.Name}}'?" modal-message="Enter the site path <strong>'{{site.Path}}'</strong> below to confirm.">
Delete
</button>
*/
adminApp.directive("confirmByTyping", ["$modal", function ($modal) {
var getConfirmTypingModalTemplate = function (title, message) {
@KerryRitter
KerryRitter / App Pool Recycle Listener.cs
Created October 29, 2015 17:15
Listens to the event log to detect when app pool recycle events are triggered (IIS must be configured to write these to the logs)
using System;
using System.Diagnostics;
using System.Net;
namespace EventLogListener
{
class Program
{
static void Main(string[] args)
{
@KerryRitter
KerryRitter / IpRangeCalculator.cs
Created October 30, 2015 19:09
Does calculations and math on IP Addresses, CIDR ranges, subnet masks
/// <summary>
/// Class for doing IP Address and network calculations
/// </summary>
public class IpRangeCalculator
{
public readonly Dictionary<string, string> CidrSuffixesForMask = new Dictionary<string, string>
{
{ "255.255.255.255", "32" },
{ "255.255.255.254", "31" },
{ "255.255.255.252", "30" },
@KerryRitter
KerryRitter / authService.js
Last active February 3, 2016 18:06
Angular services for ASP.NET Web API
/// <reference path="../app.js" />
'use strict';
app.factory('authService', ['$http', '$q', '$log', 'apiBaseUrl', 'localStorageService', function ($http, $q, $log, apiBaseUrl, localStorageService) {
var setupHttp = function() {
$http.defaults.headers.common["Content-Type"] = "application/x-www-form-urlencoded";
$http.defaults.headers.common['Authorization'] = "Bearer " + authentication.access_token;
}
var authServiceFactory = {};