This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inputs = %w[ | |
CollectionSelectInput | |
DateTimeInput | |
FileInput | |
GroupedCollectionSelectInput | |
NumericInput | |
PasswordInput | |
RangeInput | |
StringInput | |
TextInput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h = {} | |
h[:a] | |
h.default = 0 | |
h[:a] += 1 | |
h = Hash.new(0) | |
require 'active_support/core_ext/hash/indifferent_access' | |
h = {"a" => 1, "b" => 2} | |
h.symbolize_keys | |
h.with_indifferent_access[:a] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def print3(a,b,c) | |
puts "a: #{a}, b: #{b}, c:#{c}" | |
end | |
a = [1,2,3] | |
b = Array.new(3, 1) | |
c = Array.new(3) {|i| i*2} | |
print3(*a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file is an implementation of multi-level statistics. | |
# Value object. It can be created basing on SQL output. | |
SingleSubmissionStats = | |
Struct.new(:shift, :retreat_type, | |
:retreat_level, :retreat_type_and_level_id, | |
:gender, :reserve, :status, :count) | |
# Vlass responsible for calculating various staatistics. | |
# It contains a stats array that can consist of SingleSubmissionStats |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> user.devices.all.uniq.class | |
=> Device::ActiveRecord_AssociationRelation | |
# so that we can chain more AR methods | |
> user.devices.all.uniq.limit(1) | |
=> [Device] | |
> u.devices.uniq.class | |
=> Array | |
# so we can only work on array: | |
> user.devices.uniq.limit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ pry | |
[1] pry(main)> require "roo" | |
=> true | |
[2] pry(main)> require "roo/version" | |
=> true | |
[3] pry(main)> Roo::VERSION | |
=> "2.7.1" | |
[4] pry(main)> sheet = Roo::Spreadsheet.open("roo-percents-as-strings.xlsx", extension: "xlsx") | |
=> <#Roo::Excelx:1257514717731600 @tmpdir @shared @filename @sheet_files @sheet_names @sheets @sheets_by_name @options @cell @cell_type @cells_read @first_row @last_row @first_column @last_column @header_line> | |
[5] pry(main)> sheet.formatted_value('A', 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "benchmark/ips" | |
PART = <<TEXT | |
A text with 123,21231,231,23d a number: 12,212,234,12 | |
Other 12 43 123,21231,22,22,2,33d Some other 9012,123123 12 | |
TEXT | |
TEXT = PART * 100 | |
POSSESSIVE = /(\d++,?)++/ | |
LAZY = /(\d+?,?)+?/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unrolling: 1299.0 i/s | |
possessive: 1146.9 i/s - same-ish: difference falls within error | |
greedy: 63.4 i/s - 20.48x slower | |
lazy: 61.8 i/s - 21.03x slower |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# arrays | |
result = [] | |
# initial data | |
values = arrays.map{|a| a.next} | |
while true | |
maximal_value = values.max | |
for i 0...values.size do |
OlderNewer