Skip to content

Instantly share code, notes, and snippets.

@lski
lski / HtmlHelperExtensions.cs
Created July 30, 2014 08:50
Mvc Helper for dumping raw javascript to a view (handles raw dates too)
using System;
using System.Web.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
public static class HtmlHelperExtensions {
/// <summary>
/// Dumps a JSON object to a view, in javascript format rather than as a string
/// </summary>
@lski
lski / IIdentityExt.cs
Created July 31, 2014 09:48
An additional extension method for attempting to get the Guid out of a claims identity object
using System;
using System.Security.Principal;
namespace Microsoft.AspNet.Identity {
public static class IIdentityExt {
public static Guid GetGuid(this IIdentity identity) {
var result = Guid.Empty;
@lski
lski / OwinRequestExt.cs
Last active August 29, 2015 14:04
Really basic method for calculating if a request is an ajax/data request
using System;
namespace Microsoft.Owin {
public static class OwinRequestExt {
/// <summary>
/// Really basic method for calculating if a request is an ajax/data request
/// </summary>
public static bool IsAjaxRequest(this IOwinRequest request) {
@lski
lski / HttpRequestMessageExt.cs
Created July 31, 2014 10:43
Returns the Clients Ip Address from the Request message
using System.Web;
namespace System.Net.Http {
public static class HttpRequestMessageExt {
/// <summary>
/// Returns the Clients Ip Address from the Request message
///
/// Note: Use owin context version Request.GetOwinContext().Request.RemoteIpAddress (owin context can also be retrieved from (OwinContext)request.Properties["MS_OwinContext"]
@lski
lski / amd-template.js
Last active August 29, 2015 14:04
A simple empty template for creating a reuseable module in javascript, that either runs as an amd module or as vanilla code
/*jslint browser: true, white: true */
/*global define, window */
;(function(factory) {
"use strict";
// simply the dependanices required for this module pass in either required module names or the raw objects if amd not found
if (typeof define === 'function' && define['amd']) {
define([], factory);
@lski
lski / Redirection.cs
Created August 22, 2014 08:39
To get round the issue of a try/catch/finally being disrupted by transfer and redirection, fill the details of the redirection in this class and run at the end of finally if not null.
/// <summary>
/// To get round the issue of a try/catch/finally being disrupted by transfer and redirection, fill the details of the redirection in this class and run at the end of finally if not null.
/// </summary>
public class Redirection
{
public enum TransferType
{
Redirect,
Transfer
}
@lski
lski / jquery-columnPosition
Created August 23, 2014 16:58
jQuery plugin to return the zero based column position of a table cell, regardless of colspans
/**
* An extension to JQuery that returns the actual column position of the table cell regardless of columns hvaing a colspan
*
* returns column index (zerobased)
*
* Based on code from SolutionYogi on stackoverflow
* http://stackoverflow.com/questions/1166452/finding-column-index-using-jquery-when-table-contains-column-spanning-cells
*/
(function($) {
@lski
lski / bring-online.sql
Created September 6, 2014 12:49
Bring all offline databases back online TSQL 2000
DECLARE @name VARCHAR(50) -- database name
DECLARE db_cursor CURSOR FOR
SELECT name
FROM master.dbo.sysdatabases
where DATABASEPROPERTYEX(name, 'Status') = 'OFFLINE'
ORDER BY 1
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @name
@lski
lski / HtmlActionResult.cs
Last active August 29, 2015 14:06
An IHttpActionResult that returns cached views with models requires RazorEngine
using System.Linq;
using Newtonsoft.Json;
using RazorEngine.Configuration;
using RazorEngine.Templating;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.RegularExpressions;
using System.Threading;
@lski
lski / addeventlistener-shim.min.js
Last active March 25, 2016 16:08
addEventListener/removeEventListener/dispatchEvent - Deprecated use lski/addeventlistener-with-dispatch instead
!function(){"use strict;";function e(e){var t=this,n=e.eventName||e.type;if(t.fireEvent&&r["on"+n])t.fireEvent("on"+n,e);else if(t[n]&&"function"==typeof t[n])t[n](e);else if(t["on"+n]&&"function"==typeof t["on"+n])t["on"+n](e);else for(var a=0,p=o.length;p>a;a++){var i=o[a];if(this===i.object&&i.type===e.eventName){i.wrapper.call(t,e);break}}}function t(e,t){var n=this,r=function(e){e.target=e.srcElement,e.currentTarget=n,t.handleEvent?t.handleEvent(e):t.call(n,e)};if("DOMContentLoaded"==e){var a=function(e){"interactive"===document.readyState&&r(e)};/interactive|complete|loaded/.test(document.readyState)||(document.attachEvent("onreadystatechange",a),o.push({object:n,type:e,listener:t,wrapper:a}))}else n.attachEvent("on"+e,r),o.push({object:n,type:e,listener:t,wrapper:r})}function n(e,t){for(var n=0;n<o.length;){var r=o[n];if(r.object==this&&r.type==e&&r.listener==t){var a="DOMContentLoaded"===e?"onreadystatechange":"on"+e;this.detachEvent(a,r.wrapper);break}++n}}if(Event.prototype.preventDefault||(Event.pr