Skip to content

Instantly share code, notes, and snippets.

@kieetnvt
kieetnvt / Crying with Rails Associations.md
Last active April 19, 2019 04:37
Crying with Rails Associations

Crying with Rails Associations

Belongs To:

class Post < ApplicationRecord
  belongs_to :user
end

create_table :photos do |t|
@kieetnvt
kieetnvt / ruby_magic_comment.md
Last active April 10, 2019 07:40
Ruby optimization with Magic Comment

Trong việc phát triển phần mềm, muốn optimization đơn giản là làm được việc này: Find the way to do less!

Ruby thì chậm có tiếng rồi, thủ phạm chính đó là garbage collector của ruby.

Chúng ta có thể optimization ruby bằng cách tạo ít rác rưởi khi chúng ta code ruby.

String trong ruby thì mutable (thay đổi), sinh ra nhiều object rác.

Ví dụ: string = ""; string << "test" nó đã tạo 2 object string là "", và "test". (rác)

@AtulKsol
AtulKsol / psql-error-fix.md
Last active November 13, 2024 12:43
Solution of psql: FATAL: Peer authentication failed for user “postgres” (or any user)

psql: FATAL: Peer authentication failed for user “postgres” (or any user)

The connection failed because by default psql connects over UNIX sockets using peer authentication, that requires the current UNIX user to have the same user name as psql. So you will have to create the UNIX user postgres and then login as postgres or use sudo -u postgres psql database-name for accessing the database (and psql should not ask for a password).

If you cannot or do not want to create the UNIX user, like if you just want to connect to your database for ad hoc queries, forcing a socket connection using psql --host=localhost --dbname=database-name --username=postgres (as pointed out by @meyerson answer) will solve your immediate problem.

But if you intend to force password authentication over Unix sockets instead of the peer method, try changing the following pg_hba.conf* line:

from