Skip to content

Instantly share code, notes, and snippets.

😀
Coding with Rust

Stephen Blum stephenlb

😀
Coding with Rust
Block or report user

Report or block stephenlb

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@stephenlb
stephenlb / get-started-websockets.html
Last active Aug 29, 2015
Easy Get Started Guide with JavaScript Websockets.
View get-started-websockets.html
<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!" });
View PubNub-HTTP-PIPELINGING.md

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 Aug 29, 2015
PubNub CNAME Example Origin Usage
View pubnub-cname.html
<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({
View 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
View 1.js
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Geo Hash
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
function geohash( coord, resolution ) {
var rez = Math.pow( 10, resolution || 0 );
return Math.floor(coord * rez) / rez;
}
View .vimrc
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 Aug 29, 2015
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.
View publish-lots-of-pubnub-messages.py
import socket
import uuid
import random
import threading
import time
import random
import math
HOST = 'pubsub.pubnub.com'
PORT = 80
View traffic-beat.html
<!--
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 Aug 29, 2015
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.
View subscribe.cs
// Subscribe To Vote Submissions
pubnub.Subscribe<string>(
pubnubChannel,
DisplayReturnMessage,
DisplaySubscribeConnectStatusMessage,
DisplayErrorMessage
);
// Callback method Receive Votes in JSON string format
static void DisplayReturnMessage(string result)
View uuid-function.lua
function self:UUID()
return UUID()
end
You can’t perform that action at this time.