Skip to content

Instantly share code, notes, and snippets.

View glennblock's full-sized avatar

Glenn Block glennblock

View GitHub Profile
@glennblock
glennblock / books.json
Created September 7, 2020 15:50 — forked from nanotaboada/books.json
A sample collection of books in JSON format
{
"books": [
{
"isbn": "9781593275846",
"title": "Eloquent JavaScript, Second Edition",
"subtitle": "A Modern Introduction to Programming",
"author": "Marijn Haverbeke",
"published": "2014-12-14T00:00:00.000Z",
"publisher": "No Starch Press",
"pages": 472,
@glennblock
glennblock / node.js
Last active November 25, 2016 06:38 — forked from Manny7311/node.js
Webtask Stripe
'use latest';
import stripe from 'stripe';
module.exports = function(ctx,cb) {
var STRIPE_SECRET_KEY = ctx.secrets.STRIPE_SECRET_KEY;
stripe(STRIPE_SECRET_KEY).charges.create({
amount: ctx.data.amount,
currency: ctx.data.currency,
source: ctx.body.stripeToken,
// cj write template
{
"template" : {
"data" : [
{"name" : "qwe", "value" : ""},
{"name" : "rty", "type" : "part"}
]
}
}
namespace IssueDOM
{
public class Issue
{
public string Title { get; set; }
public string Description { get; set; }
public string State { get; set; }
//another option instead of generic link / rel is to just model them into the domain, for example for people you could
//generic formatter which takes in a model and transforms it to something specific for the media type
//StrategyFormatter is a generic formatter that you derive from to create specific ones. You override the formatter methods to write the response.
public interface IFormatterStrategy<TOutput> {
TOutput Transform(object model);
}
//loops through all the formatter strategies and asks them to handle the model
public abstract class StrategyFormatter<TOutput> : MediaTypeFormatter {
public IEnumerable<IStrategyFormatter<TOutput>> Strategies {public get;private set;}
@glennblock
glennblock / OrderLinkService.cs
Created January 8, 2012 02:34 — forked from anonymous/OrderLinkService.cs
Web API - Order link service
public class OrderLinkService : IOrderLinkService, ILinkService<Order> {
public ILinkable<Order> AddLinks(Order order) {
var linkedOrder = new Linkable<Order>();
if (order.State == OrderStates.Created) {
linkedOrder.Links.Add(OrderLinks.Approval, GetApprovalUri(order.ID));
}
//other state logic here
return linkedOrder;
}
http = require 'http'
server = http.createServer (req, res) ->
res.writeHead 200, {'Content-Type': 'text/plain'}
res.end 'Hello World'
server.listen 1337, "127.0.0.1"
console.log 'Server running at http://127.0.0.1:1337/'
using Microsoft.Practices.Composite.Presentation.Events;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Unity;
namespace SomeNamespace
{
public class SomeViewModel
{
private readonly IUnityContainer _container;
private readonly IEventAggregator _eventAggregator;
private TPart ComposePartWith<TPart, TImport>(TImport import)
{
var catalog = new TypeCatalog(typeof(TPart));
var childContainer = new CompositionContainer(catalog, Container);
childContainer.ComposeExportedValue(import);
return childContainer.GetExportedValue<TPart>();
}