Skip to content

Instantly share code, notes, and snippets.

@GuyHarwood
GuyHarwood / CustomerController.cs
Last active December 16, 2015 16:08
Returning the location of a newly created resource using Request Uri.
//Taken from http://codebetter.com/glennblock/2012/05/24/two-ways-to-work-with-http-responses-in-apicontroller-httpresponsemessage-and-httpresponseexception/
public class CustomerController : ApiController
{
private ICustomerContext repo;
public CustomerController(ICustomerContext repo)
{
this.repo = repo;
}
@GuyHarwood
GuyHarwood / packages.config
Last active December 16, 2015 19:48
My default Chocolatey package for a new windows dev box. 1) Install Chocolatey 2) open a cmd window 3) cinst packages.config 4) enjoy chocolatey goodness
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="notepadplusplus" />
<package id="fiddler" />
<package id="cmder" />
<package id="sourcetree" />
<package id="TortoiseGit" />
<package id="winrar" />
<package id="rdcman" />
<package id="greenshot" />
@GuyHarwood
GuyHarwood / parse-IIS-Log.cmd
Last active November 9, 2022 17:50
parse raw IIS logs using MS Log Parser into csv file
logparser -i:W3C -o:csv "SELECT * INTO c:\temp\results.csv FROM c:\temp\myLogFile.log"
@GuyHarwood
GuyHarwood / reindexAzure.sql
Created May 11, 2013 08:06
Reindex Azure SQL Database
DECLARE @TableName varchar(255)
DECLARE TableCursor CURSOR FOR
SELECT table_name FROM information_schema.tables
WHERE table_type = 'base table'
OPEN TableCursor
FETCH NEXT FROM TableCursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
exec('ALTER INDEX ALL ON ' + @TableName + ' REBUILD')
@GuyHarwood
GuyHarwood / ParallesVmIpDns.md
Last active February 24, 2016 15:46
Map Parallels VM IP to DNS entry on OSX

sudo dscl localhost -create /Local/Default/Hosts/ridiculous.nonsense.monkeys IPAddress 192.168.0.1

Enter your password when asked, and you can now ping 192.168.0.1 with the name ridiculous.nonsense.monkeys

You can see the results of your work with:

dscl localhost -readall /Local/Default/Hosts

And to undo your handy-work:

@GuyHarwood
GuyHarwood / bs-modal.js
Created May 23, 2013 14:11
auto positioning modal for bootstrap
$('#my-modal').modal({
backdrop: true,
keyboard: true
}).css({
width: 'auto',
'margin-left': function () {
return -($(this).width() / 2);
}
});
[TestFixture]
public class CustomHandleErrorAttributeTests
{
private CustomHandleErrorAttribute sut;
private ExceptionContext exceptionContext;
private readonly Mock<HttpRequestBase> mockRequest= new Mock<HttpRequestBase>();
private readonly Mock<HttpContextBase> mockContext = new Mock<HttpContextBase>();
private readonly Mock<HttpResponseBase> mockResponse = new Mock<HttpResponseBase>();
[SetUp]
@GuyHarwood
GuyHarwood / validateMappings.cs
Created November 28, 2013 09:36
Validate all AutoMapper configurations in one test
[Test]
[Description("Seeks out all implementations of IMappingConfiguration and tests the configuration for missing member mappings")]
public void ValidateAllMappingConfigurations()
{
var webAssembly = typeof (HomeController).Assembly;
var allMappingConfigurations = from typ in webAssembly.GetTypes()
let interfaces = typ.GetInterfaces()
where interfaces.Contains(typeof (IMappingConfiguration))
select typ;
@GuyHarwood
GuyHarwood / log4net.cs
Created January 23, 2014 14:23
Log4net usage patterns
private readonly ILog log = LogManager.GetLogger(typeof (MyType));
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
<log4net>
<root>
<priority value="INFO"/>
<appender-ref ref="RollingFileAppender" />
<appender-ref ref="EventLogAppender" />
@GuyHarwood
GuyHarwood / SelfSignedCert.sh
Created August 8, 2014 09:04
Generate Self Signed Cert with OpenSSL
# Create a certificate authority
openssl genrsa -des3 -out ca.key 1024
openssl req -new -key ca.key -out ca.csr
openssl x509 -req -days 365 -in ca.csr -out ca.crt -signkey ca.key
# Create a server certificate
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr