Skip to content

Instantly share code, notes, and snippets.

View sergii's full-sized avatar

Serhii Ponomarov sergii

View GitHub Profile
require "rails_helper"
feature "User signs up" do
scenario "and is added to the roster" do
visit root_path
fill_in "Name", with: "Mickey Mouse"
fill_in "Experience", with: "Junior"
click_button "Sign Me Up!"
expect(page).to have_text("Mickey Mouse")
@sergii
sergii / pg_dump_pg_restore.sh
Created July 27, 2021 16:19 — forked from orendon/pg_dump_pg_restore.sh
pg_dump pg_restore postgresql backup postgres
# Create and restore backups on PostgreSQL (tested on 9.2 and 9.3)
# create database backup
PGPASSWORD="XXX" pg_dump --no-owner --no-acl -U USER DATABASE -h HOST -F t > output_file.tar
# create database backup (heroku)
heroku pgbackups:capture
heroku pgbackups # show stored backups (assuming a117 is the desired one)
heroku pgbackups:url a117 # => it retrieves dump url on AWS S3
@sergii
sergii / sort_by.md
Created July 15, 2021 05:57 — forked from Kotauror/sort_by.md
Sort_by ruby method - sorting using multiple attributes.

Sort_by ruby method - sorting using multiple attributes.

I guess everyone knows that feeling when you struggle with a codewars kata, create (or even not!) a looong solution, then you check the solutions of of others and go whaaaaaaaat -- they did it in one line?

This is how I felt today and this is how I refreshed my memory of Ruby's sort_by method.

Task:

@sergii
sergii / heroku_pg_db_reset.md
Created July 7, 2021 08:46 — forked from zulhfreelancer/heroku_pg_db_reset.md
How to reset PG Database on Heroku?

How to reset PG Database on Heroku?

  • Step 1: heroku restart
  • Step 2: heroku pg:reset DATABASE (no need to change the DATABASE)
  • Step 3: heroku run rake db:migrate
  • Step 4: heroku run rake db:seed (if you have seed)

One liner

heroku restart; heroku pg:reset DATABASE --confirm APP-NAME; heroku run rake db:migrate

@sergii
sergii / devise_invitable.ru.yml
Created June 19, 2021 17:40 — forked from volonterx/devise_invitable.ru.yml
Russian translations for devise_invitable. Completely adheres to the format of the generated devise_invitable.en.yml as of 1.4.0.
# Additional translations at https://github.com/scambra/devise_invitable/wiki/I18n
ru:
devise:
failure:
invited: 'У вас есть непринятое приглашение, подтвердите его чтобы продолжить создание аккаунта.'
invitations:
send_instructions: 'Письмо с приглашением было отправлено на %{email}.'
invitation_token_invalid: 'Неверный токен приглашения.'
updated: 'Ваш пароль успешно сохранен. Вы вошли в систему.'
@sergii
sergii / gist:78cfd5a5aed7faa91bf610a821b05d3c
Created June 13, 2021 07:35 — forked from mozamimy/gist:52c0004c8370f78df2c2
Validations for IP address and MAC address on Ruby on Rails
require "resolv"
class Model < ActiveRecord::Base
validates :ip_address, format: { with: Resolv::IPv4::Regex }
validates :mac_address, format: { with: /\A([0-9A-F]{2}[-:]){5}([0-9A-F]{2})\z/ }
end
@sergii
sergii / make_acronym.rb
Created June 12, 2021 12:47 — forked from lrechert/make_acronym.rb
Ruby Weekly Challenge - Make Acronym
# Implement a function called make_acronym that returns the first letters
# of each word in a passed in string. Make sure the letters returned are
# uppercase.
# If the value passed in is not a string return 'Not a string'
# If the value passed in is a string which contains only characters
# other than spaces and alphabet letters, return 'Not letters'
def make_acronym(input_string)
return nil unless input_string
select
*
from
tables
join (
select table_id
from books
where rating = 1
) as t1 on t1.table_id = tables.table_id
join (
@sergii
sergii / intersection_authorize.rb
Created June 11, 2021 13:21 — forked from travisofthenorth/intersection_authorize.rb
Intersection use case - authorize a user who has an allowed role/ability
class PaymentsController < AuthenticatedController
before_action { authorize!(roles: [:superuser], abilities: [:charge_user, :manage_payments]) }
end
class AuthenticatedController < ApplicationController
def authorize!(roles: [], abilities: [])
# current
(roles & current_user.roles).any? || (abilities & current_user.abilities).any?
# desired