Skip to content

Instantly share code, notes, and snippets.

@seniorihor
seniorihor / recursive_cocktail.rb
Created May 30, 2019 14:14
Cocktail "Recursive": 20% of alcohol, 30% of water and 50% of cocktail "Recursive"...
require "faker" [35/39]
class RecursiveCocktail
def initialize(ingredients: {}, capacity: 500) # default capacity - 500 ml
validate_ingredients!(ingredients)
@ingredients = {}
ingredients.each do |ingredient, percentage|
@ingredients[ingredient] = { percentage: percentage / 100.0, used: 0 }
end
@cocktail_name = generate_cocktail_name
@seniorihor
seniorihor / .spacemacs
Created September 8, 2017 10:38
Spacemacs config
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory
def solution(arr)
index = 0
while index < arr.count do
left_s = (index-1) >= 0 ? arr.slice(0..(index-1)).reduce(0, :+) : 0
right_s = arr.slice((index+1)..(arr.count-1)).reduce(0, :+)
return index if left_s == right_s
index +=1
@seniorihor
seniorihor / app.rb
Last active August 9, 2016 01:50
martian_rovers
require_relative "./rover"
input_array = []
file = ARGV[0]
raise "Not specified input file!" if file.to_s.empty?
File.open(file, "r") do |f|
f.each_line { |line| input_array << line }
end
@seniorihor
seniorihor / shutdown.rb
Created August 14, 2012 21:18
shutdowner
#!/usr/bin/env ruby
# encoding: utf-8
class Shutdown
def initialize(*options)
@action = options[0]
@time = options[1]
@allow_actions = %w(halt reboot)
end
@seniorihor
seniorihor / shutdown.rb
Created April 25, 2012 22:38
Автовимикалка компа — надпотрібна утиліта! pre-alpha 1
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
class Shutdown
def initialize(arguments)
@argv1 = arguments[0].to_s
if arguments.size > 1
@argv2 = arguments[1].to_i
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# Author: seniorihor (12.03.2012)
class MyArray
def initialize
@array = []
@max_positive = 0
@max_minimum = 0
end
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# Author: seniorihor (12.03.2012)
class MyArray
def initialize
@array = []
end
def show_condition
print <<-CONDITION
@seniorihor
seniorihor / general.rb
Created March 11, 2012 20:02
Рішення задачі "Приїзд генерала" з http://codeforces.ru/contest/144/problem/A
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# Aurhor: seniorihor (12.03.2012)
class General
def initialize(quantity, numbers)
@quantity = quantity
@numbers = numbers
@seconds = 0
end
#!/usr/bin/python3.2 -tt
# *-* coding: utf-8 *-*
allow_names = ['Mila', 'Ihor', 'Stas', 'Michel', 'Bogdan']
name = str(input('Enter your name: '))
def birthday(name):
i = 0
while i < len(allow_names):
# Check name