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
public override Task WriteToStreamAsync(Type type, object value, Stream stream, HttpContentHeaders contentHeaders, TransportContext transportContext) {
string callback;
if (isJsonpRequest(request, out callback)) {
var writer = new StreamWriter(stream);
writer.Write(callback + "(");
writer.Flush();
return base.WriteToStreamAsync(type, value, stream, contentHeaders, transportContext).ContinueWith(_ => {
static void Main(string[] args) {
var client = new OAuthHttpClient(_consumerKey, _consumerSecret, _token, _tokenSecret);
var response = client.GetAsync("http://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=tourismgeek&count=5").Result;
response.EnsureSuccessStatusCode();
var result = response.Content.ReadAsAsync<JToken>().Result;
foreach (var status in result)
Console.WriteLine(status["text"] + Environment.NewLine);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using WebAPIDoodle.Http.Entity;
function calculateToastrPosition() {
var windowWidth = $(window).width(),
toastMsgWidth = 300;
var leftOffset = (windowWidth - toastMsgWidth) / 2;
$('<style>').text(".toast-top-center { top: 10px; left: " + leftOffset + "px; }").appendTo("head");
}
@tugberkugurlu
tugberkugurlu / Profile.cs
Created August 23, 2012 07:26
Benchmarking small code samples in C#
//http://stackoverflow.com/questions/1047218/benchmarking-small-code-samples-in-c-can-this-implementation-be-improved
static void Profile(string description, int iterations, Action func) {
// clean up
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
// warm up
public static void Configure(HttpConfiguration config) {
config.Formatters.Remove(config.Formatters.XmlFormatter);
config.Formatters.Remove(config.Formatters.FormUrlEncodedFormatter);
// From DefaultContentNegotiator class:
// If ExcludeMatchOnTypeOnly is true then we don't match on type only which means
// that we return null if we can't match on anything in the request. This is useful
// for generating 406 (Not Acceptable) status codes.
config.Services.Replace(
{
"Message": "The request is invalid.",
"ModelState":{
"blogPost": [
"Required property 'Content' not found in JSON. Path '', line 1, position 44.",
"Required property 'IsApproved' not found in JSON. Path '', line 1, position 44."
],
"blogPost.Content": [
"The Content field is required."
],
@tugberkugurlu
tugberkugurlu / AnonymousTypePropertyDescriptors.cs
Created August 23, 2012 20:37
Anonymous Type Property Descriptors
using System;
using System.ComponentModel;
namespace AnonymousTypePropertyDescriptors {
class Program {
static void Main(string[] args) {
var values = new {
{
"PageIndex": 1,
"PageSize": 2,
"TotalCount": 91,
"TotalPageCount": 46,
"HasNextPage": true,
"HasPreviousPage": false,
"Dtos": [
{
"Key": "e351b1f4-cdee-e111-be77-e89d871b012b",
DECLARE @p__linq__0 AS NVARCHAR(10) = 'en';
SELECT TOP (10)
[Project1].[Order] AS [Order],
[Project1].[Key] AS [Key],
[Project1].[LanguageKey] AS [LanguageKey],
[Project1].[SecondaryKey] AS [SecondaryKey],
[Project1].[Title] AS [Title],
[Project1].[BriefInfo] AS [BriefInfo],
[Project1].[Content] AS [Content],
[Project1].[ImagePath] AS [ImagePath],