Skip to content

Instantly share code, notes, and snippets.

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 / 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;
@dyoder
dyoder / hello_world.go
Created February 28, 2012 22:53
Hello world Go Web app
package main
import (
"fmt"
"http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}
@dyoder
dyoder / dispatcher.coffee
Created March 6, 2012 04:55
Go dispatcher, phase 1
http = require('http')
Redis = require("redis")
c = Redis.createClient(@port, @host)
marshal = (req) ->
JSON.stringify
method: req.method
url: req.url
headers: req.headers
body: req.body
@dyoder
dyoder / configure-aws.txt
Created March 28, 2012 02:16
Dolphin with no options
[dan@yoda dolphin (open-source)]$ ./bin/dolphin configure aws --help
Usage: ./bin/dolphin (options)
-g, --group GROUP The AWS security group to use for new instances
-i, --image IMAGE The AWS image for provisioning pods
-k, --key KEY Your AWS account key
-p, --keypair KEYPAIR The AWS keypair name to use with SSH
-r, --region REGION The region (datacenter) for region-specific options
-s, --secret SECRET Your AWS account secret
-h, --help Show this message
@dyoder
dyoder / architecture.md
Created April 28, 2012 00:17
The spire.io Architecture

People often ask us about the technologies we use to power the spire.io platform. Our architecture is a big part of what makes us unique and ensures that your applications will be reliable, performant, and secure.

There are basically five major components involved:

  • Load-balancer and proxy

  • A dispatcher

  • A message transport

Let's get you started building things! We're going to use JavaScript and jQuery in what follows. Once you're up and running with JavaScript, you can follow a similar process to get up and running with our [other client libraries][libraries].

Important: The example below is just to get you up and running. You should never include your account secret in a Web application. See [our tutorial][chat-tutorial] to see a more realistic example.

Create A Sample Project

Create The Project Structure

Create a project directory. Within that create a javascript directory.

Don't see your question below? [Email us!][email]

Do you guarantee that messages are delivered the order in which they were published?

No, we cannot guarantee that. There is varying latency from one client device to the next, so even if one device published before the another, we might received the second one first. It's also possible for our servers to process requests out of order if one request hits a server with less load than a subsequent request.

That said, we do guarantee the ordering once we have processed a message, and our timestamps are done on a microsecond basis, so even if you are processing thousands of requests per second, we can preserve that ordering. Furthermore, the latency variations within our own server are on the order of a millisecond or two, so messages received at a lower frequency will generally be processed in order. However, network latency can vary much more widely across devices and geography, often by tens of milliseconds.

In short, we make every possible effort to pre

@dyoder
dyoder / name-generator.rb
Created July 5, 2012 21:51
Two syllable word-based name generotor
$available = File.open("available-domains.txt","r") do |file|
file.read.split
end
$unavailable = File.open("unavailable-domains.txt","r") do |file|
file.read.split
end
def available?(domain)
$available.include?(domain) or
@dyoder
dyoder / binding-example.coffee
Created July 12, 2012 03:31
Resource Description Schema Example
account:
versions:
"1.0":
paths: [ "/accounts/:id" ]
actions:
get: (id) ->
# code for getting an account