Skip to content

Instantly share code, notes, and snippets.

View diegofcornejo's full-sized avatar
🪄
randomtechguy

Diego Cornejo diegofcornejo

🪄
randomtechguy
View GitHub Profile
@diegofcornejo
diegofcornejo / Dockerfile
Last active October 22, 2023 19:44
Dockerize: Build (Vite) React App inside Turborepo and serve on nginx
# Build stage
from node:18-alpine3.17 as build
WORKDIR /app
# Copy whole project
COPY ../../ .
# Install dependencies
RUN yarn install
@diegofcornejo
diegofcornejo / get-ssm-parameters.sh
Last active April 23, 2023 05:40
Export SSM Parameters to Environment Variables and Append to .bashrc
#======================#
# Without dependencies #
#======================#
#!/bin/bash
# This script will export all SSM parameters under a given path as environment variables
# It will also append the export statements to the ~/.bashrc file so that they are available on future logins
# Set some parameters
@diegofcornejo
diegofcornejo / README.md
Last active March 26, 2023 17:26
Deploy Express API - Kubernetes (EKS) with HTTPS endpoint

Important: This tutorial assume you already has installed and know how to use, aws cli, kubectl and eksctl

Create and Setup Cluster and required policies

1. Create Fargate Cluster

eksctl create cluster --region us-west-1 --name express-api --version 1.25 --fargate

Note: This command create a stack in cloudformation

@diegofcornejo
diegofcornejo / index.js
Created October 15, 2022 03:11
AWS Lambda - Validate if domain point to specific IP's
const dns = require('dns');
const ips = ["XX.XX.XX.XX", "XX.XX.XX.XX"];
exports.handler = (event, context, callback) => {
// context.callbackWaitsForEmptyEventLoop = false;
let body = JSON.parse(event.body);
var done = function(code, message) {
let response = {
"statusCode": code,
"body": JSON.stringify(message)
};
@diegofcornejo
diegofcornejo / index.js
Created October 15, 2022 03:07
AWS Lambda - APIGateway create API Key and Usage plan key
'use strict';
var AWS = require('aws-sdk');
var apigateway = new AWS.APIGateway();
var docClient = new AWS.DynamoDB.DocumentClient();
function generateApiKey() {
return 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'.replace(/[x]/g, function(c) {
var r = Math.random() * 36 | 0,
v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(36);
@diegofcornejo
diegofcornejo / index.js
Created October 15, 2022 03:01
AWS Lambda - Automate Elastic IP assignation to new created EC2 instance
const AWS = require('aws-sdk');
const EC2 = new AWS.EC2();
exports.handler = (event, context, callback) => {
const done = function(response) {
callback(null, response);
};
const message = JSON.parse(event.Records[0].Sns.Message);
console.log(message);
const describeAddressesParams = {
@diegofcornejo
diegofcornejo / README.md
Last active November 13, 2022 06:40
Rust vs JavaScript - Sort array number

Rust vs JavaScript - Sort array number

Rust

This is a cargo project, you need to compile before use

cargo build --release

Or just use

cargo run --release -- 1000000

JavaScript

This project use Node 16 or later

@diegofcornejo
diegofcornejo / application.properties
Last active August 7, 2022 01:10
PKG ExpressJS example
PORT=4000
API_PROTOCOL=https
API_HOST=localhost
API_PORT=4001
API_VERSION=v1
@diegofcornejo
diegofcornejo / 1_WriteInTheBlockchain.sol
Last active February 6, 2022 05:36
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
contract RandomTestContract{
string text;
function write(string calldata _text) public{
text = _text;
}
@diegofcornejo
diegofcornejo / metamask_verifier.js
Created February 4, 2022 05:15
Metamask ETH - NodeJS Signature verifier
const ethSigUtil = require("@metamask/eth-sig-util");
const address = '0x0';
const message = 'Hi I am 0x0';
const signature = '0x0';
let checkSignature = (data, signature) => {
const params = {
data,
signature