Skip to content

Instantly share code, notes, and snippets.

@dyoder
dyoder / DisruptorTest.java
Created February 24, 2012 21:46
DisruptorTest adapted for Java 6
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
// import java.net.StandardSocketOptions;
import java.nio.ByteBuffer;
import java.nio.channels.CancelledKeyException;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
subscribe: () ->
context = @context
spire = @context.spire
iteration = @context.iteration
spire.messages.subscribe "channel #{iteration}", {maxCallCount: 1},
(error,messages) ->
if error
context.error(error)
return
@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
@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 / 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 / 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 / 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 / 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 / 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
sudo gem install waves
waves generate -t classic -n myapp
cd myapp
waves server