Skip to content

Instantly share code, notes, and snippets.

View daaru00's full-sized avatar
🐢

Fabio Gollinucci daaru00

🐢
View GitHub Profile
@daaru00
daaru00 / App.vue
Last active November 21, 2020 22:54
Storyblok rich text render component
<template>
<div id="app">
<!-- get page data -->
<vs-rich-text :document="doc" />
</div>
</template>
@daaru00
daaru00 / lambda.js
Last active February 13, 2021 15:31
AWS CloudFormation manage secrets with System Manager Parameter
const axios = require('axios')
/**
* AWS clients
*/
const SSM = require('aws-sdk/clients/ssm')
const ssm = new SSM()
/**
* Lambda handler
@daaru00
daaru00 / abstract.js
Last active February 13, 2021 15:32
DynamoDB model helper (with promise wrapper)
const DynamoDB = require('aws-sdk/clients/dynamodb')
const documentClient = new DynamoDB.DocumentClient({
apiVersion: '2012-08-10',
// logger: console
})
module.exports = class Model {
/**
* Model constructor
@daaru00
daaru00 / template.yml
Created July 8, 2021 14:51
A SAM template that describe an AWS CodeBuild pipeline that build a static website and deploy it to an S3 Bucket and invalidate the CloudFront distribution.
AWSTemplateFormatVersion: 2010-09-09
Transform:
- AWS::Serverless-2016-10-31
# Template Information
Description: "Personal Website Deploy Pipeline"
# Template Parameters
@daaru00
daaru00 / useEvents.js
Last active December 28, 2021 11:28
Vue 3 composition API events bus implementation
const eventBus = new Comment('global-event-bus');
const listeners = {};
export const EVENT_NAME = 'MyEventName';
export default function () {
/**
* @param {string} event
* @param {function} callback
* @returns {number} index
@daaru00
daaru00 / index.js
Created August 5, 2022 14:01
X-Ray integration with Lambda
const AWSXRay = require('aws-xray-sdk')
AWSXRay.setLogger(console)
/**
* Lambda handler
*/
exports.handler = async (event) => {
console.log(JSON.stringify(event))
@daaru00
daaru00 / template.yaml
Last active October 3, 2022 19:24
Use EventBridge events to execute code when the CloudFormation stack itself is created
AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"
Resources:
LogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub /aws/lambda/${StackCreatedFunction}
RetentionInDays: 7
@daaru00
daaru00 / template.yml
Created June 15, 2021 08:47
A SAM template that describe an Amazon CloudFront distribution that redirect all request to a specific URL using a CloudFront Function
AWSTemplateFormatVersion: 2010-09-09
Transform:
- AWS::Serverless-2016-10-31
# Template Information
Description: "Website redirect"
# Template Parameters
@daaru00
daaru00 / authorizer.js
Last active July 12, 2023 12:45
Lambda authorizer to check OAuth2 authorization token
const https = require('https');
const jose = require('node-jose');
const region = process.env.COGNITO_REGION;
const userpool_id = process.env.COGNITO_USER_POOL_ID;
const app_client_id = process.env.COGNITO_CLIENT_ID;
const keys_url = 'https://cognito-idp.' + region + '.amazonaws.com/' + userpool_id + '/.well-known/jwks.json';
/**
* Lambda handler
@daaru00
daaru00 / opcache-clean.sh
Last active December 15, 2023 04:10
Reset PHP OPcache cache from command line
#!/bin/bash
WEBDIR=/var/www/html/
RANDOM_NAME=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13)
echo "<?php opcache_reset(); ?>" > ${WEBDIR}${RANDOM_NAME}.php
curl http://localhost/${RANDOM_NAME}.php
rm ${WEBDIR}${RANDOM_NAME}.php
echo "cache reset"