Skip to content

Instantly share code, notes, and snippets.

View briandonahue's full-sized avatar

Brian Donahue briandonahue

View GitHub Profile
using System;
using System.Net;
using System.Security.Principal;
using System.Web.Mvc;
using System.Linq;
namespace Hercules.Web.Helpers
{
public class MyAuthAttribute: AuthorizeAttribute
{
@briandonahue
briandonahue / CustomAuth.cs
Created April 29, 2011 19:07
Simple way to override controller auth at the action level
// New attribute that is only usable at the method (action) level
[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
public class ActionAuthorizeAttribute : AuthorizeAttribute {
}
// New attribute that is only usable at the class (controller) level
[AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
public class ControllerAuthorizeAttribute : AuthorizeAttribute
{
[Subject(typeof (ListingController))]
public class When_loading_page_n_of_potential_listings : SpecFor<ListingController>
{
static PaginatedQuery<ListingSearchCriteria> query;
static PaginatedQueryResult<ListingSearchModel> queryResult;
static JsonResult result;
Establish context = () =>
{
query = new PaginatedQuery<ListingSearchCriteria>();
// Common IoC methods accessed via static gateway
public interface IIoCContainer
{
T GetImplementationOf<T>();
T GetImplementationOf<T>(string key);
object GetImplementationOf(Type typeToResolve);
IEnumerable<T> GetAllImplementationsOf<T>();
}
// Container-specific implementation of IoC interface. When I used Windsor
public interface ICommand<TRequestMessage, TResponseMessage> {
public TResponseMessage Execute(TRequestMessage message);
}
public CreateCustomerCommand: ICommand<CreateCustomerRequest, CreateCustomerResponse>{
public CreateCustomerResponse Execute(CreateCustomerRequest message){
class SomeClass
def sumpm
puts "You found me!"
end
def singleton_class
class << self; self; end
end
def remove_method(method_name)
// Fails with unix transport error: http://a.yfrog.com/img535/4867/5qb.png
Task BuildTaskFromNode(XElement taskNode, int parentId)
{
var id = Convert.ToInt32(taskNode.Attribute("id").Value);
var task = new Task()
{
Type = taskNode.Name.LocalName,
Id = id,
ParentId = parentId,
// Create an observable for MouseLeftButtonDown
var mouseEvents = Observable.FromEvent<MouseButtonEventArgs> (mycontrol, "MouseLeftButtonDown");
//Query the observable just to select the points
var points = from ev in mouseEvents
select ev.EventArgs.GetPosition(this);
//Show points in windows title when ever user presses the left mouse button
points.Subscribe(p => this.Title = "Location = " + p.X + ", " + p.Y);
require 'Albacore'
require 'fileutils'
class DeepCopy
include Logging
attr_accessor :source_dir, :dest_dir, :extensions, :includes, :excludes
def initialize
super()
@extensions = []
dc = DeepCopy.new
dc.extensions = ["dll", "aspx", "ascx", "svc", "asmx", "ashx", "asax", "config", "xap",
"resx", "jpg", "gif", "png", "css", "js", "swf", "lic", "xml", "master",
"dic", "txt", "htm"]
dc.excludes = ["obj/**", "upload/**"]
dc.source_dir = web_src
dc.dest_dir = deploy_target
dc.copy