Skip to content

Instantly share code, notes, and snippets.

View tugberkugurlu's full-sized avatar
:shipit:
💥 shakalaka

Tugberk Ugurlu tugberkugurlu

:shipit:
💥 shakalaka
View GitHub Profile
@tugberkugurlu
tugberkugurlu / gist:3848783
Created October 7, 2012 16:13 — forked from benfoster/gist:3848715
Adding IServiceProvider to ValidationContext in ASP.NET MVC
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
ObjectFactory.Configure(cfg =>
{
cfg.For<IEmailValidator>().Use<EmailValidator>();
});

Assuming you have the following object:

public class Person { 
    
    public string Name { get; set; }
    public string Surname { get; set; }
    public int Age { get; set; }
}

and got a PATCH request as below:

@tugberkugurlu
tugberkugurlu / gist:3860947
Created October 9, 2012 19:36 — forked from JefClaes/gist:3860582
Command an query handlers
[TestMethod()]
public void Foo_should_start_mspaint()
{
var cmdHandler = new Mock<ICommandHandler>();
var qryHandler = new Mock<IQueryHandler>();
var controller = new Controller(cmdHandler.Object, qryHandler.Object);
controller.Foo("mspaint.exe");
@tugberkugurlu
tugberkugurlu / gist:3868580
Created October 10, 2012 21:34 — forked from benfoster/gist:3867583
A production useless version of an OAuth request
namespace OAuthDemo.Controllers
{
public static class SecurityConfig
{
public static void Configure(HttpConfiguration httpConfiguration)
{
var config = new AuthenticationConfiguration();
config.DefaultAuthenticationScheme = "Basic";
@tugberkugurlu
tugberkugurlu / gist:3905671
Created October 17, 2012 14:05 — forked from benfoster/gist:3905658
jQuery UI Autocomplete, Twitter Bootstrap Style
.ui-autocomplete {
position: absolute;
cursor: default;
list-style: none;
display: block;
outline: none;
padding: 5px 0;
margin: 2px 0 0;
background-color: @dropdownBackground;
border: 1px solid #ccc; // Fallback for IE7-8
@tugberkugurlu
tugberkugurlu / gist:3924324
Created October 20, 2012 18:49 — forked from benfoster/gist:3924025
LESS CSS Support in System.Web.Optimization
public class LessTransform : IBundleTransform
{
public void Process(BundleContext context, BundleResponse bundle)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
if (bundle == null)
@tugberkugurlu
tugberkugurlu / promises.md
Created October 22, 2012 10:55 — forked from domenic/promises.md
You're Missing the Point of Promises

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
    // the rest of your code goes here.
});
@tugberkugurlu
tugberkugurlu / gist:3989706
Created October 31, 2012 20:38 — forked from maartenba/CloudBlobExtensions.cs
Some common ICloudBlob extension methods
public static class CloudBlobExtensions
{
/// <summary>
/// Uploads a string of text to a block blob.
/// </summary>
/// <param name="content">The text to upload, encoded as a UTF-8 string.</param>
public static void UploadText(this ICloudBlob blob, string content)
{
UploadText(blob, content, Encoding.UTF8, null);
}
@tugberkugurlu
tugberkugurlu / fake-http-context.cs
Created November 5, 2012 23:07 — forked from frankshearar/fake-http-context.cs
A Moq-using fake HTTP context to test controllers.
public HttpContextBase FakeHttpContext() {
var context = new Mock<HttpContextBase>();
var files = new Mock<HttpFileCollectionBase>();
var request = new Mock<HttpRequestBase>();
var response = new Mock<HttpResponseBase>();
var session = new Mock<HttpSessionStateBase>();
var server = new Mock<HttpServerUtilityBase>();
var user = new Mock<IPrincipal>();
var identity = new Mock<IIdentity>();
request.Setup(req => req.ApplicationPath).Returns("~/");
@tugberkugurlu
tugberkugurlu / gist:4025019
Created November 6, 2012 14:27 — forked from benfoster/gist:4024709
Deserializing HttpError
public static class HttpErrorExtensions
{
public static ModelStateDictionary GetModelState(this HttpError httpError)
{
Ensure.Argument.NotNull(httpError, "httpError");
object serialized;
if (httpError.TryGetValue("ModelState", out serialized))
{
var modelState = new ModelStateDictionary();