Skip to content

Instantly share code, notes, and snippets.

View shilovk's full-sized avatar

Kᴏɴsᴛᴀɴᴛɪɴ Sʜɪʟᴏᴠ shilovk

View GitHub Profile
def time_valid?(time = Time.current)
return true unless self.notify_on_time
Time.current >= 8 && Time.current <= 18
end
@shilovk
shilovk / rspec_model_testing_template.rb
Created August 31, 2020 11:38 — forked from SabretWoW/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@shilovk
shilovk / rails_generator_cheat_sheet.md
Created August 15, 2020 16:45 — forked from cdesch/rails_generator_cheat_sheet.md
Rails Generator CheatSheet

Cheat Sheets are greate but they are not a substitute for learning the framework and reading the documentation as we most certainly have not covered every potential example here. Please refer to the Rails Command Line Docs for more information.

Command Line Generator Info

Reference

You can get all of this information on the command line.

rails generate with no generator name will output a list of all available generators and some information about global options. rails generate GENERATOR --help will list the options that can be passed to the specified generator.

#!/usr/bin/env bash
# run this script from your home folder
# sudo bash
curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.12.tgz
tar -zxvf mongodb-linux-x86_64-2.6.12.tgz
cp mongodb-linux-x86_64-2.6.12/bin/* /usr/local/bin
groupadd mongodb
useradd --system --no-create-home -g mongodb mongodb
# frozen_string_literal: true
require 'rails_helper'
RSpec.configure do |config|
config.use_transactional_fixtures = false
# DatabaseCleaner settings
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
# sudo vi /etc/nginx/sites-enabled/passenger.qna.conf
server {
listen 80;
listen [::]:80;
server_name qna.shilovk.ru;
rails_env production;
root /home/deployer/qna/current/public;
client_max_body_size 20M; # для загрузки макисмального размера файла если файлы хранятся локально, а не в облаке
# sudo vi /etc/nginx/sites-enabled/unicorn.qna.conf
# это директива nginx которая указывает список бэкенд серверов которые физически будут обрабатывать запрос и таким образом nginx будет проксировать запросы к указанным серверам и даже как loadbalancer
upstream unicorn {
server unix:/home/deployer/qna/shared/tmp/sockets/unicorn.qna.sock fail_timeout=0; # описали сервер ссылающийся на сокет а можно было на ip и таких серверов может быть несколько, fail_timeout - означает что nginx не будет посылать запросы если наш сервер не отвечает
}
# к этому никакого отношения upstream не имеет
server {
listen 80;
@shilovk
shilovk / qna_backup.rb
Last active August 19, 2020 15:27
backup to Yandex Object Storage
# ...
store_with S3 do |s3|
s3.access_key_id = "your_key"
s3.secret_access_key = "your_pass"
s3.bucket = "your_bucket_name"
s3.path = "your_path_to_backup"
s3.region = "ru-central1"
s3.fog_options = { endpoint: "https://storage.yandexcloud.net" }
end
@shilovk
shilovk / qna.monit.rc
Last active May 6, 2020 14:51
/etc/monit/conf-enabled/qna.monit.rc
### Nginx ###
check process nginx
with pidfile "/run/nginx.pid"
start program = "/usr/sbin/service nginx start"
stop program = "/usr/sbin/service nginx stop"
if cpu usage > 60% for 2 cycles then alert
if cpu usage > 80% for 5 cycles then restart
if memory usage > 80% for 5 cycles then restart
if failed host qna.shilov.ru port 80 protocol http then restart
if 3 restarts within 5 cycles then timeout
@shilovk
shilovk / add_lvhme.sh
Created April 23, 2020 12:53 — forked from mdespuits/add_lvhme.sh
Add lvh.me to Mac OS X hosts file
#!/bin/bash
main() {
if [[ $(has_lvh_me) == 1 ]]; then
echo 'lvh.me is already specified in your hosts file'
else
add_lvh_me
echo 'lvh.me was added to your hosts file!'
fi
flush_dns_cache