Skip to content

Instantly share code, notes, and snippets.

View stephenlb's full-sized avatar
😀
Coding with Rust

Stephen Blum stephenlb

😀
Coding with Rust
View GitHub Profile
@stephenlb
stephenlb / get-started-websockets.html
Last active August 29, 2015 13:56
Easy Get Started Guide with JavaScript Websockets.
<script src="http://cdn.pubnub.com/pubnub.min.js"></script>
<script>
// Initialize PubNub
var pubnub = PUBNUB.init({
publish_key : "YOUR_PUB_KEY", // < -- YOUR PUBLISH KEY!!! **
subscribe_key : "YOUR_SUB_KEY" // < -- YOUR SUBSCRIBE KEY!!! **
});
// Send a message
pubnub.publish({ channel : "chat", message : "hello!" });

PubNub HTTP Pipelining

Sending messages in parallel and in a Single TCP Packet (one Ethernet Frame) is really easy with PubNub HTTP Pipelining! We provide an example below of the Socket level data you send per message. Note that we support the full Pipelining mechanism for HTTP Pipelining. You may send serially on a single socket without waiting for the response and the responses return in order.

Essentially -- To really make this happen with top tier performance you would follow this recipe:

  1. Open 100 TCP sockets to geo1.pubnub.com (closest data center) with fallbacks next closest data center of geo2.pubnub.com geo3.pubnub.com.
  2. Send HTTP/1.1 commands round robin -- without waiting for responses you may continue sending commands! -- Pipelining!
  3. Add socket fail detect or TIMEOUTs as needed for retries.
@stephenlb
stephenlb / pubnub-cname.html
Last active August 29, 2015 13:57
PubNub CNAME Example Origin Usage
<script src=http://cdn.pubnub.com/pubnub.min.js></script>
<script>(function(){
var thespiral = PUBNUB.init({
publish_key : 'demo',
subscribe_key : 'demo',
origin : 'live.thespiral.org', // > dig live.thespiral.org
});
thespiral.subscribe({
@stephenlb
stephenlb / 1.lua
Last active August 29, 2015 13:58 — forked from ToeJamson/1.lua
require "pubnub"
--
-- GET YOUR PUBNUB KEYS HERE:
-- http://www.pubnub.com/account#api-keys
--
multiplayer = pubnub.new({
publish_key = "demo", -- YOUR PUBLISH KEY
subscribe_key = "demo", -- YOUR SUBSCRIBE KEY
secret_key = nil, -- YOUR SECRET KEY
@stephenlb
stephenlb / 1.js
Created May 7, 2014 23:26 — forked from ToeJamson/1.js
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Geo Hash
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function geohash( coord, resolution ) {
var rez = Math.pow( 10, resolution || 0 );
return Math.floor(coord * rez) / rez;
}
set nobackup
set undofile " Undo across sessions
set undolevels=200 " Keep 200 changes to be undone
set undodir=~/.vim/tmp/undo//
nmap <F2> :.w !pbcopy<CR><CR>
vmap <F2> :w !pbcopy<CR><CR>
set noswapfile
set t_Co=256
@stephenlb
stephenlb / publish-lots-of-pubnub-messages.py
Last active August 29, 2015 14:05
Rapid Publishing of Messages on PubNub. You can publish message efficiently using this mechanism. How efficient you ask? This method allows you to publish upwards of 30 messages **Per TCP Packet!**. Wow. See https://gist.github.com/stephenlb/9496723 for more information.
import socket
import uuid
import random
import threading
import time
import random
import math
HOST = 'pubsub.pubnub.com'
PORT = 80
<!--
WAIT! - This file depends on the PUBNUB API.
Visit www.pubnub.com to get your API Key and integration.
To add on your website, go here:
http://www.pubnub.com/app-showcase/traffic-beat
View source code by visiting:
http://github.com/pubnub/PubNub-Traffic-Beat
@stephenlb
stephenlb / subscribe.cs
Last active August 29, 2015 14:06
The Subscribe<string>() method is being used to receive poll answers in realtime via an automatically negotiated protocol like WebSockets, HTTP Streaming, HTTP Long-polling, TCP Streaming and more with automatic recovery of dropped messages. We've made it easy for you to get started by providing this easy-to-use SDK.
// Subscribe To Vote Submissions
pubnub.Subscribe<string>(
pubnubChannel,
DisplayReturnMessage,
DisplaySubscribeConnectStatusMessage,
DisplayErrorMessage
);
// Callback method Receive Votes in JSON string format
static void DisplayReturnMessage(string result)
function self:UUID()
return UUID()
end