Skip to content

Instantly share code, notes, and snippets.

View hjr3's full-sized avatar

Herman J. Radtke III hjr3

View GitHub Profile
@hjr3
hjr3 / truck.md
Created December 3, 2012 08:52
Example of HAL+json using truck as an example

Examples of HAL+json API calls for a truck

Get Trucks

GET /trucks HTTP/1.1
Host: api.example.com
Authorization: Basic username:password
Accept: application/hal+json
@hjr3
hjr3 / result.json
Created November 20, 2012 21:47
v4 events response for nested child events
{
"_links": {
"self": {
"href": "/v4/events/24057"
},
"http://hautelook.com/rels/catalog": {
"href": "/v4/events/24057/catalog"
},
"http://hautelook.com/rels/availability": {
"href": "/v4/events/24057/availability"
@hjr3
hjr3 / post-credit.txt
Created November 5, 2012 05:16
Add credits to a members account.
GET /members/1234/credits HTTP/1.1
Host: www.example.com
Content-Type: application/json
HTTP/1.1 200 OK
Content-Type: application/json
{
credits: 10
}
@hjr3
hjr3 / cache-control.md
Created October 17, 2012 00:34
HTTP examples for Cache-Control

Request for member resource

Request

GET /member/1234
Host: www.example.com

Response

HTTP/1.1 200 OK

@hjr3
hjr3 / nginx.conf
Created September 23, 2012 17:58
nginx phpfpm + CORS configuration
upstream phpfpm {
server 127.0.0.1:9000;
}
server {
listen 80;
server_name _;
root /var/www/html;
index index.php;
@hjr3
hjr3 / Vagrantfile
Created August 24, 2012 23:40
Standard PHP vagrant setup
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "centos64-min"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
config.vm.box_url = "http://dl.dropbox.com/u/9227672/CentOS-6.0-x86_64-netboot-4.1.6.box"
@hjr3
hjr3 / e-commerce.md
Created April 3, 2012 05:35
Examples of RESTful API calls for E-commerce platforms

Examples of RESTful API calls for E-commerce platforms

These examples are type 3 RESTful API requests and responses. The JSON-HAL specification is used to implement HATEOAS.

Some of the examples are based on my work as architect of the RESTful API at http://www.hautelook.com. All proprietary information has been removed.

Relevant links

@hjr3
hjr3 / primes.c
Created March 12, 2012 06:26
Find all prime numbers in a given range using Sieve of Eratosthenes
// gcc -std=c99 -Wall -Werror -g -o primes primes.c -lm
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
void primes(int length)
{
unsigned int bits_per_int = (sizeof(unsigned int) * CHAR_BIT);
unsigned int mask_size = 0;
@hjr3
hjr3 / debugger.py
Created March 8, 2012 06:28
XML response output from DBGP for PHP arrays
def xml_on_element(self, node):
if node.nodeName == 'property':
self.type = node.getAttribute('type')
name = node.getAttribute('name')
fullname = node.getAttribute('fullname')
if name == '':
name = 'EVAL_RESULT'
if fullname == '':
fullname = 'EVAL_RESULT'
@hjr3
hjr3 / decode.c
Created March 3, 2012 08:52
TopCoder.com SRM Problem 300
// gcc -g -Wall -Werror -o decode decode.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
const int RESULT_LEN = 2;
/**
* Transforms a string of numerics in an array of ints.