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:1993661
Created March 7, 2012 15:01 — forked from darrelmiller/gist:1989131
Conneg with quality
[TestMethod]
public void ConnegTest()
{
var selector = new FormatterSelector();
var response = new HttpResponseMessage();
response.RequestMessage = new HttpRequestMessage();
var headers = response.RequestMessage.Headers;
headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain"));
headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json",0.8));
@tugberkugurlu
tugberkugurlu / gist:2027936
Created March 13, 2012 09:58 — forked from darrelmiller/gist:2026145
ThroughputMessageHandler
public class ThroughputMessageHandler : DelegatingHandler
{
private readonly ILogger _logger;
private Timer _timer;
private int _count;
public ThroughputMessageHandler(ILogger logger)
{
_logger = logger;
_count = 0;
_timer = new Timer(new TimerCallback(timerCallback),null,1000,1000);
@tugberkugurlu
tugberkugurlu / gist:2040145
Created March 14, 2012 22:43 — forked from darkiri/gist:2039990
is there a method which returns all .net base types/structs that System.Convert is able to convert to/from?
typeof (Convert)
.GetMethods(BindingFlags.Static|BindingFlags.Public)
.Where(m=>m.Name.StartsWith("To"))
.Select(m=>m.GetParameters().First().ParameterType)
.Distinct()
paul@jupiter:~/GitHub/SignalR% wc -l **/*.cs | grep 'total'
13141 total
paul@jupiter:~/GitHub/SignalR% wc -l **/*.js | grep 'total'
94225 total
@tugberkugurlu
tugberkugurlu / AsyncResult.cs
Created May 24, 2012 22:30 — forked from davidfowl/AsyncResult.cs
Before SignalR
// From http://msdn.microsoft.com/en-us/magazine/cc163467.aspx
internal class AsyncResult : IAsyncResult
{
// Fields set at construction which never change while
// operation is pending
readonly AsyncCallback m_AsyncCallback;
readonly Object m_AsyncState;
// Fields set at construction which do change after
// operation completes
### Check me into the root of the repo
### as .gitattributes
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
@tugberkugurlu
tugberkugurlu / InvalidModelStateFilterAttribute.cs
Created June 3, 2012 07:57 — forked from bradwilson/InvalidModelStateFilterAttribute.cs
A filter for ASP.NET Web API to return 400 upon invalid model binding
using System;
using System.Net;
using System.Net.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class InvalidModelStateFilterAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(HttpActionContext actionContext)
@tugberkugurlu
tugberkugurlu / HttpContentProcessor.cs
Created July 2, 2012 21:36 — forked from HenrikFrystykNielsen/HttpContentProcessor.cs
Sample showing a DelegatingHandler which plugs in a special HttpContent wrapper for saving response content to local disk and perform asynchronous post-processing on that file. This allows content from a response to be post-processed, for example to send
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
namespace ResponseEntityProcessor.Handlers
{
/// <summary>
/// Wraps an inner <see cref="HttpContent"/> and forces the content to be written
@tugberkugurlu
tugberkugurlu / gist:3587448
Created September 1, 2012 21:10 — forked from benfoster/gist:3555524
AtomPubMediaTypeFormatter for ASP.NET Web API
public class AtomPubMediaFormatter : MediaTypeFormatter
{
private const string Atom = "application/atom+xml";
public AtomPubMediaFormatter()
{
SupportedMediaTypes.Add(new MediaTypeHeaderValue(Atom));
this.AddQueryStringMapping("format", "atom", Atom);
}