Skip to content

Instantly share code, notes, and snippets.

View mikepfeiffer's full-sized avatar
🏠
Working from home

Mike Pfeiffer mikepfeiffer

🏠
Working from home
View GitHub Profile
FROM ubuntu:16.04
# Install dependencies
RUN apt-get update
RUN apt-get -y install apache2
# Install apache and write hello world message
RUN echo 'Hello World!' > /var/www/html/index.html
# Configure apache
@mikepfeiffer
mikepfeiffer / index.js
Created December 15, 2018 20:00
Azure Function Code Sample
module.exports = async function (context, req) {
if (req.body.email) {
var email = {
from: {
email: req.body.email
},
subject: "Contact form submission from: " + req.body.name,
content: [{
type: 'text/plain',
value: req.body.message
@mikepfeiffer
mikepfeiffer / function.json
Created December 15, 2018 20:10
Function.json file for Azure Serverless App Demo
{
"disabled": false,
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
@mikepfeiffer
mikepfeiffer / index.js
Created December 16, 2018 18:05
Default HttpTrigger Code Sample for Azure Function (JavaScript)
module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
if (req.query.name || (req.body && req.body.name)) {
context.res = {
// status: 200, /* Defaults to 200 */
body: "Hello " + (req.query.name || req.body.name)
};
}
else {
@mikepfeiffer
mikepfeiffer / index.html
Created December 16, 2018 19:29
Front-end for a Serverless Web App Demo on Azure
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Hello World</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M"
crossorigin="anonymous">
@mikepfeiffer
mikepfeiffer / submitMessage.js
Created December 16, 2018 19:33
Client side code that uses fetch API to submit a form
function submitMessage(e) {
e.preventDefault();
let name = document.getElementById('name').value;
fetch('<YOUR FUNCTION URL GOES HERE>', {
method: 'POST',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-type': 'application/json'
},
@mikepfeiffer
mikepfeiffer / Dockerfile
Created December 26, 2018 19:42
Dockerfile for a bare bones Node & Express app
FROM node:alpine
WORKDIR /usr/app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "start"]
@mikepfeiffer
mikepfeiffer / app.js
Created December 26, 2018 21:12
Simple Node Demo App
const config = require('./config');
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hello World v2!');
});
app.listen(config.port, () => {
@mikepfeiffer
mikepfeiffer / DemoModule.psm1
Created September 18, 2019 18:16
Demo that shows how to use a utility function inside a PS Module
#private function
function new-baseEncode ($pat) {
$encoded = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes((":{0}" -f $pat)))
Write-Output $encoded
}
#public function
function New-EncodedMessage ($name, $data) {
$encoded = new-baseEncode $data
@mikepfeiffer
mikepfeiffer / gist:d889b3bc78b68193e407d487b197be04
Created May 9, 2016 20:39
EC2 user data script to bootstrap instance with CloudWatch sample scripts
#!/bin/bash
yum install perl-Switch perl-DateTime perl-Sys-Syslog perl-LWP-Protocol-https -y
curl http://aws-cloudwatch.s3.amazonaws.com/downloads/CloudWatchMonitoringScripts-1.2.1.zip -O
unzip CloudWatchMonitoringScripts-1.2.1.zip
rm CloudWatchMonitoringScripts-1.2.1.zip