Skip to content

Instantly share code, notes, and snippets.

@sunnygleason
sunnygleason / pubnub_kvstore_ui.html
Created April 21, 2017 16:59
Advanced BLOCKS Techniques - KV Store UI
<!DOCTYPE html>
<html>
<head>
<title>Angular 2</title>
<script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script>
<script src="https://unpkg.com/zone.js@0.7.2/dist/zone.js"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.9/Reflect.js"></script>
<script src="https://unpkg.com/rxjs@5.0.1/bundles/Rx.js"></script>
<script src="https://unpkg.com/@angular/core/bundles/core.umd.js"></script>
@sunnygleason
sunnygleason / pubnub_kvstore_block.js
Created April 21, 2017 16:37
Advanced BLOCKS Techniques - KV Store BLOCK
export default (request) => {
const db = require('kvstore');
var by = request.message.by || request.params.uuid;
var last_key = by + ":last_msg";
var count_key = by + ":count";
if (request.message && (request.message.text == '/my_stats')) {
//
// special "my_stats" command handling
@sunnygleason
sunnygleason / pubnub_events_ui.html
Last active April 19, 2017 19:15
Advanced BLOCKS Techniques - Event Types UI
<!DOCTYPE html>
<html>
<head>
<title>Angular 2</title>
<script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script>
<script src="https://unpkg.com/zone.js@0.7.2/dist/zone.js"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.9/Reflect.js"></script>
<script src="https://unpkg.com/rxjs@5.0.1/bundles/Rx.js"></script>
<script src="https://unpkg.com/@angular/core/bundles/core.umd.js"></script>
@sunnygleason
sunnygleason / pubnub_events_block.js
Created April 19, 2017 18:38
Advanced BLOCKS Techniques - Event Types BLOCK
export default (request) => {
const pubnub = require('pubnub');
var message = "Welcome, ";
var punctuation = "!";
if (request.message.action == 'join') {
message = "Welcome, ";
punctuation = "!";
} else if (request.message.action == 'timeout') {
@sunnygleason
sunnygleason / pubnub_encrypt_block.js
Created April 19, 2017 14:33
Advanced BLOCKS Techniques - Channel Encryption & Meta Attributes BLOCK
export default (request) => {
// NOTE: message metadata attributes are stored in `request.params.meta`
// NOTE: overall metadata attributes are stored in `request.meta`
// NOTE: message metadata attributes are a JSON string, read-write, but must be parsed/stringified to change
// NOTE: overall metadata attributes are read-only
if (request && request.params && request.params.meta) {
let attrs = JSON.parse(request.params.meta);
// to show attrs or request, uncomment:
// console.log(attrs);
@sunnygleason
sunnygleason / pubnub_encrypt_ui.html
Last active April 19, 2017 14:32
Advanced BLOCKS Techniques - Channel Encryption & Meta Attributes UI
<!DOCTYPE html>
<html>
<head>
<title>Angular 2</title>
<script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script>
<script src="https://unpkg.com/zone.js@0.7.2/dist/zone.js"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.9/Reflect.js"></script>
<script src="https://unpkg.com/rxjs@5.0.1/bundles/Rx.js"></script>
<script src="https://unpkg.com/@angular/core/bundles/core.umd.js"></script>
@sunnygleason
sunnygleason / pubnub_aiception_ui.html
Created March 21, 2017 22:17
PubNub Image Recognition UI w/ AIception
<!DOCTYPE html>
<html>
<head>
<title>Angular 2</title>
<script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script>
<script src="https://unpkg.com/zone.js@0.7.2/dist/zone.js"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.9/Reflect.js"></script>
<script src="https://unpkg.com/rxjs@5.0.1/bundles/Rx.js"></script>
<script src="https://unpkg.com/@angular/core/bundles/core.umd.js"></script>
@sunnygleason
sunnygleason / pubnub_aiception_block.js
Created March 21, 2017 20:43
PubNub Image Recognition BLOCK w/ AIception
export default (request) => {
const xhr = require('xhr');
const base64 = require('codec/base64');
const authToken = 'YOUR_AUTH_TOKEN';
const url = "https://aiception.com/api/v2.1/detect_object";
const httpOptions = {
"method": "POST",
"timeout": 10000,
@sunnygleason
sunnygleason / pubnub_wia_ui.html
Last active March 19, 2017 17:26
PubNub IoT Messaging UI w/ Wia
<!DOCTYPE html>
<html>
<head>
<title>Angular 2</title>
<script src="https://unpkg.com/core-js@2.4.1/client/shim.min.js"></script>
<script src="https://unpkg.com/zone.js@0.7.2/dist/zone.js"></script>
<script src="https://unpkg.com/reflect-metadata@0.1.9/Reflect.js"></script>
<script src="https://unpkg.com/rxjs@5.0.1/bundles/Rx.js"></script>
<script src="https://unpkg.com/@angular/core/bundles/core.umd.js"></script>
@sunnygleason
sunnygleason / pubnub_wia_block.js
Created March 14, 2017 22:06
PubNub IoT Messaging BLOCK w/ Wia
export default (request) => {
const xhr = require('xhr');
const authKey = request.message.authKey;
const url = "https://api.wia.io/v1/events";
const http_options = {
"method": "POST",
"headers": {
"Content-Type": "application/json",