Skip to content

Instantly share code, notes, and snippets.

@lorenadl
lorenadl / mysql_restore_db_command_line.md
Created August 7, 2018 16:04
MYSQL restore db command line

MYSQL restore db command line

$ mysql -u username -p dbname < backup_file.sql

@lorenadl
lorenadl / rails_server_errors.md
Last active July 13, 2018 15:54
Rails server errors

puma error "...in `initialize': Address already in use - bind(2) for "0.0.0.0" port 3100 (Errno::EADDRINUSE)..."

You must terminate the process that's using the port.

Find PID:

$ lsof -wni tcp:3100

Kill the process:

@lorenadl
lorenadl / mysql_create_user_with_password_and_grant_privileges.md
Created July 10, 2018 13:55
MySQL create user with password and grant privileges

MySQL create user with password and grant privileges

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';

GRANT ALL PRIVILEGES ON database_name.* TO username@localhost;

@lorenadl
lorenadl / mysql_set_root_user_password.md
Created July 10, 2018 13:48
MySQL set root user password

MySQL set or change root user password

mysqladmin -u root password NEWPASSWORD

To change password:

mysqladmin -u root password NEWPASSWORD

@lorenadl
lorenadl / notes.md
Last active June 29, 2018 14:20
Notes
@lorenadl
lorenadl / rails_index_vs_foreign_key.md
Last active April 12, 2022 11:33
[Rails] index: true vs foreign_key: true

index: true vs foreign_key:true in migration

In migration:

create_table :educations do |t| 
  t.belongs_to :profile, index: true, foreign_key: true
end

Index improve speed of data retrieval operations on database tables. When we write index: true to any column, it adds a database index to this column.

@lorenadl
lorenadl / rails_active_storage_how_to_validate_file_type.md
Last active January 25, 2024 00:11
[Rails] Active Storage how to validate file type

Rails Active Storage how to restrict uploadable file types

Active Storage doesn't have validations yet.

We can restrict the accepted file types in the form:

<div class="field">
  <%= f.label :deliverable %>
 &lt;%= f.file_field :deliverable, direct_upload: true, 
@lorenadl
lorenadl / rails_download_active_storage_attachment.md
Last active January 10, 2023 01:04
[Rails] Download an Active Storage attachment
@lorenadl
lorenadl / docker_commands.md
Last active June 13, 2018 07:36
Docker commands
@lorenadl
lorenadl / rails_autocomplete.md
Last active March 21, 2022 12:25
[Rails] Autocomplete