Skip to content

Instantly share code, notes, and snippets.

@house9
house9 / AuthorizeForAttribute.cs
Created April 22, 2011 15:17
AuthorizeForAttribute.cs
public class AuthorizeForAttribute : AuthorizeAttribute
{
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
if(filterContext.HttpContext.Request.IsAjaxRequest())
{
// filterContext.Result = new HttpStatusCodeResult(401, "Unauthorized");
filterContext.Result = new HttpStatusCodeResult(403, "Forbidden");
}
else if(filterContext.HttpContext.User.Identity.IsAuthenticated)
<html>
<head>
<title>css rows and columns</title>
<style type="text/css">
body {
font-family: Verdana;
}
div.rows div.row {
clear:both;
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="/Scripts/lib/jquery/jquery-1.4.4.min.js"%3E%3C/script%3E'))</script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>
<script>!window.jQuery.validator && document.write(unescape('%3Cscript src="/Scripts/lib/jquery/jquery.validate.min.js"%3E%3C/script%3E'))</script>
<script src="//ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.validate.unobtrusive.min.js"></script>
<script>!window.jQuery.validator.unobtrusive && document.write(unescape('%3Cscript src="/Scripts/lib/jquery/jquery.validate.unobtrusive.min.js"%3E%3C/script%3E'))</script>
@Html.JavascriptIncludeFromCdnWithFallback(
"//ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js",
"~/Scripts/lib/jquery/jquery-1.4.4.min.js",
"!window.jQuery"
)
@Html.JavascriptIncludeFromCdnWithFallback(
"//ajax.aspnetcdn.com/ajax/jquery.validate/1.7/jquery.validate.min.js",
"~/Scripts/lib/jquery/jquery.validate.min.js",
"!window.jQuery.validator"
using System;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using System.Web.Routing;
public static class HtmlHelperExtensions
{
/// <summary>
/// render script tag to include javascript file from cdn, but fallback to local if cannot be loaded
/// </summary>
@house9
house9 / TODO-Report.ps1
Created March 14, 2011 15:58
powershell script to generate a TODO report
$fileName = "_2-DO_log.txt"
$max = 20
$encoding = "ASCII"
# remove previous file if exists
if(Test-Path $fileName) { Remove-Item $fileName }
# dump 2-do report to the file system
Get-ChildItem –rec –include *.config,*.cs,*.js,*.cshtml,*.css,*.aspx |
where { $_ -notmatch 'lib' } |
/*
see README: http://github.com/house9/jquery-iframe-auto-height
*/
(function ($) {
$.fn.iframeAutoHeight = function (options) {
// set default option values
var options = $.extend({
heightOffset: 0
}, options);
@house9
house9 / util-jquery-global-ajax-handler-and-spinner.js
Created January 13, 2011 17:49
Util object with Generic Handling of ajax errors when using jquery and spinner on off
/*
util object; setSpinnerNextTo, setSpinnerOff; globalAjaxErrorHandler
assumes you have a property on your namespace of env, most likely set via server side code
YOUR_NAMESPACE.env = "DEVELOPMENT"; // STAGING, PRODUCTION
YOUR_NAMESPACE.env = '<%= Rails.env.upcase %>'; // rails
YOUR_NAMESPACE.env = '<%= ApplicationState %>'; // asp, assuming you have an ApplicationState property :)
initialize the global error handling - http://api.jquery.com/ajaxError
jQuery(document).ajaxError(YOUR_NAMESPACE.util.globalAjaxErrorHandler);
System.Data.DataTable people = GetPeopleData();
AutoMapper.Mapper.Reset();
AutoMapper.Mapper.CreateMap<IDataReader, Person>();
var results = AutoMapper.Mapper.Map<IDataReader, IList<Person>>(people.CreateDataReader());
@house9
house9 / cool date functions in ruby
Created November 5, 2010 23:48
cool date functions in ruby
last_month = Date.today.last_month # => Tue, 05 Oct 2010
last_month.beginning_of_month # => Fri, 01 Oct 2010
last_month.end_of_month # => Sun, 31 Oct 2010
last_month.beginning_of_quarter # => Fri, 01 Oct 2010
last_month.end_of_quarter # => Fri, 31 Dec 2010