Skip to content

Instantly share code, notes, and snippets.

View meleu's full-sized avatar
👨‍💻
Coding...

meleu meleu

👨‍💻
Coding...
View GitHub Profile
@meleu
meleu / sync.sh
Created September 3, 2021 23:46
script criado para sincronizar com o repositório remoto
#!/usr/bin/env bash
# BUG: se por um acaso o script não concluir o push com sucesso, a próxima
# execução não fará o push (git status não vai pegar mudança alguma).
main() {
gitStatus="$(git status --porcelain)"
[[ -z "${gitStatus}" ]] && return 0
git add --all \
@meleu
meleu / banner.sh
Created July 23, 2021 18:32
shell script "banner"
#!/usr/bin/env bash
# banner():
# Imprime uma mensagem no seguinte formato:
# ============
# olá mundo!
# ============
banner() {
local string="$@"
local length="${#string}"
@meleu
meleu / jsonFiles.js
Last active October 9, 2020 16:12
write and parse json files
function writeJsonFile(path, obj) {
if (!(typeof obj === 'object' && obj !== null)) {
return false;
}
try {
fs.writeFileSync(path, JSON.stringify(obj, null, 2));
} catch (err) {
console.error(`---[ERRO - ${new Date()}]\n${err}`);
return false;
@meleu
meleu / urldecodefile.sh
Last active April 5, 2020 14:28
urldecode the contents of a file and print it in standard output.
#!/usr/bin/env bash
urldecode() {
local encoded="${*//+/ }"
printf '%b\n' "${encoded//%/\\x}"
}
main() {
local file="$1"
local line
@meleu
meleu / covid-ranking.sh
Created March 27, 2020 17:18
Show a bargraph with a ranking of countries with the highest number of deaths caused by COVID-19
#!/usr/bin/env bash
# covid-ranking.sh
##################
#
# Show a bargraph with a ranking of countries with
# the highest number of deaths caused by COVID-19.
#
# Dependencies: curl, jq, termgraph
#
# (install termgraph via `pip3 install termgraph`)
@meleu
meleu / urlshort.sh
Last active March 19, 2020 00:04
An URL shortener using a free bit.ly account.
#!/usr/bin/env bash
# urlshort.sh
#############
#
# An URL shortener using a free bit.ly account.
#
# Before running this script, you're gonna need a bitly access token.
#
# INSTRUCTIONS:
# 1. Create an account at https://bitly.com
@meleu
meleu / covid.sh
Last active March 18, 2020 23:42
Check the numbers of COVID-19 (caused by Coronavirus) cases/deaths/recovered directly at your terminal.
#!/usr/bin/env bash
# covid.sh
##########
readonly API_URL='https://coronavirus-19-api.herokuapp.com'
readonly USAGE="Usage: $0 [country1 [country2] [countryN]] "
declare -A data
json2array() {
#!/usr/bin/env bash
# pacotesAusentes.sh
# https://meleu.sh/
file='file.txt'
notFoundArray=()
for pkg in "${pkg_install[@]}"; do
# -q: modo quieto; -m1: encerra na primeira ocorrência
grep -q -m1 "$pkg" "$file" || notFoundArray+=("$pkg")
@meleu
meleu / rsync.md
Last active May 18, 2022 17:16
Clonando com rsync

Clonando um sistema com rsync

Tava precisando migrar um sistema da Amazon para a Digital Ocean, e para clonar o sistema todo, usei rsync.

Conectei na máquina a ser migrada/clonada e mandei o seguinte comando:

sudo rsync --numeric-ids -aHAXSve ssh \
    --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} \
    / root@NewServer:/destination/directory
@meleu
meleu / myFirstTelegramBot.js
Created April 25, 2019 16:06
learning telegram bot
const TelegramBot = require('node-telegram-bot-api');
const TOKEN = 'BLABLEBLIBLOBLU';
const bot = new TelegramBot(TOKEN, {polling: true});
const botoesSimNao = {
inline_keyboard: [
[
{text: 'Sim', callback_data: 'sim'},
{text: 'Não', callback_data: 'nao'},