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 / pam-example.php
Last active January 3, 2016 15:38
UPDATE - OFFICIAL PHP PAM SDK NOW HERE - https://github.com/pubnub/php -- PubNub Access Manager (PAM) PHP Full Library for Granting and Revoking Access in Real-Time on the PubNub Real-Time Network.
<?php
// UPDATE - OFFICIAL PHP PAM SDK NOW HERE - https://github.com/pubnub/php
require('pam.php');
## PubNub Access Manager (PAM)
$manager = new access(
"pub-c-e132b7b4-0c2c-4d36-a828-1de1ea50d167",
"sub-c-f95db694-6ff9-11e3-9291-02ee2ddab7fe",
@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;
}
@stephenlb
stephenlb / pubnub-post.js
Last active December 15, 2022 21:19
PubNub POST Gzip Examples
var http = require("http");
var zlib = require("zlib");
exports.publish = function(msg) {
var req = http.request({
"host" : "pubsub.pubnub.com",
"method" : "POST",
"path" : "/publish/demo/demo/0/my_channel/0",
"headers" : {
"Content-Encoding" : "gzip",
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 / parse-cloud-publish-to-pubnub.js
Last active September 28, 2016 09:20
Combining Parse API with PubNub Realtime Messaging - By combining the Parse API with PubNub Data Streams you will have a better starting point rather than building a custom backend from scratch.
var pubnub = {
'publish_key' : 'demo',
'subscribe_key' : 'demo'
};
var bob_channel = "channel-bob";
var sally_channel = "channel-sally";
var message = {
"from" : "Sally",
@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