Skip to content

Instantly share code, notes, and snippets.

View poacosta's full-sized avatar
👨‍💻
πολυμαθής

Pedro Orlando Acosta Pereira poacosta

👨‍💻
πολυμαθής
View GitHub Profile
@poacosta
poacosta / elastic-beanstalk-cheatsheet.sh
Last active December 6, 2023 06:47
Elastic Beanstalk CLI Cheatsheet
# This command will list all your environments which are setup in Elastic Beanstalk (EB)
$ eb list
EnvironmentName1 # Name of the first environment
EnvironmentName2 # Name of the second environment
EnvironmentName3 # Name of the third environment
# This command is used to display the status of the specified environment (EnvironmentName1)
$ eb status EnvironmentName1
# The following command will set an environment variable (ENV_VAR_NAME) to a specific value (value)
@poacosta
poacosta / create_admin_user.sql
Last active November 29, 2023 23:30
Create users and grant permissions in PostgreSQL
-- The below query is used to fetch all the role names from the 'pg_roles' system catalog table.
-- It will return a list of all user (role) names in the current PostgreSQL database.
SELECT rolname FROM pg_roles;
-- This command is used to create a new PostgreSQL user with the specified username and password.
-- In this case, the newly created username is 'username' and the password is 'P@55w0rd'.
CREATE USER username WITH PASSWORD 'P@55w0rd';
-- This command grants all privileges to the user 'username' on the database 'dbname'.
-- These privileges include SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, TRIGGER, CREATE, CONNECT, TEMPORARY, EXECUTE, and USAGE
@poacosta
poacosta / cometchat-script.py
Last active July 31, 2023 20:55
Delete Cometchat users and groups using Pyhon
# python -m pip install requests
import requests
url = "https://api-us.cometchat.io/v2"
headers = {
"accept": "application/json",
"Content-Type": "application/json",
"Accept": "application/json",
"appId": "---",
@poacosta
poacosta / mail_sent_from_ror_console.rb
Last active May 6, 2023 07:35
Send email from RoR console
# frozen_string_literal: true
mailer = ActionMailer::Base.new
mailer.delivery_method
mailer.smtp_settings
mailer.mail(from: 'sender@example.com', to: 'recipient@example.com', subject: 'Testing email', body: "Hello, you've got mail!").deliver!
@poacosta
poacosta / README.MD
Created March 14, 2023 18:00
Happy Pi Day! (Codewars Kumite)

Calculate Pi to a precision p.

Pi Day is an annual celebration of the mathematical constant π (pi). Pi Day is observed on March 14 (3/14 in the month/day format) since 3, 1, and 4 are the first three significant figures of π. It was founded in 1988 by Larry Shaw, an employee of the San Francisco, California science museum, the Exploratorium.

@poacosta
poacosta / huge_n-th_fibonacci.py
Last active February 19, 2023 15:33
n-th fibonacci with n up to 2_000_000
from numpy import matrix
def fib(n):
return (matrix(
'0 1; 1 1' if n >= 0 else '-1 1; 1 0', object
) ** abs(n))[0, 1]
@poacosta
poacosta / fibonacci.cs
Last active February 24, 2023 16:46
n-th fibonacci (3 ways)
namespace Fibonacci;
/// <summary>
/// The Fibonacci sequence is a sequence of numbers where a number is the sum of the two preceding numbers.
/// The first 10 numbers in the Fibonacci sequence are: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34.
/// </summary>
public static class Fibonacci
{
/// <summary>
/// Fibonacci in a recursive version
@poacosta
poacosta / create-files-by-extensions-given-a-path.py
Last active February 7, 2023 11:54
Create files by extensions given a path using Python
import os
EXTENSIONS = ['py', 'rb', 'cs', 'ex', 'js', 'go', 'rs', 'dart', 'php', 'sql']
def create_files_by_extension_given_a_filename(name, directory):
for extension in EXTENSIONS:
file = f"{name}.{extension}"
if os.path.exists(os.path.join(directory, file)):
print('{0}: already exists!'.format(file))
@poacosta
poacosta / create-dirs-by-filenames-given-a-path.py
Last active January 16, 2023 03:31
Create directories by file names given a path using Python
import os
def create_dirs_by_filenames(filenames, parent_dir):
mode = 0o777
for directory in filenames:
os.mkdir(os.path.join(parent_dir, directory), mode)
def get_filenames(path):