Skip to content

Instantly share code, notes, and snippets.

View artyomlagun's full-sized avatar

Artsiom Lahun artyomlagun

View GitHub Profile
class PasscodeService
# assume that phone can contain from 7 to 9 digits
PHONE_REGEXP = /^\d{7,9}$/
def initialize
@response = { action: false, message: '' }
end
def send(phone)
# validate phone through regexp
@artyomlagun
artyomlagun / anagram.rb
Created September 20, 2021 09:51
Anagram on Ruby
def is_anagram?(first, second)
first = first.split('').sort.join # get sorted string from words characters
second = second.split('').sort.join
matches = first.length == second.length # check match by length
return if !matches # return if words have different length
first.length.times do |i| # check every character in sorted string
matches = first[i] == second[i]
@artyomlagun
artyomlagun / application.rb
Created December 16, 2020 13:23
Convert params key from JS practics to Ruby
#config/application.rb
class SnakeCaseParametersMiddleware
def initialize(app)
@app = app
end
def call(env)
request = ActionDispatch::Request.new(env)
request.request_parameters.deep_transform_keys!(&:underscore)

Disable Device Enrollment Notification on Mac.md

Restart the Mac in Recovery Mode by holding Comment-R during restart

Open Terminal in the recovery screen and type

csrutil disable
@artyomlagun
artyomlagun / ethereum_token.md
Last active January 8, 2018 08:49
Ethereum token

How to create Ethereum Token (ERC20 Ethereum Standard For Tokens)

ERC20 Standard

The ERC20 standard is basically a specific set of functions which developers must use in their tokens to make them ERC20 compliant. While this is not an enforced rule, most DAPP developers are encouraged to follow the standards to ensure that their tokens can undergo interactions with various wallets, exchanges and smart contracts without any issues. This was great news for everyone because now they at least had an idea of how future tokens are expected to behave. ERC20 tokens have gotten widespread approval and most of the DAPPS sold on ICO’s have