Skip to content

Instantly share code, notes, and snippets.

@laser
laser / barrister.js
Created April 30, 2014 17:50
Barrister.js Node Server
// server
var express = require('express')
, fs = require('fs')
, http = require('http')
, path = require('path')
, barrister = require('barrister')
, store = require("./store").store
, idl = JSON.parse(fs.readFileSync("./todo_manager.json").toString());
@laser
laser / success_curl.json
Last active August 29, 2015 14:00
A Successful POST to Contact Service pt. 2
[
{
"id":1,
"age":32,
"importance_level":100,
"alias":"hippipp",
"full_name":"S-H, Erin",
"url":"http://example.com/api/v1/contacts/1.json"
}
]
@laser
laser / api_paths.txt
Last active August 29, 2015 14:00
API Paths Table
| Verb | URI Pattern |
| -------| ------------------------------------------- |
| GET | http://example.com/api/v1/contacts.json |
| POST | http://example.com/api/v1/contacts.json |
| GET | http://example.com/api/v1/contacts/:id.json |
| PATCH | http://example.com/api/v1/contacts/:id.json |
| DELETE | http://example.com/api/v1/contacts/:id.json |
@laser
laser / contact.rb
Created April 29, 2014 22:01
The Contact Model
class Contact < ActiveRecord::Base
validates :full_name, presence: true
validates :alias, presence: true
validates :importance_level, inclusion: {
in: [100, 200, 300]
}
validates :age, numericality: {
@laser
laser / sad_curl.json
Last active August 29, 2015 14:00
An Unsuccessful POST to Contact Service pt. 2
{
"first_name":["can't be blank"],
"last_name":["can't be blank"]
}
@laser
laser / sad_curl.sh
Last active August 29, 2015 14:00
An Unsuccessful POST to Contact Service
curl -X POST \
-H "Content-Type: application/json" \
-d '{"full_name": "Erin S-H", "age": 32, "importance_level": 100, "alias": "laser"}' \
http://example.com/api/v1/contacts.json
@laser
laser / success_curl.sh
Last active August 29, 2015 14:00
First Successful POST to Contact Service
curl -X POST \
-H "Content-Type: application/json" \
-d '{"first_name": "Erin", "last_name": "S-H", "age": 32, "importance_level": 100, "alias": "lzr"}' \
http://example.com/api/v1/contacts.json
@laser
laser / contact_service.txt
Last active August 29, 2015 14:00
Contact Service API Documentation
# Contact Service API Reference
/api/v1/contacts.json
## Reading
GET /contacts.json HTTP/1.1
Host: example.com
### Fields
@laser
laser / rpc_benchmark.rb
Created April 28, 2014 16:39
RPC benchmark
#!/usr/bin/env ruby
require 'net/http'
require 'securerandom'
require 'json'
require 'benchmark'
require 'redis'
require 'bunny'
require 'pry'
uri = URI('http://localhost:4567/calc')
@laser
laser / benchmark.log
Created April 28, 2014 16:36
RPC messaging through HTTP / Redis / RabbitMQ
Rehearsal --------------------------------------------
RabbitMQ 0.980000 0.570000 1.550000 ( 1.602346)
Redis 0.280000 0.040000 0.320000 ( 0.419955)
HTTP 0.500000 0.200000 0.700000 ( 2.436720)
----------------------------------- total: 2.570000sec
user system total real
RabbitMQ 0.980000 0.580000 1.560000 ( 1.604432)
Redis 0.270000 0.040000 0.310000 ( 0.416424)
HTTP 0.490000 0.190000 0.680000 ( 6.691767)