Skip to content

Instantly share code, notes, and snippets.

@prabirshrestha
prabirshrestha / gist:3965297
Created October 27, 2012 16:48
conemu shell integration
C:\Users\prabir\AppData\Local\GitHub\PortableGit_8810fd5c2c79c73adcc73fd0825f3b32fdb816e7\bin\sh.exe --login -i
C:\Users\Prabir\ConEmuPack\ConEmu64.exe,0
public class CassetteBundleConfiguration : IConfiguration<BundleCollection>
{
private readonly string rootPath;
public CassetteBundleConfiguration()
{
this.rootPath = HostingEnvironment.MapPath("~/");
//this.rootPath = rootPathProvider.GetRootPath();
}
[Fact]
public void AdditionTest() {
// given
int a = 1;
int b = 2;
// when
var result = Math.Add(a, b);
// then
// install-package httphelper -pre
// install-package simplejson
#define SIMPLE_JSON_DYNAMIC
public static object Get(string url)
{
var httpHelper = new HttpHelper(url);
using (var stream = httpHelper.OpenRead())
@prabirshrestha
prabirshrestha / gist:4061724
Created November 12, 2012 20:38
nancy model binding and validation example
public class SampleModule : NancyModule {
public SampleModule() {
Post["/"] = x => {
var person = this.Bind<Person>();
this.Validate(person);
if(!this.ModelValidationResult.IsValid)
return 400;
return 200;
}
}
@prabirshrestha
prabirshrestha / gist:4067816
Created November 13, 2012 19:24
nancy fb real time subscription example
// advanced
public class FacebookSubscriptionModule : NancyModule {
public FacebookSubscriptionModule() {
Get["/"] =
_ => Response.AsFacebookGetSubscriptionResponse("app_secret", "verify_token");
Post["/"] = x => {
_ => Response.AsFacebookPostSubscriptionResponse("app_secret", x => {
});
public object DoSomething(string jsonString) {
var json = DeserializeJson(jsonString);
var dict = json as IDictionary<string, object>;
if(dict == nul) {
// use another serializer to normalize the json
// and set dict.
} else {
// DeserializeJson worked so do nothing.
}
@prabirshrestha
prabirshrestha / gist:4151336
Created November 26, 2012 23:26
dictionary reflection get value for key
namespace ConsoleApplication4
{
using System;
using System.Collections.Generic;
using ConsoleApplication4.Reflection;
using Newtonsoft.Json;
class Program
{
Get["/{rss?html}"] = x => {
var articles = new List<Article>();
return Negotiate
.WithModel(articles)
.WithMediaRangeModel("application/xml", articles).WithView("articles/rss/xml/index")
.WithMediaRangeModel("application/javascript", articles).WithView("articles/rss/jsonp/index")
.WithMediaRangeModel("application/json", articles).WithView("articles/rss/json/index")
.WithMediaRangeModel("text/html", articles).WithView("articles/article");
var FB = require('fb')
Step = require('step');
function fbnodify (res) {
if(!res || res.error) throw new Error(JSON.stringify(res));
this(null, res);
}
function fbnodifybatch (res) {
if(!res || res.error) throw new Error(JSON.stringify(res));