Skip to content

Instantly share code, notes, and snippets.

View davidfowl's full-sized avatar

David Fowler davidfowl

View GitHub Profile
var factory = new PackageRepositoryFactory();
IPackageRepository repository = factory.CreateRepository("https://go.microsoft.com/fwlink/?LinkID=206669");
foreach (var p in repository.GetPackages()) {
Console.WriteLine(p);
}
public class Voting : Hub {
public void SubmitVote(int answerId) {
question.Answers.Single(x => x.AnswerId == answerId).NumVotes++;
Clients.update(question);
}
}
public class Voting : Hub {
// Could load this from a DB
static Question question = new Question {
QuestionText = "What's your favourite upcoming technology?",
Answers = new List<Answer> {
new Answer { AnswerId = 1, AnswerText = "C# 5" },
new Answer { AnswerId = 2, AnswerText = "WebSockets" },
new Answer { AnswerId = 3, AnswerText = "Windows 8" },
new Answer { AnswerId = 5, AnswerText = "Magic rainbow unicorns" },
}
@davidfowl
davidfowl / gist:1095586
Created July 20, 2011 18:36
Generic memoize function
public static class FuncExtensions {
public static Func<TKey, TResult> Memoize<TKey, TResult>(this Func<TKey, TResult> f) {
return f.Memoize(EqualityComparer<TKey>.Default);
}
public static Func<TKey, TResult> Memoize<TKey, TResult>(this Func<TKey, TResult> f, IEqualityComparer<TKey> equalityComparer) {
var cache = new ConcurrentDictionary<TKey, Lazy<TResult>>(equalityComparer);
return key => {
var lazy = cache.GetOrAdd(key, new Lazy<TResult>(() => f(key)));
return lazy.Value;
$ git -s status
Unknown option: -s
usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects]
[--bare] [--git-dir=<path>] [--work-tree=<path>]
[-c name=value] [--help]
<command> [<args>]
$ git status -s
?? .gitignore
@davidfowl
davidfowl / SignalR.knockout.js
Created September 9, 2011 17:57
SignalR knockout
/// <reference path="jquery-1.6.2.js" />
(function (window) {
"use strict";
if (typeof (window.signalR) !== "function") {
throw "SignalR: SignalR is not loaded. Please ensure SignalR.js is referenced before ~/signalr/hubs.";
}
var viewModels = {};
var oldProcessState = window.signalR.hub.processState;
@davidfowl
davidfowl / gist:1302887
Created October 21, 2011 01:32
IIS + sh.exe = fail
<%@ Page Language="C#" Debug="true" %>
<%
var exePath = @"C:\Program Files (x86)\Git\bin\sh.exe";
var working = @"C:\Program Files (x86)\Git\bin";
var args = "-c ls";
var psi = new System.Diagnostics.ProcessStartInfo {
FileName = exePath,
WorkingDirectory = working,
@davidfowl
davidfowl / gist:2723952
Created May 18, 2012 08:26
AjaxMinFail
/*!
* SignalR JavaScript Library v0.5
* http://signalr.net/
*
* Copyright David Fowler and Damian Edwards 2012
* Licensed under the MIT.
* https://github.com/SignalR/SignalR/blob/master/LICENSE.md
*/
/// <reference path="jquery-1.6.2.js" />
@davidfowl
davidfowl / gist:3155602
Created July 21, 2012 11:50
Fix ravendb SignalR
diff --git a/Imports/SignalR/SignalR.Client/Http/DefaultHttpClient.cs b/Imports/SignalR/SignalR.Client/Http/DefaultHttpClient.cs
index 345a30f..3999ed6 100644
--- a/Imports/SignalR/SignalR.Client/Http/DefaultHttpClient.cs
+++ b/Imports/SignalR/SignalR.Client/Http/DefaultHttpClient.cs
@@ -17,8 +17,12 @@ public class DefaultHttpClient : IHttpClient
/// <returns>A <see cref="Task{IResponse}"/>.</returns>
public Task<IResponse> GetAsync(string url, Action<IRequest> prepareRequest)
{
- return HttpHelper.GetAsync(url, request => prepareRequest(new HttpWebRequestWrapper(request)))
- .Then(response => (IResponse)new HttpWebResponseWrapper(response));
@davidfowl
davidfowl / defaultwap.cmd
Created August 13, 2012 15:58
Default WAP kudu cmd
@echo off
:: Specify project file
IF "%PROJECT%" == "" (
SET PROJECT=PROJECTFILEGOESHERE
)
IF "%PROJECT%" == "PROJECTFILEGOESHERE" goto MissingProject
:: Specify project configuration