Skip to content

Instantly share code, notes, and snippets.

View davidfowl's full-sized avatar

David Fowler davidfowl

View GitHub Profile
@davidfowl
davidfowl / SolutionFolders.ps1
Created February 21, 2011 10:01
Adding a solution folder via DTE in NuGet
function Add-SolutionFolder {
param(
[string]$Name
)
$solution2 = Get-Interface $dte.Solution ([EnvDTE80.Solution2])
$solution2.AddSolutionFolder($Name)
}
function Get-SolutionFolder {
param (
@davidfowl
davidfowl / Powershell Magic
Created March 2, 2011 06:41
Script showing how to use Register-TabExpansion. The sample is adding intellisense for Scaffold-Controller
function global:Get-Types {
param (
$ProjectName,
$BaseType,
[switch]$IgnoreProjectReferences
)
if($ProjectName) {
$project = Get-Project $ProjectName
}
else {
var factory = new PackageRepositoryFactory();
IPackageRepository repository = factory.CreateRepository("https://go.microsoft.com/fwlink/?LinkID=206669");
foreach (var p in repository.GetPackages()) {
Console.WriteLine(p);
}
@davidfowl
davidfowl / Examples
Created May 21, 2011 08:19
Powershell function that recursively walks all project items within a project and lets you execute an action on each one
# Print all project items
Recurse-Project -Action {param($item) "`"$($item.ProjectItem.Name)`" is a $($item.Type)" }
# Function to format all documents based on https://gist.github.com/984353
function Format-Document {
param(
[parameter(ValueFromPipelineByPropertyName = $true)]
[string[]]$ProjectName
)
Process {
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 / gist:1158895
Created August 20, 2011 09:19
Dynamic Orderby
public static class QueryExtensions {
public static IQueryable<T> SortBy<T>(this IQueryable<T> source, string propertyName) {
if (source == null) {
throw new ArgumentNullException("source");
}
// DataSource control passes the sort parameter with a direction
// if the direction is descending
int descIndex = propertyName.IndexOf(" DESC");
if (descIndex >= 0) {
propertyName = propertyName.Substring(0, descIndex).Trim();
@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;