Skip to content

Instantly share code, notes, and snippets.

View chrisckchang's full-sized avatar
🎯
Focusing

Christopher Chang chrisckchang

🎯
Focusing
View GitHub Profile
@chrisckchang
chrisckchang / direct-did-dial.py
Created October 18, 2019 20:42
Amazon Connect example: Direct inbound DID dial to agent
import boto3
def lambda_handler(event, context):
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('agentNumbersDb')
print(event)
## Find which number was dialed by customer.
## You may need to do some string manipulation to remove the "+" in the phone number.
dialedNumber = event['Details']['SystemEndpoint']['Address']
@chrisckchang
chrisckchang / sns-express-example.js
Created April 9, 2018 19:18
Express app that subscribes to SNS and displays notifications
var express = require('express')
var app = express()
var request = require('request')
var bodyParser = require('body-parser')
// Middleware to convert SNS request message body from plain text to JSON
var convertToJson = function (req, res, next) {
if (req.headers['x-amz-sns-message-type']) {
req.headers['content-type'] = 'application/json;charset=UTF-8';
}
@chrisckchang
chrisckchang / app.js
Created September 29, 2015 01:07
Contact list Angular homepage-specific code
angular.module("contactsApp", ['ngRoute'])
.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl: "list.html",
controller: "ListController",
resolve: {
contacts: function(Contacts) {
return Contacts.getContacts();
}
@chrisckchang
chrisckchang / server.js
Created September 28, 2015 21:48
Contact list app - complete server.js file
var express = require("express");
var path = require("path");
var bodyParser = require("body-parser");
var mongodb = require("mongodb");
var ObjectId = require("mongodb").ObjectID;
var app = express();
app.use(express.static(__dirname + "/public"));
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
@chrisckchang
chrisckchang / server.js
Created September 28, 2015 21:07
Contact list /contacts POST request
app.post("/contacts", function(req, res) {
var newDoc = req.body;
newDoc.createDate = new Date();
if (req.body.firstName === undefined || req.body.lastName === undefined) {
handleError(null, res, "Must provide a contact name.");
}
if (req.body.email === undefined) {
handleError(null, res, "Must provide an email.");
@chrisckchang
chrisckchang / data-model.js
Created September 25, 2015 23:05
Contact data model
{
"_id": <ObjectId>
"firstName": <string>,
"lastName": <string>,
"email": <string>,
"phoneNumbers": {
"mobile": <string>,
"work": <string>
}
"twitterHandle": <string>,
@chrisckchang
chrisckchang / app.js
Created July 24, 2015 01:28
Todolist Angular routeProvider
angular.module("todolists", ["ui.bootstrap", "ui", "ngRoute"])
.config(function($routeProvider) {
$routeProvider
.when("/", {
controller: "TodolistController as todolist",
templateUrl: "todolists.html",
resolve: {
todolists: function(Todolists) {
return Todolists.getTodolists();
}
@chrisckchang
chrisckchang / data-model.js
Last active September 11, 2015 21:25
Todolist and Todo schema
// Todolist
{
_id: <string>,
name: <string>,
createDate: <Date>,
[todos: <Array>] // <Array of Todos">?
}
// Todo
{
@chrisckchang
chrisckchang / app.js
Last active September 11, 2015 21:38
Todolist POST endpoint
//comments: We’ve added some basic input validation to ensure that the basic requirement that every todo list has a name is met.
app.post("/todolists", function(req, res) {
var postQuery = {createDate: new Date()};
if (req.body.name == "undefined") {
handleError(null, res, "Must provide a todolist name");
}
postQuery.name = req.body.name;
@chrisckchang
chrisckchang / server.js
Last active February 21, 2017 14:00
Contact list app initialization and database connection
var express = require("express");
var path = require("path");
var bodyParser = require("body-parser");
var mongodb = require("mongodb");
var ObjectID = mongodb.ObjectID;
var CONTACTS_COLLECTION = "contacts";
var app = express();
app.use(express.static(__dirname + "/public"));