Skip to content

Instantly share code, notes, and snippets.

Coding with Rust

Stephen Blum stephenlb

Coding with Rust
View GitHub Profile
stephenlb / get-started-websockets.html
Last active Aug 29, 2015
Easy Get Started Guide with JavaScript Websockets.
View get-started-websockets.html
<script src=""></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 (closest data center) with fallbacks next closest data center of
  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 / pubnub-cname.html
Last active Aug 29, 2015
PubNub CNAME Example Origin Usage
View pubnub-cname.html
<script src=></script>
var thespiral = PUBNUB.init({
publish_key : 'demo',
subscribe_key : 'demo',
origin : '', // > dig
View 1.lua
require "pubnub"
multiplayer ={
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 /
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 for more information.
import socket
import uuid
import random
import threading
import time
import random
import math
HOST = ''
PORT = 80
View traffic-beat.html
WAIT! - This file depends on the PUBNUB API.
Visit to get your API Key and integration.
To add on your website, go here:
View source code by visiting:
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
// Callback method Receive Votes in JSON string format
static void DisplayReturnMessage(string result)
View uuid-function.lua
function self:UUID()
return UUID()
You can’t perform that action at this time.