Skip to content

Instantly share code, notes, and snippets.

View beyond-code-github's full-sized avatar

Pete Smith beyond-code-github

View GitHub Profile
@beyond-code-github
beyond-code-github / mongodocumentusage.cs
Created April 22, 2013 20:32
Using the MongoDocument class
var mongoCollection = database.GetCollection<MongoDocument>("Dynamic");
mongoCollection.Insert(
new MongoDocument(
new BsonDocument {
{ "Name", "A test record" },
{ "Date", new DateTime(2013,01,01) },
{ "Age", 28 },
{ "Complete", false } }));
@beyond-code-github
beyond-code-github / MongoDocumentClassSerializer.cs
Created April 22, 2013 20:26
Implementation of BsonDocumentBackedClass serializer, with id generation and concrete property
using System;
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.IdGenerators;
using MongoDB.Bson.Serialization.Serializers;
public class MongoDocumentClassSerializer : BsonDocumentBackedClassSerializer<MongoDocument>, IBsonIdProvider
{
public MongoDocumentClassSerializer()
@beyond-code-github
beyond-code-github / MongoDocument.cs
Created April 22, 2013 20:23
Implementation of BsonDocument backed class
using System;
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Attributes;
[Serializable]
[BsonSerializer(typeof(MongoDocumentClassSerializer))]
public class MongoDocument : BsonDocumentBackedClass
{
var koProvider = {
observable: function () {
return ko.observable();
},
computed: function (func)
{
return ko.computed(func);
}
}
@beyond-code-github
beyond-code-github / gist:5317736
Created April 5, 2013 08:54
State machine routing Javascript prototype
<html>
<head>
<title>State machine routing prototype</title>
</head>
<body>
<h3>State machine routing concept</h3>
<p>Extremely flexible mechanism for defining routes for web applications</p>
<ul>
<li>Hierarchical
</li>
@beyond-code-github
beyond-code-github / gist:5310180
Last active December 15, 2015 19:19
Http routes as state machine
The route state machine defined in pseudo code below is able to handle the following routes:
/Api/Products/
/Api/Products/1
/Api/Categories
/Api/Categories/1
/Api/Products/1/Categories
/Api/Products/1/Categories/2
@beyond-code-github
beyond-code-github / PhantomExpress.cs
Created March 29, 2013 22:33
Phantom Express is a console application that will start IIS Express for a given folder and port, then run Phantom JS as writing the results to the console. Once phantom JS is finished, IIS express is closed.
namespace PhantomExpress
{
using System;
using System.Diagnostics;
using System.Threading.Tasks;
internal class Program
{
private static int Main(string[] args)
{
@beyond-code-github
beyond-code-github / gist:5244422
Last active December 15, 2015 10:19
Cache invalidation use-case #1
I have a URI used to manipulate data records:
http://api/{AppId}/AppData/
There is also the ability to retrieve several report dataviews based on the records.
http://api/{AppId}/ChartData/{chartId}
I need a mechanism so that when I POST to http://api/{AppId}/AppData/, or DELETE\PATCH to http://api/{AppId}/AppData/{id} then any cached route starting with http://api/{AppId}/ChartData/ gets invalidated.
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (this.Context.Request.Path.Contains("signalr/"))
{
this.Context.Response.AddHeader("Access-Control-Allow-Headers", "accept,origin,authorization,content-type");
}
}
public static void RegisterCors(HttpConfiguration httpConfiguration)
{
WebApiCorsConfiguration corsConfig = new WebApiCorsConfiguration();
corsConfig.RegisterGlobal(httpConfiguration);
corsConfig.ForAllOrigins().AllowMethods("GET", "POST", "PUT", "PATCH", "DELETE").AllowAllRequestHeaders();
}