Skip to content

Instantly share code, notes, and snippets.

View manninofrancesco's full-sized avatar
🌱
Simple always wins

Francesco Mannino manninofrancesco

🌱
Simple always wins
View GitHub Profile
@manninofrancesco
manninofrancesco / months_ita.rb
Created March 25, 2024 16:24
Translate months number in years and months in Italian language
def convert_months_to_years(months)
years = months / 12
remaining_months = months % 12
[years, remaining_months]
end
def get_friendly_years_and_month(months_count)
years, months = convert_months_to_years(months_count)
friendly_years = "#{years > 1 ? "#{years} anni" : '1 anno'} e #{months > 1 ? "#{months} mesi" : '1 mese'}"
@manninofrancesco
manninofrancesco / git_tips_tricks.sh
Last active May 25, 2024 13:32
Git tips & tricks
# Remove a file from repository (example .DS_Store)
# Remember to add **/filename.extension to your .gitignore!
find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
# merge a branch in your current one
git pull origin <remote_branch_name>
# get total lines of code of a repo
git ls-files | xargs -I {} find {} -type f | xargs wc -l | grep ' total'
def hash_with_levels(number_of_levels)
Hash.new { |i, parent|
i[parent] = number_of_levels == 1 ? {} : hash_with_levels(number_of_levels - 1)
}.compare_by_identity
end
@manninofrancesco
manninofrancesco / linux_commands.sh
Last active April 29, 2024 13:39
Linux commands
# Permission of file or folder
ls -l
#Example output: drwxr-xr-x 2 root root 4096 Jan 19 08:45 database_backups/
#1. Type: - for file and d for directories
#2. Permissions: rwxr is for root user | xr is for root group users | x is for others
#3. User Owner: root
#4. Group Owner: root
#Docs: https://www.redhat.com/sysadmin/linux-file-permissions-explained
# Find things
@manninofrancesco
manninofrancesco / script.sh
Last active March 19, 2024 07:26
SSH Authentication Keys
#Generate the private and the public keys
#Docs: https://www.ssh.com/academy/ssh/keygen#command-and-option-summary
ssh-keygen -t ed25519 -C "Comment"
#Now the private key must be used connecting to the server
ssh-i /path/of/private/key <user>@<hostip-host-url>
#You must copy the public key (.pub) in the server, specifically in .ssh/autorized_keys
#Or you can add your custom ssh key with: ssh-add github_ssh_key (private key)