Skip to content

Instantly share code, notes, and snippets.

View renatamarques97's full-sized avatar

Renata Marques renatamarques97

  • Qulture.rocks
  • Teresina, PI
View GitHub Profile
sudo docker-compose rm --all &&
sudo docker-compose pull &&
sudo docker-compose build --no-cache &&
sudo docker-compose up -d --force-recreate

following scenario: log

Webpack HOT dev build for Rails
Unhandled 'error' event
rake aborted!
SignalException: SIGTERM
bundle _1.17.3_ install
# given an array of hashes x:
x = [{"a" => 10}, {"b" => 20}, {"c" => 30}]
# return all the keys: ["a", "b", "c"]
x.flat_map(&:keys)
# return all the values: [10, 20, 30]
x.flat_map(&:values)
# return the sum of values: 60
# 1st
# 48ms
def running_sum(nums)
result = []
nums.inject(0) do |acc, n|
result << acc + n
acc + n
end
result
end
# 1st
# 56 ms
def find_numbers(nums)
count = 0
nums.each do |n|
count += 1 if n.digits.size.even?
end
count
end

File Modes

Ruby supports the following file modes:

r read-only, starts at beginning of file (default mode).
r+ read-write, starts at beginning of file.
w write-only, truncates existing file to zero length or creates a new file for writing.
w+ read-write, truncates existing file to zero length overwriting existing data or creates a new file for reading and writing.
a write-only, appends to end of file if file exists, otherwise creates a new file for writing.
a+ read-write, appends or reads from end of file if file exists, otherwise creates a new file for reading and writing.
=begin
Given a list of 24-hour clock time points in "Hour:Minutes" format, find the minimum minutes difference between any two time points in the list.
*
* Example 1:
* Input: ["23:59","00:00"] should return 1
* Example 2:
* Input: ["03:12","01:00", "03:10"] should return 2
=end
class Matrix
def call(string)
puts "rows:"
puts show_rows(string)
puts "columns:"
puts show_columns(string)
end
private

.transpose()

Assumes that self is an array of arrays and transposes the rows and columns.

a = [[1,2], [3,4], [5,6]]
a.transpose   #=> [[1, 3, 5], [2, 4, 6]]

.in_groups_of(number, fill_with = nil)

rails method