Skip to content

Instantly share code, notes, and snippets.

Choice.options do
header 'Run a waves application server.'
header ''
option :port do
short '-p'
long '--port=PORT'
desc 'Port to listen on.'
desc 'Defaults to value given in configuration.'
cast Integer
end
/* A simple store using libmicrohttp */
#include <stdint.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdarg.h>
#include <sys/socket.h>
#include <microhttpd.h>
#include <string.h>
#include <fcntl.h>
sudo gem install waves
waves generate -t classic -n myapp
cd myapp
waves server
@dyoder
dyoder / article.rb
Created December 2, 2010 01:24
Current Example - Listing 1
class Acme::Web::Adapters::Article < Acme::Web::Adapter
resource Acme::Resources::Article
Comments = Acme::Web::Adapters::Comments
version "1.0" do
path "article", :name
get [ json, xml, html ]
authorized do
put json => json, xml => xml
delete
end
@dyoder
dyoder / Create-A-Channel.js
Created October 5, 2011 22:31
REST Tutorial
shred.post({
url: description.resources.session.resources.channels.url,
headers: {
accept: description.schema["1.0"].channel.mediaType,
content_type: description.schema["1.0"].channel.mediaType,
authorization: "Capability " +
description.resources.session.resources.channels.capability
},
content: {
name: "Foo",
@dyoder
dyoder / safeFactory.js
Created October 7, 2011 19:27
Function and method callbacks for simplifying error handling
// So we start with a function that will allow to create new functions that
// convert errors into events.
var safeFactory = function(emitter) {
return function(fn) {
return function(err,value) {
if (err) { emitter.emit("error",err); }
else fn(value);
}
}
@dyoder
dyoder / test-service.coffee
Created October 15, 2011 22:37
Adapter code cleans up nicely in CoffeeScript ...
#!/usr/bin/env coffee
Server = require("../../lib/shark/http_server")
Adapter = require("../../lib/shark/http_adapter")
configuration = require("../conf/server.conf")
configuration.processor = (server) ->
adapter = new Adapter(server)
@dyoder
dyoder / subscription.coffee
Created October 17, 2011 18:52
Create A Subscription
a.accept "subscription", (a) ->
a.describe "Create a subscription"
a.contentType "subscription", (a) ->
a.run (object) ->
context = this
manager = new Channel.Manager
manager.on "success",(channel) ->
create = CREATE Subscription, (subscription) ->
subscription.url = context.url("subscription", [
context.workspace.captured.sessionID
@dyoder
dyoder / stubby.coffee
Created October 20, 2011 00:48
Test For Stubby API
s = this; s.API.discovery "http://localhost:1337/", (description) ->
s.Account.create description, (account) ->
channel_name = "Foo"; message = "Hello, World!"
s.Session.create [description, account], (session) ->
s.Channel.create [description,session.channels,channel_name],
(channel) ->
s.Channel.publish [description,channel,message]
# Okay, now create another session and get the message
s.Session.create [description, account], (session) ->
@dyoder
dyoder / Result.txt
Created November 9, 2011 20:51
Chaining tests in cakefiles
[dan@yoda shark (stubby*)]$ cake test
test - run all the shark tests
test:dispatcher - run all the dispatcher specs
build - compile coffee script source files and copy them into lib
Waiting one second to make sure task 'build' has completed
Running on 127.0.0.1, port 1337
Response URL defined as http://localhost:1337/
Checking long-polling ...
√ [Account: creation (POST)] Result: includes an account key
√ [Account: delete (DELETE)] Result: the delete was successful