Skip to content

Instantly share code, notes, and snippets.

def reverse_1(array)
index = array.size - 1
result = []
for i in 0..index do
result[index - i] = array[i]
end
result
end
@mkaschenko
mkaschenko / git-churn.rb
Last active February 11, 2021 16:43
Provides churn statistics (frequency of change) for git repositories
#!/usr/bin/env ruby
# frozen_string_literal: true
# This program modifies the original output of git-churn program https://github.com/garybernhardt/dotfiles/blob/master/bin/git-churn.
# It highlights current project files in green colour.
unless Kernel.system('command -v git-churn &> /dev/null')
STDOUT.puts("Install git-churn first. See details at https://github.com/garybernhardt/dotfiles/blob/master/bin/git-churn")
Kernel.exit
end
@mkaschenko
mkaschenko / difference_in_years.rb
Last active May 16, 2022 06:15
The difference in years between dates
# Year 2017
module Date
def self.difference_in_years(left_date, right_date)
# NOTE: xxxx.yyzz (2017.1231)
#
# xxxx stands for years
# yy stands for months
# zz stands for days
#
# frozen_string_literal: true
require 'axlsx' # https://github.com/randym/axlsx
require 'rubyXL' # https://github.com/weshatheleopard/rubyXL
require 'spreadsheet' # https://github.com/zdavatz/spreadsheet
require 'memory_profiler'
rows = 1_000
columns = 20
# NOTE: There are Application pages we need to calculate progress for.
# Every page has specific rules/conditions how to estimate progress.
# Rules have scores/weights and they are used to calculate progress.
# pages = {
# home_page: { home_page_rule => score },
# info_page: { info_page_rule_1 => score_1, info_page_rule_2 => score_2 }
# }
module ApplicationProgress
module Rules
def human?(req)
req[:headers][:client] != 'google'
end
def auth?(req)
req[:params][:secret] == 'ruby'
end
def access_rules
{uri: '/admin', handler: {and: [:human?, :auth?]}}
@mkaschenko
mkaschenko / hungry_dog.rb
Last active August 29, 2015 13:59
Rspec and predicates
class Dog
def hungry?
true
end
def full?
false
end
end
@mkaschenko
mkaschenko / 1_spec.rb
Last active November 25, 2023 14:15
A class developed via TDD
# Year 2014
# encoding: UTF-8
require 'export'
require 'export/secure_name'
require 'active_support/core_ext/object/blank'
describe Export::SecureName do
subject { described_class.new('name', '.ext') }
class Creature
def self.metaclass
class << self
self
end
end
end
require 'test/unit'
class TestRecursiveReverse < Test::Unit::TestCase
def test_o_make
assert_equal [3, 2, 1], RecursiveReverse.new.o_make([1, 2, 3])
end
def test_f_make
assert_equal [3, 2, 1], RecursiveReverse.new.f_make([1, 2, 3])