Skip to content

Instantly share code, notes, and snippets.

View ShMcK's full-sized avatar

Shawn McKay ShMcK

View GitHub Profile
@ShMcK
ShMcK / twilio-multiple.js
Last active March 10, 2018 19:27
twilio-multiple.js
const twilio = require('./utils/twilio');
class TwilioSMS {
constructor(messagingServiceSid, account) {
this.from = messagingServiceSid;
this.sms = twilio.init(account);
this.sendSMS = ({ to, body }) => this.sms.create({ to, body, messagingServiceSid: this.from });
this.attempts = 0;
}
send(to, body) {
@ShMcK
ShMcK / twilio-wrapper.js
Created March 10, 2018 19:29
twilio-wrapper.js
const twilio = require('twilio');
// created in order to stub twilio in tests
module.exports = {
init: () => twilio(ACCOUNT_ID, AUTH_TOKEN).messages,
};
@ShMcK
ShMcK / expo-pn-listener.js
Last active March 10, 2018 20:28
expo-pn-listener
import { Notifications } from 'expo'
Notifications.addListener(async ({ data, origin }) => {
if (origin === 'received') {
// trigger modal
} else if (origin === 'selected') {
// route to page with linked data
}
})
@ShMcK
ShMcK / expo-message-server.js
Created March 10, 2018 20:34
simple expo message server demo
const Expo = require('expo-server-sdk')
const expo = new Expo()
async function send(messages) {
const chunks = expo.chunkPushNotifications(messages)
for (const chunk of chunks) {
try {
const receipts = await expo.sendPushNotificationsAsync(chunk)
receipts.forEach(receipt => {
if (receipt.status === 'error') {
@ShMcK
ShMcK / branch-server.js
Created March 10, 2018 20:58
branch server
class DeepLink {
constructor(branchKey) {
this.key = branchKey;
this.url = 'https://api.branch.io/v1/url';
}
request(data) {
return fetch(this.url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@ShMcK
ShMcK / branch-expo.js
Created March 10, 2018 21:01
Branch Expo
import { DangerZone } from 'expo'
const { Branch } = DangerZone
Branch.subscribe((bundle) => {
if (bundle && bundle.params && !bundle.error) {
// handle link
}
})
@ShMcK
ShMcK / react-navigation-link.js
Created March 11, 2018 04:51
deep linking in react navigation
@ShMcK
ShMcK / notification-permissions-expo.js
Created March 12, 2018 20:32
Notification Permissions
import { Permissions } from 'expo'
export default async function verifyPushNotificationsPermissions() {
const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS)
let finalStatus = existingStatus
// only ask if permissions have not already been determined, because
// iOS won't necessarily prompt the user a second time.
if (existingStatus !== 'granted') {
// Android remote notification permissions are granted during the app
@ShMcK
ShMcK / reactXState.js
Last active May 24, 2018 03:20
React XState Context API wrapper
import React from 'react'
const capitalize = (string) => string.charAt(0).toUpperCase() + string.slice(1)
// lib, returns Context.Provider, Context.
function reactXState ({ name, machine, actions }) {
name = name || 'defaultName'
const Context = React.createContext(name)
DrawerOpen*
loadTape -> HasTape
closeDrawer -> NoTape
DrawerClosed
eject -> DrawerOpen
NoTape
HasTape*