Skip to content

Instantly share code, notes, and snippets.

@prabirshrestha
prabirshrestha / AsyncAwaitHttpHelperSample
Created July 24, 2011 01:30
Async/Await FluentHttp.Core Sample
private async static Task<object> HttpAsync()
{
Stream input = new MemoryStream(Encoding.UTF8.GetBytes("message=hello"));
var httpHelper = new HttpHelper("https://api.example.com");
var httpWebRequest = httpHelper.HttpWebRequest;
httpWebRequest.Method = "POST";
if (input != null)
{
@prabirshrestha
prabirshrestha / ConsoleProgress.cs
Created July 25, 2011 20:35
C# Console Progress
public class ProgressBar
{
private int _lastOutputLength;
private readonly int _maximumWidth;
public ProgressBar(int maximumWidth)
{
_maximumWidth = maximumWidth;
Show(" [ ");
}
@prabirshrestha
prabirshrestha / web.config
Created August 5, 2011 23:03
Staging Applications using url rewrite
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<!-- Stage A:
A(enabled) B(enabled,negate)
Stage B:
A(enabled,negate) B(enabled)
@prabirshrestha
prabirshrestha / FacebookPemissions.cs
Created August 13, 2011 21:15
check if the specified access token has enough permission
/// <returns>returns null is doesn't have enough permission</returns>
public string[] HasPermissions(string accessToken, string[] permissions)
{
try
{
var fb = new FacebookClient(accessToken);
var remoteResult = ((IDictionary<string, object>)fb.Get("me/permissions"));
if (remoteResult != null && remoteResult.ContainsKey("data"))
{
var data = remoteResult["data"] as IList<object>;
@prabirshrestha
prabirshrestha / nJake
Created August 30, 2011 21:36
Sample Jake File using nJake
var n = require('./Build/nJake/nJake'),
path = require('path'),
root = path.normalize(path.join(__dirname, '/'));
n.options.msbuild.version = 'net40';
msbuild_config = 'Release';
var version = { full: '5.2.0.0' };
namespace('build', function () {
@prabirshrestha
prabirshrestha / url decode.cs
Created September 13, 2011 18:55 — forked from anonymous/url decode
if elif madness
public static string UrlDecode(string s)
{
#if WINDOWS_PHONE
return System.Net.HttpUtility.UrlDecode(s);
#elif SILVERLIGHT
return System.Windows.Browser.HttpUtility.UrlDecode(s);
#else
// Since HttpUtility.UrlDecode doesn't exist in Client Framework
// get it from Mono.
// Thank god, mono libraries are licensed under MIT.
@prabirshrestha
prabirshrestha / twitterStreamApi.cs
Created September 19, 2011 08:19
Twitter Streaming Api with FluentHttp.Core, SimpleJson and Async/Await
// install-package FluentHttp.Core
// install-package SimpleJson
// add as conditional symbol
// FLUENTHTTP_CORE_TPL;FLUENTHTTP_CORE_UTILS;FLUENTHTTP_HTTPBASIC_AUTHENTICATION;SIMPLE_JSON_DYNAMIC;SIMPLE_JSON_REFLECTIONEMIT
namespace ConsoleApplication1
{
using System;
using System.IO;
<Target Name="Build" DependsOnTargets="CreateOutputDir">
38
cmd /C "WebpiCmd\WebpiCmd.exe /Install /AcceptEula /SuppressReboot /Products:WindowsInstaller31"
cmd /C "WebpiCmd\WebpiCmd.exe /Install /AcceptEula /SuppressReboot /Products:WindowsInstaller45"
# .NET
cmd /C "WebpiCmd\WebpiCmd.exe /Install /AcceptEula /SuppressReboot /Products:netframework2"
cmd /C "WebpiCmd\WebpiCmd.exe /Install /AcceptEula /SuppressReboot /Products:NETFramework35"
cmd /C "WebpiCmd\WebpiCmd.exe /Install /AcceptEula /SuppressReboot /Products:NETFramework4"
# IIS
cmd /C "WebpiCmd\WebpiCmd.exe /Install /AcceptEula /SuppressReboot /Products:IIS7"
@prabirshrestha
prabirshrestha / TaskIterationExtensions.cs
Created January 7, 2012 10:19
TaskIterationExtensions
namespace TaskIterationExtensions
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
/// <remarks>
// http://blogs.msdn.com/b/pfxteam/archive/2009/06/30/9809774.aspx
/// </remarks>
static class TaskIterationExtensions