Skip to content

Instantly share code, notes, and snippets.

@jwcarroll
jwcarroll / ReflectionExtensions.cs
Created April 6, 2011 20:29
Will map a string value to pretty much any primitive type. It also handles lists of values.
public static class ReflectionExtensions
{
public static Boolean Implements<T>(this Type typeToCheck)
{
return typeToCheck.Implements(typeof(T));
}
public static Boolean Implements(this Type typeToCheck, Type typeToCheckFor)
{
if (typeToCheck == null || typeToCheckFor == null) return false;
using System;
using System.Linq;
using System.Text;
using Disruptor;
using Elasticity.Domain;
using Elasticity.Events;
namespace Elasticity.Domain
{
@jwcarroll
jwcarroll / MockPrincipal.cs
Created January 31, 2012 04:57
Mock IPrincipal / IIdentity object that can be used for unit testing security.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;
namespace TechnoFattie.Lib.Tests.Mocks
{
public enum MockPrincipalBehavior
{
@jwcarroll
jwcarroll / modifyConnectionStrings.ps1
Created March 5, 2012 20:56
Set Connection String Powershell Function
Function Set-ConnectionString{
[CmdletBinding(SupportsShouldProcess=$True)]
Param(
[string]$fileName="app.config",
[string]$connectionStringName,
[string]$connectionString
)
$config = [xml](Get-Content -LiteralPath $fileName)
@jwcarroll
jwcarroll / NLB_functions.ps1
Created June 5, 2012 16:08
A set of functions that can be used to automate a cluster using NLB
# Name: Network Load Balancer Functions
# Description: Collection of functions for managing NLB on 2003 machines
# Author: Josh Carroll
Add-Type @'
public class NLBStatusCode
{
public NLBStatusCode(int code, string name, System.ConsoleColor color){
_code = code;
_name = name;
@jwcarroll
jwcarroll / CacheHelper.cs
Created November 12, 2012 17:03
Cache Helper to make using the Memory cache a little easier
public static class CacheHelper
{
private static readonly Object _locker = new object();
public static T GetCacheItem<T>(String key, Func<T> cachePopulate, TimeSpan? slidingExpiration = null, DateTime? absoluteExpiration = null)
{
if(String.IsNullOrWhiteSpace(key)) throw new ArgumentException("Invalid cache key");
if(cachePopulate == null) throw new ArgumentNullException("cachePopulate");
if(slidingExpiration == null && absoluteExpiration == null) throw new ArgumentException("Either a sliding expiration or absolute must be provided");
@jwcarroll
jwcarroll / ExcludeProjectFromStyleCop.ps1
Created February 26, 2013 14:09
A powershell script that will exclude files in a project from StyleCop analysis.
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string]$projectPath,
[string]$filter='*.*',
[switch]$useRegularExpression=$False,
[switch]$undo=$False
)
$ErrorActionPreference = "Stop"
@jwcarroll
jwcarroll / console-mirror.js
Created August 16, 2014 20:40
Shows console output side-by-side in a presentation using Blazon (Present Boldly)
(function (global) {
var toString = Object.prototype.toString;
var $console = global.console;
var util = {
//Lifted from LoDash
isString: function (value) {
return typeof value == 'string' ||
(value && typeof value == 'object' && toString.call(value) == '[object String]') || false;
@jwcarroll
jwcarroll / solution.js
Created June 5, 2015 04:17
Coding Game: Skynet the virus (solution)
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
var mainNetwork = initializeNetwork();
// game loop
while (true) {
var agentIndex = parseInt(readline());
class Foo {
constructor($http, $log, WhateverElse) {
// This is the boilerplate I'm talking about
this.$http = $http;
this.$log = $log;
this.whateverElse = WhateverElse;
// anytime I add something, I have to add it here
// anytime I remove something, I have to remove it from here
// I just don't really see what classes are getting me from
// a reusability/maintainability/readability/whatever standpoint.