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 / serverless.yml
Created September 18, 2021 02:34
Trigger lambda function using AWS Elastic load balance
service: sample-lambda-alb
provider:
name: aws
runtime: nodejs14.x
stage: ${opt:stage, 'dev'}
region: ${opt:region, 'us-west-2'}
profile: crazy
alb:
targetGroupPrefix: tg-${opt:stage, 'dev'}- # this is the name for the target group
@yeisoncruz16
yeisoncruz16 / how-to-run.js
Last active August 19, 2021 23:45
How to update html field value when the page is using React
sendKeys(document.getElementById("SELECTOR_GO_HERE"), "My cool message to type", 'input');
var email = "YOU_EMAIL_WITHOUT_GMAIL_GOES_HERE";
var emailList = [];
for(let i = 1; i < email.length - 1; i++){
for(let x = 1; x <= email.length; x++){
if(i+1 !== x && i != x) {
let splitEmail = email.split("");
splitEmail.splice(i, 0, '.');
splitEmail.splice(x, 0, '.');
@yeisoncruz16
yeisoncruz16 / Button.js
Created May 15, 2021 15:03
ReactJS onClick acts as event but only if they’re used on HTML-like elements.
import React from 'react';
export class Button extends React.Component {
render() {
return (
<button onClick={this.props.onClick}>
Click me!
</button>
);
}
@yeisoncruz16
yeisoncruz16 / truncate-large-tables.sql
Created March 11, 2021 17:06
How to truncate Large Mysql Tables
CREATE TABLE new_foo LIKE foo;
RENAME TABLE foo TO old_foo, new_foo TO foo;
DROP TABLE old_foo;
@yeisoncruz16
yeisoncruz16 / lambda-get-ip.js
Created March 3, 2021 17:25
Simple lambda function to get Current IP
let response;
exports.lambdaHandler = async (event, context) => {
try {
const ret = await axios(url);
response = {
'statusCode': 200,
'body': JSON.stringify({
location: ret.data.trim()
})
@yeisoncruz16
yeisoncruz16 / increase-ec2.md
Last active March 3, 2021 14:12
Increase EC2 Volume Size
  • Log into your AWS account and navigate to EC2
  • View Instance Details looking for the Root Device and Block Devices to identify the volume you want to resize
  • Click the storage Device and select the EBS ID
  • While in the Volumes panel click Actions at the top of the page
  • Select Modify Volume to modify that particular volume
  • Enter the desired volume size in GBs and click modify, yes to confirm
  • SSH into your Instance
  • Run lsblk to list available blocks (volumes) and note the volume size / names
  • Run sudo growpart /dev/volumename 1 on the volume you want to resize, in our case it was sudo growpart /dev/xvda 1
@yeisoncruz16
yeisoncruz16 / perform-folder-actions.sh
Created February 26, 2021 15:24
Perform action inside multiple folders
for D in *; do
if [ -d "${D}" ]; then
echo "Processing -> ${D}"
cd "${D}" && YOU_SPECIAL_COMMAND_GO_HERE && cd -
echo "----------------------------";
fi
done
@yeisoncruz16
yeisoncruz16 / secrets.js
Created November 18, 2020 21:19
NodeJs script to get Secrets from secrets manager
class Secrets {
constructor(awsClient) {
this.client = awsClient;
}
async getSecret(SecretId){
return new Promise((resolve) => {
this.client.getSecretValue({ SecretId }, (secretManagerError, data) => {
if (secretManagerError) {
if (secretManagerError.code === "DecryptionFailureException")
@yeisoncruz16
yeisoncruz16 / Makefile
Last active November 18, 2020 21:16
Simple NodeJs lambda function to get SQS counts using CDK
deploy:
@cdk deploy --require-approval never
install:
@npm install
install_production:
@npm install --only=prod
watch: