Skip to content

Instantly share code, notes, and snippets.

View azelenets's full-sized avatar
:octocat:
Impossible is nothing

Andrii Zelenets azelenets

:octocat:
Impossible is nothing
View GitHub Profile
@azelenets
azelenets / index.html
Created March 12, 2025 08:31
Custom plain JS modal window
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Web Components</title>
<style>
* {
box-sizing: border-box;
@azelenets
azelenets / read and write to files
Created February 26, 2025 08:13
Read CSV files from fir and group by last column value (HTTP response code)
Dir.foreach('broken_links_data') do |filename|
next if filename == '.' or filename == '..'
grouped_data = {}
File.foreach("broken_links_data/#{filename}") do |line|
line_data = line.split(',')
grouped_data[line_data.last.chomp] ||= []
grouped_data[line_data.last.chomp] << "#{line_data[0..2].join(',')},\"#{line_data[3..-2].join(',')}\""
end
RSpec.shared_examples 'validates url' do |attribute, validation_options = {}|
describe "##{attribute}" do
if validation_options[:allow_blank]
context 'when blank' do
let(:value) { '' }
it { is_expected.to allow_value(value).for(attribute) }
end
end
def solution(input_array)
missing_numbers_array = (1..input_array.size + 1).to_a - input_array
missing_numbers_array.first
end
def solution(counters_count, initial_counters)
current_max_value = 0
max_value_to_set = 0
counters = Array.new(counters_count, 0)
initial_counters.each do |current_counter|
if current_counter > counters_count
max_value_to_set = current_max_value
else
current_counter -= 1
def solution(array)
sorted_array = array.sort
return 0 if sorted_array[0] != 1
sorted_array.size.times do |index|
break if sorted_array[index + 1] == nil
return 0 if sorted_array[index] + 1 != sorted_array[index + 1]
end
# Using Array#each_with_index
def solution(desired_position, fallings)
covered_positions = []
fallings.each_with_index do |falling_position, second|
if falling_position <= desired_position && !covered_positions.include?(falling_position)
covered_positions << falling_position
end
return second if covered_positions.size == desired_position
def solution(a)
last_index = a.size - 1
head = a[0]
tail = a[1..last_index].inject(0, :+)
min_diff = (head - tail).abs
(1..last_index-1).each do |arr_index|
head += a[arr_index]
tail -= a[arr_index]
def solution(a)
# write your code in Ruby 2.2
return 1 if a.size == 0
n = a.size + 1
(n * (n + 1) / 2) - a.inject(0, :+)
end
def solution(x, y, d)
# write your code in Ruby 2.2
distantion = y - x
(distantion / d.to_f).ceil
end