Instantly share code, notes, and snippets.

View production.rb
# paths
app_path = "/home/deployer/qna"
working_directory "#{app_path}/current"
pid "#{app_path}/current/tmp/pids/unicorn.pid"
# listen
listen "/tmp/unicorn.qna.sock", :backlog => 64
# logging
stderr_path "log/unicorn.stderr.log"
View monit.rc
### Nginx ###
check process nginx with pidfile /opt/nginx/logs/nginx.pid
start program = "/etc/init.d/nginx start"
stop program = "/etc/init.d/nginx stop"
if cpu > 60% for 2 cycles then alert
if cpu > 80% for 5 cycles then restart
if memory usage > 80% for 5 cycles then restart
if failed host 127.0.0.1 port 80 protocol http
then restart
if 3 restarts within 5 cycles then timeout
View monit
### Unicorn ###
check process unicorn
with pidfile "/home/deployer/qna/current/tmp/pids/unicorn.pid"
start program = "/bin/su - deployer -c 'cd /home/deployer/qna/current && /home/deployer/.rvm/bin/rvm default do bundle exec unicorn -c /home/deployer/qna/current/config/unicorn/production.rb -E deployment -D'"
stop program = "/bin/su - deployer -c 'cd /home/deployer/qna/current && /home/deployer/.rvm/bin/rvm default do bundle exeс kill -s USR2 `cat /home/deployer/qna/current/tmp/pids/unicorn.pid`'"
if memory usage > 90% for 3 cycles then restart
if cpu > 90% for 2 cycles then restart
if 5 restarts within 5 cycles then timeout
### Nginx ###
View ability.rb
class Ability
include CanCan::Ability
def initialize(user)
if user
can :create, [Question, Answer, Attachment, Comment]
can %i[update destroy], [Question, Answer], user_id: user.id
can :destroy, Comment, user_id: user.id
can :destroy, Attachment, attachable: { user_id: user.id }
View ability_spec.rb
require 'rails_helper'
RSpec.describe Ability do
subject(:ability) { Ability.new(user) }
describe "for guest" do
let(:user) { nil }
it { should be_able_to :read, :all }
it { should_not be_able_to :manage, :all }
View gist:40fc77b8a815ce5944b0c3ee8f6f86d8
#application.js
var App = App || {}
App.cable = ActionCable.createConsumer();
#questions.coffee
ready = ->
questionsList = $('.questions-list')
View gist:35c971de7ec100ddce41f886f9c7e029
Started POST "/questions" for 127.0.0.1 at 2018-06-27 14:53:40 +0300
Processing by QuestionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"89Ynn9vtVRoTip2t7mZyI5EixXTqjgOerZnKpRFe1yL0fmRx9KRk2xmMldAuk50/hg50uipn5jJUyy0S3kDI6A==", "question"=>{"title"=>"Question", "body"=>"jhjhjhjhjhj", "attachments_attributes"=>{"0"=>{"_destroy"=>"false"}}}, "commit"=>"Create"}
User Load (3.6ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
↳ /Users/pavelsazonov/.rvm/gems/ruby-2.5.0@qna/gems/activerecord-5.2.0/lib/active_record/log_subscriber.rb:98
(0.2ms) BEGIN
↳ app/controllers/questions_controller.rb:25
Question Create (7.9ms) INSERT INTO "questions" ("title", "body", "created_at", "updated_at", "user_id") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["title", "Question"], ["body", "jhjhjhjhjhj"], ["created_at", "2018-06-27 11:53:40.942765"], ["updated_at", "2018-06-27 11:53:40.942765"], ["user_id", 1]]
↳ ap
View тест-гуру-вопрос.txt
Which tag is used to refer to a paragraph?
<p>
<br>
err
err
View тест-гуру-вопрос.txt
Show syntax to define a new function?
function name(parameters) {};
func name(parameters) {};
View тест-гуру-вопрос.txt
Which tag is used to set background color?
background-color
color