Skip to content

Instantly share code, notes, and snippets.

xxxxxxxx // benchmarks on
00:00:00.xxxxxxx // 1st call
00:00:00.xxxxxxx // 2nd call with cached
00:00:00.xxxxxxx // 3rd-1000000th calls with cached
1st run
ctor method invoke
00:00:00.0087014
00:00:00.0007445
00:00:00.3629976
@prabirshrestha
prabirshrestha / .gitattributes
Created May 12, 2012 05:28
.gitattributes don't convert line endings
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
using MyType = System.Func<object, System.IObservable<System.Tuple<string, System.Collections.Generic.Dictionary<string, HeuristicTreeInformation>>>>;
var x = new MyType(....);
@prabirshrestha
prabirshrestha / gist:2706671
Created May 16, 2012 01:49
Task Timeout After
public async static Task<T> TimeoutAfter<T>(Task<T> task, int delay)
{
await TaskEx.WhenAny(task, TaskEx.Delay(delay));
if (!task.IsCompleted)
throw new TimeoutException("Timeout hit.");
return await task;
}
dynamic result = fb.Post("id/tags", new[] {
new { x = "40", y = "40", id = "...", tag_text = "..."
});
@prabirshrestha
prabirshrestha / default.aspx
Created May 21, 2012 23:30
ASP.NET 4.5 WebSockets echo server
<%@ Page Language="C#" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
@prabirshrestha
prabirshrestha / socket.io.cs
Created May 22, 2012 15:56
socket.io 4 .net
namespace WebSocketHelloEchoServer.SocketIo
{
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.WebSockets;
using System.Reflection;
@prabirshrestha
prabirshrestha / api.cs
Created May 22, 2012 19:41
general api
var fb = new FacebookApi();
dynamic result = await fb.ApiAsync(
method: "GET"
path: "me/feed",
parameters: new { fields= new[] {"id", "name"},
cancel: CancellationToken.None,
onUploadProgress:null, // IProgress<Tuple <long,byte[]>> -> totalBytesReceived, byteBuffer
onDownloadProgress: null);
var headers = result.headers;
@prabirshrestha
prabirshrestha / MapReduce.cs
Created May 30, 2012 15:54
MapReduce in C# using TPL.
// http://ox.no/files/MapReduce.cs
public static class MapReduce
{
public static Task<TResult> Start<TInput, TPartialResult, TResult>(Func<TInput, TPartialResult> map, Func<TPartialResult[], TResult> reduce, params TInput[] inputs)
{
var mapTasks = CreateMapTasks(map, inputs);
var reduceTask = CreateReduceTask(reduce, mapTasks);
@prabirshrestha
prabirshrestha / WebBrowserScriptExtensions.cs
Created June 2, 2012 18:17
WP7 web browser script extensions
using System;
using Microsoft.Phone.Controls;
public static class WebBrowserScriptExtensions
{
public static object ExecuteCode(this WebBrowser browser, string code)
{
return browser.InvokeScript("eval", "(function(){\r\n" + code + "\r\n})();");
}