Skip to content

Instantly share code, notes, and snippets.

View serialseb's full-sized avatar

Sebastien Lambla serialseb

View GitHub Profile
@serialseb
serialseb / ddd-excercise1
Created December 8, 2010 14:56
A simple value object in .net
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
namespace DDD_1
{
class Program
{
@serialseb
serialseb / gist:1238163
Created September 23, 2011 18:59
Which language do you prefer?
ResourceSpace.Has.Resource<Home>()
/*(1)*/ .Map(_=>_.LastModified(r=>r.UpdateTime)
.Etag(r=>r.ID))
/*(2)*/ .MapLastModified(_=>_.UpdateTime)
.MapEtag(r=>r.ID)
/*(3)*/ .Map().LastModified(_=>_.UpdateTime)
.Etag(_=>_.ID)
@serialseb
serialseb / gist:1373164
Created November 17, 2011 13:45
Parsing link headers quick and dirty
static internal class ResponseExtensions
{
public static string GetLinkValue(this WebResponse response, string rel)
{
return (from header in response.Headers["Link"].Split(',')
let components = header.Split(';')
let uri = components[0]
where components.Any(
component =>
Regex.IsMatch(component,
public static IEnumerable<Dictionary<string, string>> ItemScope(this XDocument document, string schema, params string[] propertyNames)
{
return from node in document.Document.Descendants()
where node.HAttr("itemtype") == schema
where node.HAttr("itemscope") == "itemscope"
select (from property in node.Descendants()
let propName = property.HAttr("itemprop")
where propertyNames.Contains(propName)
select property).ToDictionary(_=>_.HAttr("itemprop"), _=>_.Value);
}
@serialseb
serialseb / gist:1373311
Created November 17, 2011 14:52
rest-aurant client
class Program
{
private const string REL_RESTAURANT_LIST = "http://rest.aurant.org/restaurant-list";
static void Main(string[] args)
{
var restaurantHref = DiscoverRestaurantListUri();
Console.WriteLine("Using " + restaurantHref);
var selectedRestaurant = SelectRestaurantUri(restaurantHref);
@serialseb
serialseb / test
Last active December 25, 2015 20:59
Tests for calculator
1+1,2
1.1+0.1,1.2
1+-1,0
-2+1,-1
1+2+3,6
2*3,6
2*-3,-6
2*3*4,24
3+3*4,15
(3+3)*4,24
@serialseb
serialseb / Stuff.cs
Created May 16, 2014 12:40
A more compositional approach
public class Wireup
{
public void DoWireup()
{
var identity = new IdentityFormatter();
var stringFormat = new FormattingStringFormatter();
// that would normally get registered in your container or what not.
Selectors = new[]
{
@serialseb
serialseb / owinfx
Last active August 29, 2015 14:02
owin stuff
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Nancy;
using Nancy.Owin;
using Nowin;
public class cappedqueue : cappedcontext
{
static object[] examples =
{
new { members = new[] { 1, 2, 3, 4 }, cap = 3, expected = new[] { 2, 3, 4 } }
};
public cappedqueue(int[] members, int cap)
{
@serialseb
serialseb / projections.cs
Last active August 29, 2015 14:03
Projecting things
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MongoDB.Bson.Serialization.Attributes;