Skip to content

Instantly share code, notes, and snippets.

View gshutler's full-sized avatar
📅
👨‍💻

Garry Shutler gshutler

📅
👨‍💻
View GitHub Profile
Expression<Func<X, bool>> Blah<X, T>(Expression<Func<X, T>> prop, Expression<Func<T, bool>> pred)
{
return x => pred.Compile().Invoke(prop.Compile().Invoke(x));
}
public class PageTemplateManager : IPageTemplateManager
{
readonly IReadModelRepository readModelRepository;
readonly object mutex;
readonly IDictionary<Guid, IList<PageTemplate>> templates;
public PageTemplateManager(IReadModelRepository readModelRepository)
{
this.readModelRepository = readModelRepository;
this.templates = new Dictionary<Guid, IList<PageTemplate>>();
public interface IHeader
{
string Value { get; }
IEnumerable<string> Values { get; }
}
public sealed class Header : IHeader
{
readonly IEnumerable<string> values;
readonly string value;
@gshutler
gshutler / about_scoring_project.rb
Created July 18, 2011 10:24 — forked from jakcharlton/about_scoring_project.rb
About Scoring from Ruby Koans
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
# Greed is a dice game where you roll up to five dice to accumulate
# points. The following "score" function will be used calculate the
# score of a single roll of the dice.
#
# A greed roll is scored as follows:
#
# * A set of three ones is 1000 points
#
#!/usr/bin/env ruby
require "rubygems"
# Take a copy of the arguments as rubygems or bundler modifies them
args = ARGV.dup
begin
gem "bundler"
rescue Gem::LoadError
@gshutler
gshutler / gist:1540305
Created December 30, 2011 15:26
Installing bash git completion and display of active branch

Install bash git completion (I used homebrew).

Then alter the end of your .bash_profile to be this:

NO_COLOR="\033[0m"
GRAY="\033[90m"

if [ -f /usr/local/etc/bash_completion.d/git-completion.bash ]; then
 . /usr/local/etc/bash_completion.d/git-completion.bash;
Approval resource URL is discovered through the base resource, no naughty URL templating.
GET /resource/5/approve
404 when not approved, 200 with the thingy-approval resource once approved.
PUT /resource/5/approve
Replaces the current approval message or whatever (you can always store a history of approval messages internally).
public static class DiffGenerator
{
public Diff<T> Generate<T>(IEnumerable<T> left, IEnumerable<T> right)
{
var added = right.Except(left).ToList();
var removed = left.Except(right).ToList();
var leftList = left.ToList();
var common = right.Where(item => leftList.Contains(item)).ToList();
@gshutler
gshutler / DiffGenerator.cs
Created March 2, 2012 17:27 — forked from DominicFinn/DiffGenerator.cs
Two ways of generating the difference in between two lists
using System.Collections.Generic;
using System.Linq;
namespace Other.Something.Core.Tasks
{
public static class DiffGenerator
{
public static Diff<T> Generate<T>(IEnumerable<T> left, IEnumerable<T> right)
{
var added = right.Except(left);
GET /users
Content-Type: application/json
Link: rel=page2;href=/users?page=2
{
page: 1,
total: 1111002324,
results: [