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 / simpleexample.js
Last active January 3, 2016 00:49
Using the simple change tracking
var viewModel = {
Name: ko.observable("Pete"),
Age: ko.observable(29),
Occupation: ko.observable("Developer")
};
applyChangeTracking(viewModel);
viewModel.Occupation("Unemployed");
@beyond-code-github
beyond-code-github / flatchangetracking.js
Last active January 3, 2016 00:49
Change tracking for flat viewmodels, all properties must be observables
var getObjProperties = function (obj) {
var objProperties = [];
var val = ko.utils.unwrapObservable(obj);
if (val !== null && typeof val === 'object') {
for (var i in val) {
if (val.hasOwnProperty(i)) objProperties.push({ "name": i, "value": val[i] });
}
}
public class MyMiddleware
{
public Func<IDictionary<string, object>, Task> GetAppFunc(Func<IDictionary<string, object>, Task> next)
{
return (env) => {
// do stuff
await next(env);
// do more stuff
}
}
ʃ.Route(ʅ => ʅ / "Hello" * Pipeline.Action<FirstComponent>() / (
ʅ / "World" * Pipeline.Action<SecondComponent>()
| ʅ / "Foobar" * Pipeline.Action<ThirdComponent>()));
@beyond-code-github
beyond-code-github / subpipeline.cs
Created November 29, 2013 20:26
Sub-pipeline example
if (routeData.Pipeline.Any())
{
IAppBuilder branch = builder.New();
foreach (var middleware in routeData.Pipeline)
{
branch.Use(middleware);
}
branch.Use(typeof(RedirectMiddleware), this.next);
public class MailController : ApiController
{
private readonly dynamic[] mail =
{
new { Id = 1, Location = "Inbox", Subject = "value1" },
new { Id = 2, Location = "Inbox", Subject = "value2" },
new { Id = 3, Location = "Inbox", Subject = "value3" },
new { Id = 4, Location = "Deleted", Subject = "value4" },
new { Id = 5, Location = "Sent", Subject = "value5" }
};
CacheControlHeaderProvider = (request, cfg) =>
{
var matcher = new Regex("/Api/Notifications");
if (matcher.IsMatch(request.RequestUri.ToString()))
{
return null;
}
return new CacheControlHeaderValue
{
public class IndividualResult<T> {
public bool WasCalculated { get; set; }
public T Result { get; set; }
}
public class CalculatesThings {
private PropertyACalculator<AType> propertyACalculator;
private PropertyBCalculator<BType> propertyBCalculator;
private PropertyCCalculator<CType> propertyCCalculator;
namespace OwinModulesHelloWorld
{
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public double Price { get; set; }
}
@beyond-code-github
beyond-code-github / ProductPost.cs
Last active December 23, 2015 16:29
Post handler binding to a product model
this.Post["Products"] = _ =>
{
var product = _.Bind<Product>();
_.StatusCode = 201;
return new { Message = string.Format("Received product {0}", product.Name) };
};