Skip to content

Instantly share code, notes, and snippets.

View Mth0158's full-sized avatar
🏔️
Focusing

Mathieu EUSTACHY Mth0158

🏔️
Focusing
View GitHub Profile

Ruby: The future of frozen string literals

What is a literal?

In programming languages, literals are textual representations of values in the source code. This is a syntactical concept.

Some examples:

7 # integer literal
@nhattan
nhattan / .gitlab-ci.yaml
Created March 19, 2020 08:15
Gitlab CI/CD for Rails, Postgres, Rspec, Brakeman
stages:
- build
- test
- deploy
.base:
image: ruby:2.7.0
cache:
key: gems_and_packages
paths:
@pietromoro
pietromoro / before_render.rb
Last active September 9, 2024 13:28
BeforeRender Callback as concern for rails controller(s). Use it with the same syntax used for other callbacks, just include in the controller. Fires after action but before rendering happens.
module BeforeRender
extend ActiveSupport::Concern
included do
alias_method :render_without_before_render_action, :render
alias_method :render, :render_with_before_render_action
define_callbacks :render
end
def render_with_before_render_action(*options, &block)
@joshbuchea
joshbuchea / semantic-commit-messages.md
Last active November 15, 2024 16:02
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@loziju
loziju / macosx-configure-postfix-as-relay.md
Last active August 29, 2024 03:01
Configure postfix as relay for OS X
@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

@mattetti
mattetti / gist:1015948
Created June 9, 2011 02:44
some excel formulas in Ruby
module Excel
module Formulas
def pmt(rate, nper, pv, fv=0, type=0)
((-pv * pvif(rate, nper) - fv ) / ((1.0 + rate * type) * fvifa(rate, nper)))
end
def ipmt(rate, per, nper, pv, fv=0, type=0)
p = pmt(rate, nper, pv, fv, 0);
ip = -(pv * pow1p(rate, per - 1) * rate + p * pow1pm1(rate, per - 1))
(type == 0) ? ip : ip / (1 + rate)