Skip to content

Instantly share code, notes, and snippets.

@sanjayuttam
sanjayuttam / ProcDump Timed Snapshots
Created April 15, 2014 18:23
Create DMP file on 20s increments
ProcDump: http://technet.microsoft.com/en-us/sysinternals/dd996900.aspx
ProcDump Command that I used: C:\Procdump>procdump.exe -ma w3wp.exe 3rdfix.dmp -n 20
//analyze managed memory
@sanjayuttam
sanjayuttam / Azure WebRole_On_Start
Created November 4, 2013 15:02
Hook for executing on start of an azure web role. This can go into the web project directly.
using Microsoft.Web.Administration;
using Microsoft.WindowsAzure.ServiceRuntime;
using System;
namespace WebRole1
{
public class WebRole : RoleEntryPoint
{
public override bool OnStart()
{
@sanjayuttam
sanjayuttam / WCF Service Behavior
Created October 15, 2013 14:35
Create WCF Service Behavior programmatically
ServiceHost host = new ServiceHost(typeof(SomeService), new Uri("http://localhost:8986"));
WebHttpBinding binding = new WebHttpBinding();
ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(ISomeContractName), binding, "ServiceHost");
WebHttpBehavior httpBehavior = new WebHttpBehavior();
endpoint.Behaviors.Add(httpBehavior);
@sanjayuttam
sanjayuttam / gist:5463272
Created April 25, 2013 21:21
Generate self-signed cert for use on amazon
--Generate self-signed cert for use on amazon
openssl genrsa -out server_privatekey.pem 1024
openssl req -new -key server_privatekey.pem -out server_certificate_csr.pem
openssl x509 -req -days 3650 -in server_certificate_csr.pem -signkey server_privatekey.pem -out server_certificate.pem
)
Certificate Name: mycert
@sanjayuttam
sanjayuttam / GetLastErrorDetail.sql
Created April 17, 2013 21:10
Sql Server, get last error detail
select * from sys.messages where message_id = '18452' and language_id = 1033
NET TIME \\TIMESRV /SET /YES
NET TIME /domain:mydomainname /SET /Y
@sanjayuttam
sanjayuttam / gist:4542783
Created January 15, 2013 22:31
Custom OnException
public class ControllerBase : System.Web.Mvc.Controller
{
protected override void OnException(ExceptionContext filterContext)
{
//Do whatever stuff you'd like
DoSomeOtherStuff();
//Displays a friendly error, doesn't require HandleError
filterContext.ExceptionHandled = true;
this.View("Error").ExecuteResult(this.ControllerContext);
//Displays a friendly error, *requires* HandlError
@sanjayuttam
sanjayuttam / gist:4542761
Created January 15, 2013 22:28
Default OnException
public virtual void OnException(ExceptionContext filterContext)
{
if (filterContext == null)
{
throw new ArgumentNullException("filterContext");
}
if (!filterContext.ExceptionHandled && filterContext.HttpContext.IsCustomErrorEnabled)
{
Exception innerException = filterContext.Exception;
@sanjayuttam
sanjayuttam / gist:4542733
Created January 15, 2013 22:26
Crop image on server side
protected byte[] CropImageFile(byte[] imageFile, int targetW, int targetH, int targetX, int targetY)
{
MemoryStream imgMemoryStream = new MemoryStream();
System.Drawing.Image imgPhoto = System.Drawing.Image.FromStream(new MemoryStream(imageFile));
Bitmap bmPhoto = new Bitmap(targetW, targetH, PixelFormat.Format24bppRgb);