Skip to content

Instantly share code, notes, and snippets.

@oliveira-andre
Last active October 1, 2024 02:10
Show Gist options
  • Select an option

  • Save oliveira-andre/b28dd90d740ec9314a25993ea9c5d66a to your computer and use it in GitHub Desktop.

Select an option

Save oliveira-andre/b28dd90d740ec9314a25993ea9c5d66a to your computer and use it in GitHub Desktop.
commandcheat linux
#execute mariadb container
sudo docker exec -it mariadb mysql -u root -p
# importing data.sql to a database
sudo docker exec -i mariadb mysql -uroot -proot database < data.sql
# connect to postgres container
docker exec -it postgres psql
# setup postgres new user and db
CREATE USER devandre WITH PASSWORD 'your_new_password';
CREATE DATABASE dev_andre_development;
GRANT ALL PRIVILEGES ON DATABASE dev_andre_development to devandre;
ALTER DATABASE dev_andre_development OWNER TO devandre;
# start postgres on macos
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
# stop postgres on mac
pg_ctl -D /usr/local/var/postgres stop -s -m fast
# import data.sql to a database in postgres
psql -U password_manager -d password_manager_production < data.sql
# with docker
sudo docker exec -i container_name /bin/bash -c "PGPASSWORD=pg_pass psql --username pg_user database_name" < data.sql
# export data.sql from a database postgres container
sudo docker exec -it container_name pg_dump -U user db_name > data.sql
# export pg db
pg_dump db_name > data_dump
# execute mongodb container
sudo docker exec -it mongodb mongo
# create user on mongodb
db.createUser({ user: 'devandre', pwd: 'my_password_1234', roles: [{ role: 'readWrite', db: 'dev_andre_development' }] })
# kill any process on some port on linux
sudo kill $(sudo lsof -t -i:3000)
# change yout default terminal
sudo update-alternatives --config x-terminal-emulator
# copy to clipboard by terminal
pbcopy < ~/.ssh/id_rsa.pub
or
grep "<keyword>" | pbcopy
# pasting from clipboard by terminal
grep "<keyword>" | tee myfile.txt
# show terminal calendar
cal
# encrypting files on VIM
:X
# adding linux to platforms on gem lock
bundle lock --add-platform x86_64-linux-musl
# installing libpq on macos
brew install libpq
bundle config --local build.pg --with-opt-dir="/usr/local/opt/libpq"
bundle install
# counting lines
wc -l < /etc/passwd
# getting size of file/folder
du -sh Downloads
# split bigger files in minor files, in this case 25000 lines in each one
split -l 250000 safe_of_brafe.txt
# backuping big data to .tar file
pg_dump -U user -W -F t my_database_production > my_backup.tar
# restoring big data from .tar file
pg_restore -c -i -U user -d my_database_production -v "/tmp/client03.tar" -W
# show dns trace routing
dnstracer -s . -4 -o desconstruindoaweb.com.br
# show tls cert details
openssl s_client -connect desconstruindoaweb.com.br:443
# configure ruby build before install older version on macos/rbenv
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix [email protected])"
RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC arch -arm64 rbenv install 2.4.10
or
export optflags="-Wno-error=implicit-function-declaration"
RUBY_CFLAGS=-DUSE_FFI_CLOSURE_ALLOC rbenv install 2.4.2
# install old gem
LDFLAGS="-L/opt/homebrew/opt/libffi/lib" PKG_CONFIG_PATH="/opt/homebrew/opt/libffi/lib/pkgconfig" gem install ffi -v '1.9.18' -- --with-cflags="-Wno-error=implicit-function-declaration"
# Backup postgres docker
docker run --rm --volumes-from cyberchecker_api-database-1 -v $(pwd):/backup postgres:12.3 tar cvf /backup/backup.tar /var/lib/postgresql/data
# Restore backuped data postgres
docker run --rm --volumes-from cyberchecker_api-database-1 -v $(pwd):/backup postgres:12.3 bash -c "cd /var/lib/postgresql/data && tar xvf /backup/backup.tar --strip 1"
# run image id container on macos using platform linux
docker run --rm --platform linux/amd64 -it --pull=never db0abf5d0472 /bin/bash
@lucasdepvh
Copy link

#Exemplo

=> Booting Puma
=> Rails 5.2.1 application starting in development
=> Run rails server -h for more startup options
Puma starting in single mode...

  • Version 3.12.0 (ruby 2.5.1-p57), codename: Llamas in Pajamas
  • Min threads: 5, max threads: 5
  • Environment: development
  • Listening on tcp://0.0.0.0:3000
    Exiting
    Traceback (most recent call last):
    41: from bin/rails:3:in <main>' 40: from bin/rails:3:in load'
    39: from /home/lucas/projetos/desaparecidos/bin/spring:15:in <top (required)>' 38: from /usr/local/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:70:in require'
    37: from /usr/local/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:70:in require' 36: from /usr/local/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in <top (required)>'
    35: from /usr/local/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/binstub.rb:31:in load' 34: from /usr/local/lib/ruby/gems/2.5.0/gems/spring-2.0.2/bin/spring:49:in <top (required)>'
    33: from /usr/local/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client.rb:30:in run' 32: from /usr/local/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/command.rb:7:in call'
    31: from /usr/local/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in call' 30: from /usr/local/lib/ruby/gems/2.5.0/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in load'
    29: from /home/lucas/projetos/desaparecidos/bin/rails:9:in <top (required)>' 28: from /usr/local/lib/ruby/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in require'
    27: from /usr/local/lib/ruby/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:253:in load_dependency' 26: from /usr/local/lib/ruby/gems/2.5.0/gems/activesupport-5.2.1/lib/active_support/dependencies.rb:287:in block in require'
    25: from /usr/local/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in require' 24: from /usr/local/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in require_with_bootsnap_lfi'
    23: from /usr/local/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in register' 22: from /usr/local/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in block in require_with_bootsnap_lfi'
    21: from /usr/local/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in require' 20: from /usr/local/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/commands.rb:18:in '
    19: from /usr/local/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/command.rb:46:in invoke' 18: from /usr/local/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/command/base.rb:65:in perform'
    17: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor.rb:387:in dispatch' 16: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in invoke_command'
    15: from /usr/local/lib/ruby/gems/2.5.0/gems/thor-0.20.0/lib/thor/command.rb:27:in run' 14: from /usr/local/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/commands/server/server_command.rb:142:in perform'
    13: from /usr/local/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/commands/server/server_command.rb:142:in tap' 12: from /usr/local/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/commands/server/server_command.rb:147:in block in perform'
    11: from /usr/local/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/commands/server/server_command.rb:53:in start' 10: from /usr/local/lib/ruby/gems/2.5.0/gems/rack-2.0.5/lib/rack/server.rb:297:in start'
    9: from /usr/local/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/rack/handler/puma.rb:70:in run' 8: from /usr/local/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/launcher.rb:184:in run'
    7: from /usr/local/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/single.rb:96:in run' 6: from /usr/local/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/runner.rb:151:in load_and_bind'
    5: from /usr/local/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/binder.rb:88:in parse' 4: from /usr/local/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/binder.rb:88:in each'
    3: from /usr/local/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/binder.rb:105:in block in parse' 2: from /usr/local/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/binder.rb:272:in add_tcp_listener'
    1: from /usr/local/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/binder.rb:272:in new' /usr/local/lib/ruby/gems/2.5.0/gems/puma-3.12.0/lib/puma/binder.rb:272:in initialize': Address already in use - bind(2) for "0.0.0.0" port 3000 (Errno::EADDRINUSE)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment