Skip to content

Instantly share code, notes, and snippets.

View apavlyut's full-sized avatar

Alexander Pavlyut apavlyut

View GitHub Profile
@apavlyut
apavlyut / _post.html.slim
Created July 6, 2020 02:48
ActionText render for API
h3 = post.title
= raw post.content
@apavlyut
apavlyut / Gemfile
Created June 27, 2017 04:53
Gemfile example
source 'https://rubygems.org'
ruby '2.3.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.18'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Задача: Программа получает ссылку на страницу, выбирает оттуда все ссылки которые найдет и выводит их на экран.
# Ограничения: программа должна получать ссылку от меня в интерактивном режиме (используя метод gets)
# Программа:
class Proga # создание класса "Программа"
puts "Please, input a web-site" # запрос у пользователя ссылки на сайт
link = gets.chomp # создание переменной link, в которую будет складываться ответ пользователя
puts "You enter #{link}" # вывести на экран значение переменной link
PGPASSWORD=mypassword pg_dump -Fc --no-acl --no-owner -h localhost -U myuser mydb > mydb.dump
heroku pg:backups capture;
curl -o latest.dump `heroku pg:backups public-url`;
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U pguser -d blog_development latest.dump;
# connecting select2 to the appropriate hooks:
#
# hard case: best_in_place's select
$ ->
# first, find the mount point
$('body').on 'best_in_place:activate', '.best_in_place', ->
# second, attach empty update() to `this` to screen the downstream calls
# which otherwise will cause an error
module Accessible
extend ActiveSupport::Concern
included do
has_many :accessibilities, as: :accessible, dependent: :destroy
has_many :roles, -> { uniq }, through: :accessibilities
scope :visible_to, ->(role_names) {
role_names = [role_names] if [String, Symbol].include?(role_names.class)
if role_names.include?(Role::ROOT_ROLE)
all
require 'tire'
require 'nobrainer'
NoBrainer.connect 'rethinkdb://server/company'
class Employee
include NoBrainer::Document
field :name
field :title
@apavlyut
apavlyut / heroku_redirect.rb
Last active August 29, 2015 14:00
Ловим на входе в heroku наши домены поддомены и что надо делаем.
# lib/heroku_redirect.rb
class HerokuRedirect
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
unless request.host.starts_with?("www.") || request.host.starts_with?("start.") || request.host.starts_with?("crm.") || request.host.starts_with?("api.") || request.host.starts_with?("erp.") || request.host.include?("mydomain.com") || request.host.include?("staging.")
# puts 'redirecting to www'
@apavlyut
apavlyut / heroku_redirect.rb
Created April 23, 2014 09:29
Ловим на входе в heroku наши домены поддомены и что надо делаем.
# config/environments/production.rb
# ...
config.middleware.use HerokuRedirect