Skip to content

Instantly share code, notes, and snippets.

View mmccall10's full-sized avatar
🐢
💻

Mike McCall mmccall10

🐢
💻
View GitHub Profile
@mmccall10
mmccall10 / Mutation.createProduct.vtl
Last active November 1, 2021 13:50
Helper to build AppSync CDK mapping templates in a single
#set($id = $util.autoId())
#set($pk = "PRODUCT#$id")
{
"version" : "2018-05-29",
"operation" : "PutItem",
"key" : {
"PK" : $util.dynamodb.toDynamoDBJson($pk),
"SK" : $util.dynamodb.toDynamoDBJson($pk)
},
"attributeValues" : $util.dynamodb.toMapValuesJson($ctx.args.input)
@mmccall10
mmccall10 / EnforceAppSyncResolverNaming.ts
Last active October 18, 2021 14:32
AWS CDK Aspect to enforce consistent naming of AppSync resolvers
import { CfnResolver } from '@aws-cdk/aws-appsync'
import { IConstruct } from '@aws-cdk/core'
interface IAspect {
visit: (node: IConstruct) => void
}
class EnforceAppSyncResolverNaming implements IAspect {
visit (node: IConstruct): void {
if (node instanceof CfnResolver) node.overrideLogicalId(`${node.typeName}${node.fieldName}Resolver`)
@mmccall10
mmccall10 / unique_script.sh
Created October 4, 2018 15:34
Bash script to run other scripts uniquely
#!/bin/bash
PIDFILE=$2
SCRIPT=$1
if [ -f $PIDFILE ]
then
PID=$(cat $PIDFILE)
ps -p $PID > /dev/null 2>&1
if [ $? -eq 0 ]
then
[program:sqs-alertify]
command=python3 /Project/Path/sqsnotify/main.py
autostart=true
autorestart=true
numprocs=1
redirect_stderr=true
stdout_logfile=/Project/Path/sqsnotify/sqs_alertify.log
[supervisord]
@mmccall10
mmccall10 / sqs_alertify.py
Created November 14, 2017 21:05
Local notification with sqs and mac
import boto3
import subprocess
# Get the sqs resource
sqs = boto3.resource('sqs')
# Get the queue
queue = sqs.get_queue_by_name(QueueName='Alertify')
# endless loop
@mmccall10
mmccall10 / app.module.ts
Last active September 27, 2017 16:15
App module that includes the HttpModule
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
declarations: [
@mmccall10
mmccall10 / app.component.ts
Created September 26, 2017 05:45
Article embed file upload in progress
import {Component, ElementRef, ViewChild} from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
acceptedMimeTypes = [
@mmccall10
mmccall10 / environment.ts
Created September 25, 2017 22:56
Angular environment with apiUrl paramenter (article embed)
export const environment = {
production: false,
apiUrl: <your api url> // i.e.'https://beepboop.execute-api.us-west-2.amazonaws.com/Prod'
};
@mmccall10
mmccall10 / lambda.js
Last active January 31, 2018 17:24
Upload file to s3 lambda (article embed)
const AWS = require('aws-sdk');
const fileType = require('file-type');
const config = new AWS.Config({
accessKeyId: process.env.ACCESS_KEY_ID,
secretAccessKey: process.env.SECRET_ACCESS_KEY,
region: process.env.REGION
});
AWS.config.update(config);
@mmccall10
mmccall10 / app.component.ts
Last active September 27, 2017 16:30
File input form events final (article embed)
import {Component, ElementRef, ViewChild} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {environment} from '../environments/environment';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {