Skip to content

Instantly share code, notes, and snippets.

View ogabrielguerra's full-sized avatar
🏠
Working from home

Gabriel Guerra ogabrielguerra

🏠
Working from home
View GitHub Profile
// old
const handleSubmit = async (event) => {
event.preventDefault()
setIsLoading(true)
var userMessage:ChatMessageFormat = {
...message,
id: crypto.randomUUID()
}
var searchResult = await Promise.all([runSearches(message.content, selectedCollection)])
console.log("Search Result: ", searchResult)
@ogabrielguerra
ogabrielguerra / testString.js
Created February 17, 2024 20:37
Checks if a given string has the expected closing char.
const testString = (s)=>{
console.log('Evaluating string ', s)
let opening = ['(', '[', '{']
let closing = [')', ']', '}']
const findIndex = (list, char) =>{
for (let i in list)
@ogabrielguerra
ogabrielguerra / Login.jsx
Created February 13, 2024 23:51
Login Component Example
import { useNavigate } from "react-router";
import { fetchToken, setToken } from "./Auth";
import { validateForm } from "./FormValidation";
import { useState, useEffect } from "react";
import axios from "axios";
import Button from "react-bootstrap/Button";
import { Container, Row, Col } from "react-bootstrap";
import FormInput from "./components/FormInput";
export default function Login() {
@ogabrielguerra
ogabrielguerra / validateForm.js
Last active February 13, 2024 22:55
[ReactJS] Form validation function
const validateForm = (formFields, formState) => {
let errors = [];
let allowedToProceed = true;
//All required fields are empty
if (!formState) {
for (let field of formFields) {
errors.push(field);
}
setFormErrors(errors);
@ogabrielguerra
ogabrielguerra / core.py
Last active February 7, 2024 01:46
Abstracting ObjectId handling and CRUD operations (MongoDB).
import json
from bson.objectid import ObjectId
from pymongo.cursor import Cursor as pymongo_cursor
from pymongo.collection import Collection as pymongo_collection
from pydantic.main import ModelMetaclass
class JSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, ObjectId):
return str(o)
@ogabrielguerra
ogabrielguerra / UpscaleWorkaround.py
Created June 10, 2023 22:50
Workaround for Super Resolution Upscaling with any aspect ratio
import math
from PIL import Image, ImageChops
class AdjustImages:
@staticmethod
def get_next_height(height):
fullhd_height = 1080
if height % fullhd_height == 0:
@ogabrielguerra
ogabrielguerra / backup-projects.sh
Created February 28, 2022 21:24
Bash script for backing up web projects.
#!/bin/bash
printf "[BACKUP PROJECTS]\n\n"
temp_dir=$(mktemp -d)
package_name=backup_package
mkdir ~/$package_name
printf "COPYING TO TEMP DIR...\n\n"
@ogabrielguerra
ogabrielguerra / dump_object_or_table.lua
Created October 26, 2021 11:10
LUA - Dump a table or object
local inspect = require('inspect')
local table = { a='a', b='b', c='c'}
print(inspect(table))
find . -name "*.[extension]" | xargs wc -l | tail -1
const handleResumeForm = (inputTargetId)=>{
const RESUME_INPUT = document.getElementById(inputTargetId);
const RESUME_FILE_NAME = RESUME_INPUT.value;
const ALLOWED_EXTENSIONS = ['pdf','doc','docx'];
const ERROR_CLASS = 'form-error';
const inArray = (array, key)=>{
let result = false;
array.forEach((item)=>{ item === key ? result = true : '' })
return result;