Skip to content

Instantly share code, notes, and snippets.

@ajb413
ajb413 / index.js
Created March 15, 2018 04:20
eth-event-megaphone from my repo
// Libs
const PubNub = require('pubnub');
const Web3 = require('web3');
const ContractBuild = require('PATH_TO_TRUFFLE/build/contracts/Token.json');
// PubNub
pubnub = new PubNub({
publishKey : '__YOUR_PUB_KEY__',
subscribeKey : '__YOUR_SUB_KEY__'
});
@ajb413
ajb413 / onRequest.js
Created March 15, 2018 05:45
Serverless Token Validation Microservice
export default (request, response) => {
const vault = require('vault');
let paramsObject = request.params;
return vault.get('myToken').then((token) => {
if (paramsObject.token === token) {
response.status = 200;
return response.send();
} else {
@ajb413
ajb413 / index.html
Created March 15, 2018 05:45
Serverless Token Validation Microservice Test UI
<!DOCTYPE html>
<html>
<head>
<title>Token Validator</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
</head>
<body>
<input id="text" type="text">
<input id="submit" type="submit">
<p id="serverResponse"></p>
@ajb413
ajb413 / index.html
Created March 15, 2018 16:34
Currently Online Users Widget with PubNub
<!DOCTYPE html>
<html>
<head>
<title>Currently Active Demo</title>
<style type="text/css">
.currently-active {
position: fixed;
margin: 10px;
padding: 5px;
bottom: 0;
@ajb413
ajb413 / index.html
Last active March 22, 2018 21:45
Import ChatEngine Example snippet
<script src="https://cdn.jsdelivr.net/npm/chat-engine@0.9.5/dist/chat-engine.min.js"></script>
<script>
// WARNING! - Get PubNub API keys and run the ChatEngine setup:
// https://www.pubnub.com/docs/tutorials/chatengine#step-one-pubnub-keys
// Make sure to import ChatEngine first!
const ChatEngine = ChatEngineCore.create({
publishKey: '__your_PubNub_Publish_key__',
subscribeKey: '__your_PubNub_Subscribe_key__'
}, {
globalChannel: 'chat-engine-demo'
@ajb413
ajb413 / app.js
Last active March 22, 2018 23:38
aws blog snippet
// Be sure to replace strings with your own App's Publish & Subscribe keys
// Also replace the REST endpoint with your own On Request handler
var userPubKey = '__PUBNUB_PUBLISH_KEY__';
var userSubKey = '__PUBNUB_SUBSCRIBE_KEY__';
var pollyFunctionURI = 'https://pubsub.pubnub.com/v1/blocks/sub-key/__SUB_KEY__/__URI__';
@ajb413
ajb413 / app.js
Created March 23, 2018 17:02
polly get audio function for AWS demo
// Polly Button click event handler from app.js
function (e) {
var _app = this;
if (e.dataset.voiceAudioContent) {
_app.play(e.dataset.voiceAudioContent);
return;
} else {
$.ajax({
method: "POST",
url: pollyFunctionURI,
@ajb413
ajb413 / onBefore.js
Last active March 28, 2018 23:31
Sample PubNub Function
// PubNub Functions event handler
// Deploy globally in minutes at https://admin.pubnub.com/
// Specify one channel or all with '*' in the editor
// Use `xhr.fetch(url).then()` to do an HTTP request
const xhr = require("xhr");
export default (request) => {
@ajb413
ajb413 / app.js
Created March 29, 2018 00:03
Amazon Comprehend ChatEngine demo snippet
// Be sure to replace strings with your own App's Publish & Subscribe keys
// Also replace the REST endpoint with your own On Request handler
var userPubKey = '__PUBNUB_PUBLISH_KEY__';
var userSubKey = '__PUBNUB_SUBSCRIBE_KEY__';
var comprehendFunctionURI = 'https://pubsub.pubnub.com/v1/blocks/sub-key/__SUB_KEY__/__URI__';
@ajb413
ajb413 / app.js
Created March 29, 2018 00:25
Amazon Comprehend code snippet
this.sentimentAnalysis(plainText, message.timetoken)
.then(function(id, sentiment) {
var messageInfoSpan = $('span[data-identifier="' + id + '"]');
var messageDiv = $('div[data-identifier="' + id + '"]');
if (sentiment.Sentiment &&
sentiment.SentimentScore &&
sentiment.SentimentScore.Negative &&
sentiment.SentimentScore.Positive
) {