Skip to content

Instantly share code, notes, and snippets.

View Lichers0's full-sized avatar

Romodanov Denis Lichers0

View GitHub Profile

Constant lookup in Ruby can happen lexically or through the ancestry tree of the receiver(a class or module). You can identify which lookup rules are being applied by the context you're in or by the syntax being used to define a class or module.

A class body that is defined as class A::B::C; …; end will lookup constants through the ancestry tree when a constant is evaluated in its class body. Anytime you see A::B::C being used as syntax to define a class or lookup the value of a constant the ancestry tree is being used for the lookup.

@Lichers0
Lichers0 / task_3.rb
Created September 30, 2021 10:29
task 3
# Problem Description
# Update the stock with new products. If the product in the stock update is new, add it to the current stock. If the product in the stock update is present in the current stock, add it, but only if the current stock is not already full. Assume that the data is correct, e.g. there are no negative numbers in the stock update. Data is given in a line-by-line format and the answer is expected in the same format. It should be sorted in the same order as the input data with new items added to the end in the same order they are encountered in the stock update.
# Example:
# Input data:
text = <<-TXT
current_stock
10,Glass
2,Water bottle

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.

Setup

Replace IRB with Pry (in your Gemfile) and Byebug with pry-byebug.

gem 'pry-rails', group: [:development, :test]
gem 'pry-byebug', group: [:development, :test]

Using PRY

@Lichers0
Lichers0 / rich_domain_models2.md
Created May 15, 2021 00:23 — forked from vsavkin/rich_domain_models2.md
Building Rich Domain Models in Rails (revision 2)

Building Rich Domain Models in Rails.

Part 1. Decoupling Persistence.

Abstract

Domain model is an effective tool for software development. It can be used to express really complex business logic, and to verify and validate the understanding of the domain among stakeholders. Building rich domain models in Rails is hard. Primarily, because of Active Record, which doesn't play well with the domain model approach.

One way to deal with this problem is to use an ORM implementing the data mapper pattern. Unfortunately, there is no production ready ORM doing that for Ruby. DataMapper 2 is going to be the first one.

Another way is to use Active Record just as a persistence mechanism and build a rich domain model on top of it. That's what I'm going to talk about in this article.

### 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 > 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 45.87.2.112 port 80 protocol http
then restart
if 3 restarts within 5 cycles then timeout
@Lichers0
Lichers0 / test-furu-question.txt
Created November 1, 2020 14:10
A question about Addition from TestGuru
2+2=
1
2
3
4