Skip to content

Instantly share code, notes, and snippets.

View chandler767's full-sized avatar

Chandler Mayo chandler767

View GitHub Profile
platform :ios, '11.0'
use_frameworks!
target 'PubNub Demo' do
pod 'PubNub', '~> 4.0'
end
@chandler767
chandler767 / SlackPost.JS
Created March 8, 2019 22:22
Slack Incoming Webhooks provide an easy way to post messages to Slack from a PubNub Function.
// FOR A PUBNUB SERVERLESS ENV.
// Learn More: https://api.slack.com/incoming-webhooks
export default (request, response) => {
const xhr = require('xhr');
// Message
let message = `Hello World!`;
// Slack Webhook URL
const url = "SLACK-WEBHOOK-URL-HERE";
// Basic Slack Post
const http_options = {
@chandler767
chandler767 / StripeCharge.JS
Last active March 8, 2019 20:12
Charge a customer token from a PubNub Function in a serverless environment using Stripe.
// DO NOT USE THIS CODE CLIENT SIDE. FOR A PUBNUB SERVERLESS ENV ONLY.
// Set the module event type to "On Request".
// Create a token with Stripe.JS: https://stripe.com/docs/stripe-js
// Or use a test token: token=tok_visa
export default (request, response) => {
const vault = require("vault");
const xhr = require("xhr");
const token = request.params.token;
return vault.get("stripe_secret_key").then((apiKey) => {
const http_options = {
@chandler767
chandler767 / Add to bash_profile #Android #ReactNative
Last active August 23, 2018 15:06
[React Native Push Notifications With PubNub] How to implement push notifications in a React Native app using PubNub. Tutorial here: https://www.pubnub.com/blog/react-native-push-notifications/ #PubNub #Push-Notifications #ReactNative
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
@chandler767
chandler767 / blankreactproject.js
Last active July 20, 2018 23:02
UV Index Monitor App that subscribes to PubNub and displays the UV index value. Code snippets for blog post. See project here: https://github.com/chandler767/PubNub-UV-Index-Monitor/
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
type Props = {};
export default class App extends Component<Props> {
render() {
return (
);
}
}
@chandler767
chandler767 / loop.ino
Last active July 26, 2018 15:25
Reads the current UV index level once per minute and publishes the value to PubNub when the value changes and at least once every 10 minutes. Code snippets for blog post. See project here: https://github.com/chandler767/PubNub-UV-Index-Monitor/
void loop() {
sensorTimer = (sensorTimer + 1); // Add a second to the sensor timer.
if (sensorTimer == 60) { // Check sensor.
sensorTimer = 0; // Reset timer.
sendTimer = (sendTimer + 1); // Add a minute to sendTimer.
if (sendTimer == 10) { // Reset timer after 10 minutes.
sendTimer = 0; // Reset timer.
}
sensorValue = analogRead(A0); // Read sensor. Convert to UV index.
if ((sensorValue >= 0) && (sensorValue < 20)) {
@chandler767
chandler767 / indicator.ino
Last active July 17, 2018 21:57
UV Index Indicator subscribes to PubNub and displays the UV index value using color. Code snippets for blog post. See project here: https://github.com/chandler767/PubNub-UV-Index-Monitor/
#include <ESP8266WiFi.h>
#define PubNub_BASE_CLIENT WiFiClient
#include <PubNub.h>
const static char ssid[] = "Sensor Network";
const static char pass[] = "sens0rpassw0rd";
int rled = 14; // The PWM pins the LED is attached to.
int gled = 12;
int bled = 15;
@chandler767
chandler767 / pubnub-ESP8266.ino
Last active November 13, 2020 10:11
Pubnub Arduino SDK code sample for ESP8266. Demonstrates publish and subscribe. Get your unique PubNub keys from the PubNub Developer Portal (https://admin.pubnub.com/?devrel_gh=PubNub-UV-Index-Monitor ). If you don't have a PubNub account, you can sign up for a PubNub account for free (https://dashboard.pubnub.com/signup/?devrel_gh=PubNub-UV-In…
#include <ESP8266WiFi.h>
#define PubNub_BASE_CLIENT WiFiClient
#include <PubNub.h>
const char* ssid = "YourSSID";
const char* password = "YourPASSWORD";
const char* channelName = "hello_world";
void setup() {
Serial.begin(9600);
@chandler767
chandler767 / GoFizzBuzz.go
Last active February 2, 2018 20:39
Write a program that prints numbers from 1 to N. But for multiples of three print “Fizz” instead of the number, and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz".
package main
import "fmt"
func main() {
n := 15
for i:=1; i<=n; i++ {
if (i%3 == 0) && (i%5 == 0) {
fmt.Println("FizzBuzz")
} else if i%3 == 0 {
@chandler767
chandler767 / isprime.go
Created January 30, 2018 01:14
Function to determine if a number is prime in Go.
package main
import "fmt"
func main(){
fmt.Println(isPrime(4))
fmt.Println(isPrime(7))
fmt.Println(isPrime(1616161))
}
/**