Skip to content

Instantly share code, notes, and snippets.

View welbesw's full-sized avatar
💭
Swifting

William Welbes welbesw

💭
Swifting
View GitHub Profile
@welbesw
welbesw / coffeeBrewed.js
Created January 31, 2019 20:04
Coffee Brewed Lambda Function
const AWS = require('aws-sdk');
const https = require('https');
const DynamoDB = new AWS.DynamoDB();
const SLACK_PROTOCOL = 'https:';
const SLACK_HOST = 'hooks.slack.com';
const SLACK_PATH = '/services/YOUR-SLACK-PATH-HERE';
async function postToSlack(event) {
var coffeeType = event.clickType == 'SINGLE' ? 'Regular' : 'Decaf'
@welbesw
welbesw / costSummary-index.js
Created October 1, 2018 16:10
Lambda function to get current month cost summary
var AWS = require('aws-sdk');
exports.handler = (event, context, callback) => {
var now = new Date();
var startDate = new Date(now.getFullYear(), now.getMonth(), 1);
var endDate = new Date(now.getFullYear(), now.getMonth() + 1, 1)
if (now.getMonth() == 12) {
endDate = new Date(now.getFullYear() + 1, 1, 1)
}
@welbesw
welbesw / PushManager.swift
Created March 7, 2018 23:56
A simple push notification manager.
import UIKit
import UserNotifications
protocol PushManagerDelegate {
func pushManagerUpdated()
}
class PushManager: NSObject {
static let sharedInstance = PushManager()
@welbesw
welbesw / AppDelegate.swift
Created March 7, 2018 23:52
Push Assign UNUserNotificationCenter delegate
import UIKit
import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
class ContactsViewController: UITableViewController {
private var contacts:[SalesforceContact] = []
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
reloadContacts()
}
public class SalesforceContact {
public var id: String?
public var firstName: String?
public var lastName: String?
public var email: String?
//Method to initialize with JSON dict returned by the API
public init(dictionary: [String : AnyObject]) {
func fetchContacts(completion completion: (contacts: [SalesforceContact], error: NSError?) -> ()) {
//TODO: Confirm that user is authenticated
let request = SFRestAPI.sharedInstance().requestForQuery("SELECT Id, FirstName, LastName, Email FROM Contact")
SFRestAPI.sharedInstance().sendRESTRequest(request, failBlock: { (error) in
//Handle the error
print("sendRESTRequest error: \(error.localizedDescription)")
}) { (response) in
//Parse the response
print("sendRESTRequest response")
func launch() {
SalesforceSDKManager.sharedManager().launch()
}
func setupSDKManager() {
let salesforceSDKManager = SalesforceSDKManager.sharedManager()
salesforceSDKManager.connectedAppId = self.consumerKey
salesforceSDKManager.connectedAppCallbackUri = self.redirectUrl
salesforceSDKManager.authScopes = ["web", "api"]
//Post launch action handler
salesforceSDKManager.postLaunchAction = { launchActionList in
let launchActionString = SalesforceSDKManager.launchActionsStringRepresentation(launchActionList)
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
override init() {
super.init()
//Setup the SalesforceManager
SalesforceManager.sharedInstance.setupSDKManager()