Skip to content

Instantly share code, notes, and snippets.

@scalabl3
scalabl3 / xhr.js
Last active January 3, 2019 21:43
Functions XHR Request with Retries
export default (request) => {
const kvstore = require('kvstore');
const xhr = require('xhr');
const vault = require('vault'); // You can use the Vault to store a header/key for your backend
// to validate the request with, alternatively you can use IP whitelist
const host = 'https://f8234c78.ngrok.io';
var url = host + '/v1/webhooks/pubnub';
@scalabl3
scalabl3 / crc32.js
Created October 15, 2018 16:47
Example of using CRC32 to shard
function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
s4() + '-' + s4() + s4() + s4();
}
@scalabl3
scalabl3 / fanin.js
Created October 10, 2016 17:46
FanIn Block
export default (request) => {
const pubnub = require('pubnub');
const kvstore = require('kvstore');
const xhr = require('xhr');
function crc32(str) {
function Utf8Encode(string) {
string = string.replace(/\r\n/g, "\n");
var utftext = "";
@scalabl3
scalabl3 / crc32.js
Created October 10, 2016 17:22
CRC32 in Javascript
function crc32(str) {
function Utf8Encode(string) {
string = string.replace(/\r\n/g, "\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
@scalabl3
scalabl3 / webrtc-pubnub.md
Last active April 27, 2018 18:04
Summary of WebRTC & PubNub

What is WebRTC? [OS]

WebRTC is a Protocol specifically designed for Peer-To-Peer streaming of video + audio. It includes video/audio compression algorithms/codecs, key framing, session control, etc. It does offer some messaging but that part of the protocol doesn't work very well. As a Protocol, like ftp, http, smtp, etc., it requires support at a lower level than the Application tier in most cases. Currently, support for the WebRTC protocol is not on every device/operating system. Notably, Apple devices don't support WebRTC natively. You can see support here: http://iswebrtcreadyyet.com/ and http://caniuse.com/#feat=rtcpeerconnection. Since Apple doesn't support natively, an SDK for iOS is needed, there is an open source one, or you can go with a full service SaaS with an SDK. The upsides of WebRTC is that it is free, works pretty well, and handles automatic upgrading and downgrading of compression/quality based on latency. The downsides of WebRTC is that the standards are still evolving, changing, a

@scalabl3
scalabl3 / timetoken_conversion.md
Last active February 23, 2022 05:54
PubNub Timetoken <-> Epoch Timestamp Conversion
  1. PubNub timetoken:

14459765691299403

  1. Divide by 10000000 (becomes Epoch in seconds if you truncate):

1445976569.1299403

  1. Subtract 1.0 seconds:
@scalabl3
scalabl3 / webrtc.md
Last active April 27, 2018 18:04
WebRTC Resources
@scalabl3
scalabl3 / normalize_callback.js
Last active August 29, 2015 14:27
Normalizing Callback returns on Subscribe and Presence
function normalize_subscribe_message_callback_object(msg, envelope) {
var result = {
channel_group: null,
channel: null,
message: msg
};
// if the message received through channel group
if (envelope.length === 4) {
result.channel_group = envelope[2];
result.channel = envelope[3];
@scalabl3
scalabl3 / gist:8da810423f868b8fd81a
Last active April 15, 2017 02:34
Manual Setup of PubNub SDK in Xcode

Getting Setup with PubNub Manually for iOS

Additional Reference: PubNub Github Repo README Instructions

Important Notes

Make sure that your iOS project (.xcodeproj) is within a Xcode Workspace (.xcworkspace). Being in a workspace rather than a project changes Xcode behavior when drag-dropping files.

If you are only in an .xcodeproj, then it doesn't prompt you with options to "copy items if needed" and automatically creates symlink rather than copy files into project (hence being susceptible to the changes in the original PubNub project).

@scalabl3
scalabl3 / 1_instantiate.html
Last active March 18, 2016 01:29
Getting Started Tutorial for Using PubNub Presence with JavaScript
<!-- Include the PubNub Library -->
<script src="https://cdn.pubnub.com/pubnub.min.js"></script>
<!-- Instantiate PubNub -->
<script type="text/javascript">
var PUBNUB_demo = PUBNUB.init({
publish_key: 'demo',
subscribe_key: 'demo'
});