Skip to content

Instantly share code, notes, and snippets.

@karlitros
karlitros / HSSFPatriarch.cs
Created October 19, 2012 12:41
An object that allows you to draw things on spreadsheets like textboxes
HSSFPatriarch _patriarch;
@karlitros
karlitros / maxAllowedContentLength.xml
Created October 19, 2012 12:07
New value for the maxAllowedContentLength attribute of the requestLimits element in the web.config. This allows for uploading of much larger files.
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
@karlitros
karlitros / maxRequestLength.xml
Created October 19, 2012 12:06
New value for the maxRequestLength attribute of the httpRuntime element in the web.config
<httpRuntime maxRequestLength="1048576" executionTimeout="3600" />
@karlitros
karlitros / ElmahHandledErrorLoggerFilter.cs
Created October 19, 2012 11:45
Ensures that errors are raised by Elmah in an MVC 3 application. This is referenced in the global.asax.cs file.
public class ElmahHandledErrorLoggerFilter : IExceptionFilter
{
public void OnException(ExceptionContext context)
{
// Log only handled exceptions, because all other will be caught by ELMAH anyway.
if (context.ExceptionHandled)
ErrorSignal.FromCurrentContext().Raise(context.Exception);
}
}
@karlitros
karlitros / New_With_Elmah_Logging_Global.asax.cs
Created October 19, 2012 11:42
New reference to the ElmahHandledErrorLoggerFilter class, which raises the errors to Elmah when customErrors is switched on.
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new ElmahHandledErrorLoggerFilter());
filters.Add(new HandleErrorAttribute());
}
@karlitros
karlitros / Old_No_Logging_Global.asax.cs
Created October 19, 2012 11:39
The old global.asax.cs file that doesn't allow logging when customErrors is switched on.
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
@karlitros
karlitros / GetCellReferenceByCell
Created August 15, 2012 12:49
A function for NPOI that, when provided with an object implementing ICell, will return the cell reference (A1, B2, C3, etc)
/// <summary>
/// Gets the cell reference (A1, B2, etc) by object implementing ICell.
/// </summary>
/// <param name="cell">The cell.</param>
/// <returns>cell reference as string</returns>
private string GetCellReferenceByCell(ICell cell)
{
CellReference cellRef = new CellReference(cell);
return cellRef.FormatAsString();
}
@karlitros
karlitros / LiveUpdate.js
Created July 19, 2012 15:38
SignalR Javascript to allow communication between client and server.
/// <reference path="jquery-1.7.2.js" />
/// <reference path="jquery-ui-1.8.20.js" />
/// <reference path="jquery.signalR-0.5.2.js" />
$(function () {
// Establish a connection to the updateFeed hub
var hub = $.connection.updateFeed;
// Extend the object with our feedUpdated method held within the updateFeed hub
$.extend(hub, {
@karlitros
karlitros / LiveUpdateHub.cs
Created July 19, 2012 15:35
Hub class for SignalR communication between client and server
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SignalR.Hubs;
namespace LiveUpdate.Hubs
{
/// <summary>
/// Skeleton hub class used to establish connections.
@karlitros
karlitros / BroadcastUpdate.cs
Created July 19, 2012 15:27
Broadcasts the update to all connected clients using SignalR. I've done this within the controller to demonstrate server -> client pushing.
/// <summary>
/// Broadcasts the update to all connected clients. I've done this directly in the controller to
/// demonstrate server -> client pushing, rather than client -> client pushing.
/// </summary>
/// <param name="updateItem">The update item.</param>
internal static void BroadcastUpdate(Update updateItem)
{
// Fetch the hub's context to broadcast
IHubContext context = GlobalHost.ConnectionManager.GetHubContext<LiveUpdate.Hubs.LiveUpdateHub>();