Skip to content

Instantly share code, notes, and snippets.

View dcortesnet's full-sized avatar
🏀
quick to answer

Diego Esteban dcortesnet

🏀
quick to answer
View GitHub Profile
@dcortesnet
dcortesnet / react_send_file_form_data.jsx
Created March 22, 2024 20:48
Reactjs send file to form data
import React, { useState } from 'react';
export function App() {
const [file, setFile] = useState(null);
const handleFileChange = (event) => {
setFile(event.target.files[0]);
};
const handleSubmit = (event) => {
@dcortesnet
dcortesnet / pg_database_authors_books.sql
Last active February 18, 2024 17:04
PostgreSQL authors - books relation
/* PostgreSQL */
CREATE DATABASE book_store;
CREATE TABLE authors (
author_id SERIAL PRIMARY KEY,
name VARCHAR(255) NOT NULL,
age SMALLINT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
@dcortesnet
dcortesnet / print_formatted_number.py
Created February 12, 2024 00:31
Python convertir un número en los diferentes sistemas númericos
# Contrains 1 <= n <= 99
def print_formatted(number: int):
width = len(bin(number)[2:])
for n in range(1, number +1):
decimal = n
octal = oct(n)[2:]
hexadecimal = hex(n)[2:].upper()
binary = bin(n)[2:]
print("{0:>{width}} {1:>{width}} {2:>{width}} {3:>{width}}".format(decimal, octal, hexadecimal, binary, width=width))
@dcortesnet
dcortesnet / mutate_string_with_position_and_character.py
Created February 11, 2024 03:25
Python mutar un string por una posición y un carácter
def mutate_string(string, position, character):
string_list = list(string)
string_list[position] = character
string = "".join(string_list)
return string
mutate_string("hola", 0, "H")
@dcortesnet
dcortesnet / swap_case_upper_lower.py
Created February 11, 2024 03:14
Python revertir casos de mayúsculas y minúsculas
def swap_case(text: str):
swap = ""
for word in text:
if word.isupper():
swap += word.lower()
continue
if word.islower():
swap += word.upper()
continue
@dcortesnet
dcortesnet / python_order_2d_array_by_field.py
Last active February 11, 2024 02:57
Python ordenar un array 2d por un dato
students = [['Harry', 37.21], ['Berry', 37.21], ['Tina', 37.2], ['Akriti', 41], ['Harsh', 39]]
data_sorted = sorted(students, key=lambda x: x[1])
print(data_sorted)
@dcortesnet
dcortesnet / nodejs_aws_sqs_client_producer_consumer.js
Last active April 3, 2023 23:25
Nodejs aws SQS server producer and consumer
const express = require('express');
const fs = require('fs');
const app = express();
const port = 3000;
const dotenv = require('dotenv');
const { SQS, SendMessageCommand } = require('@aws-sdk/client-sqs');
const { Consumer } = require('sqs-consumer');
dotenv.config();
@dcortesnet
dcortesnet / template.yml
Created March 29, 2023 15:50
AWS SAM template - lambda S3 yml
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:
MyFunction:
Type: 'AWS::Serverless::Function'
Properties:
Handler: index.handler
Runtime: nodejs8.10
CodeUri: 's3://my-bucket/function.zip'
Policies:
@dcortesnet
dcortesnet / policy.json
Last active March 29, 2023 15:16
AWS policies - create logs stream in cloud watch
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Effect": "Allow",
@dcortesnet
dcortesnet / aws_cli_sqs.md
Last active February 11, 2024 02:52 — forked from janjaali/aws-cli-sqs.md
Little cheatsheet for AWS CLI SQS commands

Create a FIFO queue

aws --endpoint http://localhost:9324 sqs create-queue --queue-name queue-name.fifo --attributes FifoQueue=true,MessageRetentionPeriod=1209600,ContentBasedDeduplication=false
  • MessageRetentionPeriod is set to 1209600 seconds which equals to 14 days

Send a message (file) to queue