Skip to content

Instantly share code, notes, and snippets.

@hmlON
hmlON / minesweeper.rb
Last active April 7, 2017 21:00
Minesweeper logic ruby code
class Field
attr_accessor :field, :dimenstions, :number_of_mines
def initialize(dimenstions, number_of_mines)
@dimenstions = dimenstions
@number_of_mines = number_of_mines
initialize_free_of_mines_coordinates
build_field
fill_field_with_mines
end
@hmlON
hmlON / progress_bar.rb
Created April 13, 2017 20:54
Ruby helper for html progress bar tag with bootstrap
class ProgressBar
include ActionView::Helpers::TagHelper
def initialize(current:, min: 0, max: 100, text: '')
@current = current
@min = min
@max = max
@text = text
end
@hmlON
hmlON / Gemfile
Created June 7, 2017 10:35
This script finds definition of words in input.txt and creates output.csv with 2 columns (word, definition)
source 'https://rubygems.org'
gem 'capybara'
gem 'capybara-webkit'
@hmlON
hmlON / sort_array_with_different_types.rb
Created June 28, 2017 17:11
Sort subarrays with same type of differrent typed array. (['b', a', 2, 1, 'c'] => ['a', 'b', 1, 2, 'c'])
class TypedArraySorter < Struct.new(:array)
def sort
joined_sorted_splitted_array
end
private
def splitted_array_by_types
result = []
current_part = []
@hmlON
hmlON / user.sublime-keymap
Last active July 23, 2017 17:42
Sublime settings
[
// These are from Atom
{ "keys": ["ctrl+\\"], "command": "toggle_side_bar" },
{ "keys": ["ctrl+up"], "command": "swap_line_up" },
{ "keys": ["ctrl+down"], "command": "swap_line_down" },
// Go To Definition
{ "keys": ["ctrl+e"], "command": "goto_definition" },
{ "keys": ["ctrl+t"], "command": "goto_symbol_in_project" },
]
@hmlON
hmlON / coupon_generator.rb
Created August 2, 2017 10:43
Coupon generator
require 'securerandom'
count = 20000
output = File.open("coupons_#{count}.csv", 'w')
count.times do
output.puts SecureRandom.hex(10)
end
output.close
@hmlON
hmlON / Statement.java
Created December 10, 2017 15:20
Java test parser in Ruby
package whiteBox;
import deposit.FixedTotalDeposit;
import deposit.TotalDeposit;
import order.Order;
import order.OrderItem;
import order.ProductType;
import order.ShipmentType;
import org.junit.Test;
@hmlON
hmlON / text_newline_remover.py
Created June 30, 2018 14:05
Removes newlines from text
text = """
Невиконання першої умови свідчить про надмірну спрощеність моделі,
зокрема про необхідність збільшення порядку поліноміальної моделі.
Невиконання другої умови є свідченням того, що модель треба спростити,
наприклад зменшити порядок полінома. У деяких випадках друга умова
може не виконуватися навіть для однофакторних лінійних моделей. Найчастіше
це може бути наслідком свідомого підганяння емпіричних даних
під заздалегідь задану модель. Це часто роблять у навчальних задачах, але
на практиці такий результат свідчить про навмисне викривлення первинних
даних. Іншою причиною може бути неправильна (завищена) оцінка
@hmlON
hmlON / latest_releases_deezer.py
Created December 13, 2018 17:09
Fetching latest releases from Deezer API
deezer_id = 700513741 # paste your ID here
# hello, User
import requests
url = f"https://api.deezer.com/user/{deezer_id}"
user_response = requests.get(url)
name = user_response.json()['name']
print(f"Hello, {name}!")
# fetching favorite artists