Skip to content

Instantly share code, notes, and snippets.

public class Attribute : ActionFilterAttribute {
public override void OnActionExecuted(ActionExecutedContext filterContext) {
base.OnActionExecuted(filterContext);
if (!filterContext.ExceptionHandled) {
var exception = filterContext.Exception;
if (exception is CustomException) {
filterContext.Controller.ViewData.ModelState.Add(String.Empty, Resource.CustomExceptionMessage);
}
@alexbeletsky
alexbeletsky / gist:1259608
Created October 3, 2011 17:06
Running SSH under web application
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Diagnostics;
using System.IO;
// Please try to run both: Cassini and IIS.
// For IIS select Application Pool with Process Identity == Your identity
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcForDebug2.Infrastructure {
public class ServiceAttribute : ActionFilterAttribute {
public override void OnActionExecuted(ActionExecutedContext filterContext) {
if (filterContext.RequestContext.HttpContext.Request.IsAjaxRequest()) {
@alexbeletsky
alexbeletsky / gist:1325577
Created October 30, 2011 06:19
ASP.NET MVC2 Views web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<!--
Enabling request validation in view pages would cause validation to occur
public interface IMapper<TInput, TOutput>
{
TOutput Map(TInput input);
}
public interface ICompositeMapper<TInput, TOutput>
{
TOutput[] Map(TInput input);
}
@alexbeletsky
alexbeletsky / gist:1722396
Created February 2, 2012 08:44
Moq and NSubstitute tests
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NSubstitute;
using Moq;
namespace NewTools
{
@alexbeletsky
alexbeletsky / gist:1836711
Created February 15, 2012 15:32
Sublime Text 2 Build System for .NET solutions
{
"shell": true,
"working_dir": "${project_path:${folder}}",
"cmd": ["%WINDIR%\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild", "${project_base_name}.sln"]
}
@alexbeletsky
alexbeletsky / gist:1884547
Created February 22, 2012 12:11
My git config
[user]
name = alexander.beletsky
email = alexander.beletsky@gmail.com
[alias]
lg = log --all --graph --pretty=format:'%C(bold blue)<%an>%Creset %Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ci)%Creset' --abbrev-commit
[merge]
tool = p4merge
[diff]
tool = p4diff
@alexbeletsky
alexbeletsky / gist:2626946
Created May 7, 2012 09:45
CS101 - Simple Web Crawler (week 3)
import urllib2
def web_request(url):
response = urllib2.urlopen(url)
return response.read()
def get_next_link(page):
href = '<a href="';
start_pos = page.find(href)
if start_pos > 0:
@alexbeletsky
alexbeletsky / gist:2757731
Created May 20, 2012 11:37
CS101 - Simple Web Crawler (week 4)
import urllib2
def get_html_body(html):
openTag = '<body>'
closeTag = '</body>'
bodyBegins = html.find(openTag) + len(openTag)
bodyEnds = html.find(closeTag, bodyBegins)
return html[bodyBegins:bodyEnds]