Skip to content

Instantly share code, notes, and snippets.

View yeisoncruz16's full-sized avatar
😄
Work harder than you did yesterday

Yeison Cruz yeisoncruz16

😄
Work harder than you did yesterday
View GitHub Profile
@yeisoncruz16
yeisoncruz16 / template.yaml
Created August 20, 2020 14:13
Cloudformation template to create Lambda, SQS, role, Policy, Api
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: >
Lambda, SQS, role, Policy, Api
Globals:
Function:
Timeout: 5
Runtime: python3.6
Handler: app.lambda_handler
@yeisoncruz16
yeisoncruz16 / Chain-of-Responsibility-Pattern.js
Last active August 20, 2020 14:14
Simple chain of responsibility pattern implemented using Javascript ES6
class BaseDesign {
setNext(next){
this._next = next;
}
next(role){
if(this._next){
return this._next.run(role);
}
@yeisoncruz16
yeisoncruz16 / commit-msg.sh
Created September 22, 2020 15:43
simple commit message hook to validate message contain :
#!/bin/bash
MSG="$1"
message="Hey! looks like your commit message is not following correct format"
if ! grep -qE ":" "$MSG";
then
printf "\n";
echo -e "\e[91m${message}\e[0m";
echo "Your commit message: " && cat "${MSG}";
@yeisoncruz16
yeisoncruz16 / Dockerfile
Last active October 8, 2020 17:14
Dockerfile to run PHP & NodeJs with serverless installed (useful for CI/CD)
FROM thecodingmachine/php:7.4-v3-cli-node10
LABEL authors="Julien Neuhart <j.neuhart@thecodingmachine.com>, David Négrier <d.negrier@thecodingmachine.com>"
USER root
RUN apt-get update && \
apt-get install -y --no-install-recommends gnupg && \
curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
apt-get update && \
@yeisoncruz16
yeisoncruz16 / .gitlab-ci.yml
Last active October 9, 2020 16:11
Simple Gitlab CI, deploy AWS Lambda using Serverless framework
image: node:latest
stages:
- deploy
Production:
stage: deploy
only:
refs:
- master
before_script:
@yeisoncruz16
yeisoncruz16 / DRY.js
Created October 10, 2020 02:08
Ejemplo de DRY usando Javascript
// ----> Design Principles
// DRY
// 0
console.log("Don’t Repeat Yourself");
// 1
console.log("Encapsulate What Varies");
@yeisoncruz16
yeisoncruz16 / save-dynamo.py
Created October 15, 2020 02:06
Simple Python lambda function to store & list information from DynamoDB
import json
import boto3
from datetime import datetime
def lambda_handler(event, context):
dynamodb = boto3.resource('dynamodb')
client = boto3.client('dynamodb')
queryStringParameters = event.get("queryStringParameters", {})
list_items = queryStringParameters.get("list_items", "false")
@yeisoncruz16
yeisoncruz16 / install-telegraf.sh
Created October 15, 2020 15:59
Set up Telegraf on Ubuntu server
sudo apt update
wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -
echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list
sudo apt update
sudo apt -y install telegraf
@yeisoncruz16
yeisoncruz16 / apis.txt
Last active October 17, 2020 02:24
Free APIS to try new projects
https://futuramaapi.herokuapp.com/
https://thesimpsonsquoteapi.glitch.me/
https://api.chucknorris.io/
https://rickandmortyapi.com/
https://catfact.ninja/
@yeisoncruz16
yeisoncruz16 / remove-UNTAGGED-ecr.sh
Created October 22, 2020 00:45
Simple bash script
#!/bin/bash
ECR_REGION='us-east-1'
ECR_REPO='YOUR_REPO_GO_HERE'
IMAGES_TO_DELETE=$( aws ecr list-images --region $ECR_REGION --repository-name $ECR_REPO --filter "tagStatus=UNTAGGED" --query 'imageIds[*]' --output json )
if [ "$IMAGES_TO_DELETE" == [] ]
then