Skip to content

Instantly share code, notes, and snippets.

View pbzona's full-sized avatar
🤠
having fun on the computer

Phil Z pbzona

🤠
having fun on the computer
View GitHub Profile
@pbzona
pbzona / index.js
Created April 30, 2018 21:59
Serverless Weather pt 3
// Make the request using axios, a promise-based HTTP library
axios.get(weatherURL).then((response) => {
// Once the response is received, pull the different parameters we'll need and save them as variables
const tomorrow = response.data.daily.data[1];
const high = Math.round(tomorrow.temperatureHigh);
const low = Math.round(tomorrow.temperatureLow);
const precip = Math.round(tomorrow.precipProbability * 100);
const summary = tomorrow.summary;
@pbzona
pbzona / index.js
Created April 30, 2018 21:55
Serverless Weather pt 2
exports.handler = (event, context, callback) => {
// Construct the URL to make weather forecast requests
const weatherURL = `https://api.darksky.net/forecast/${API_KEY}/${COORDS}?exclude=currently,minutely,hourly,flags`;
@pbzona
pbzona / index.js
Created April 30, 2018 21:49
Serverless Weather pt 1
'use strict';
const AWS = require('aws-sdk');
const SNS = new AWS.SNS();
// In addition to the AWS SDK, we'll use axios to help make our requests
const axios = require('axios');
// Make sure to define these environment variables in the template.yaml file
const API_KEY = process.env.API_KEY;
const COORDS = process.env.COORDS;
@pbzona
pbzona / Example Policy Document
Created April 30, 2018 20:03
lambdaWeather IAM role
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "sns:Publish",
"Resource": "*"
}
]
@pbzona
pbzona / index.html
Created April 23, 2018 00:41
Serverless contact form with inline success message
<!DOCTYPE html>
<html>
<head>
<title>My Contact Form Microservice</title>
<style>
/* It's not pretty, but it'll do :) */
input,
textarea {
display: block;
margin: 20px;
@pbzona
pbzona / index.js
Created April 20, 2018 16:05
Displaying success or error page
fetch(lambdaRequest)
.then(response => {
window.location.replace('https://yoursite.com/success-page');
})
.catch(err => {
window.location.replace('https://yoursite.com/error-page');
});
@pbzona
pbzona / iam.json
Created April 7, 2018 19:55
something
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"iam:*",
"lambda:*",
"ses:*",
@pbzona
pbzona / index.html
Last active February 28, 2018 16:24
Serverless contact form with reset on submission
<!DOCTYPE html>
<html>
<head>
<title>My Contact Form Microservice</title>
<style>
/* It's not pretty, but it'll do :) */
input,
textarea {
display: block;
margin: 20px;
@pbzona
pbzona / bands.txt
Created January 24, 2018 19:21
List of bands that have appeared on Vans Warped Tour
# List of bands that have appeard on the Vans Warped Tour
# Scraped from https://en.wikipedia.org/wiki/List_of_Warped_Tour_lineups_by_year
# Possibly not a complete list but it's the best I got
3OH!3
'68
5606
A+ Dropouts
Aaron West and the Roaring Twenties
Abriel
@pbzona
pbzona / mappings.rb
Created November 21, 2017 21:30
CloudFormations - Mapping example in Ruby
region_map = {
“us-east-1”: {“32”: “ami-6411e20d”, “64”: "ami-7a11e213"},
“us-west-2”: {“32”: “ami-c9c7978c”, “64”: "ami-cfc7978a"}
}
puts region_map[“us-east-1”]["32"]