Skip to content

Instantly share code, notes, and snippets.

View kleytonmr's full-sized avatar
🎯
Focusing

Kleyton Matos Ramos kleytonmr

🎯
Focusing
View GitHub Profile
@kleytonmr
kleytonmr / check_unused_images.md
Created July 13, 2024 23:50
Clean unused images

docker images -a

docker images -f "dangling=true"

docker ps -a --format '{{.Image}}' | sort | uniq -c | sort -nr

docker ps -a --filter ancestor=<image_name_or_id>

docker image prune -a

@kleytonmr
kleytonmr / notes-tropicalruby.txt
Last active September 3, 2024 19:20
Repos I will check - Tropical Ruby
- https://github.com/lazaronixon/authentication-zero
- https://github.com/seattlerb/flog
- https://gist.github.com/tenderlove/44fd4206b9cbc42bcafc90adb3f5820d
- https://github.com/anchietajunior/sporticalapp
- https://github.com/dphilla/boxer
- https://github.com/danmayer/churn
- https://github.com/whitesmith/rubycritic
- https://shopify.engineering/how-to-introduce-composite-primary-keys-in-rails
@kleytonmr
kleytonmr / getRandomIntExcludingExistingNumbers.js
Last active January 13, 2023 15:49
Get random int excluding existing numbers
/**
* Returns a random integer between min (inclusive) and max (inclusive).
* Pass all values as an array, as 3rd argument which values shouldn't be generated by the function.
* The value is no lower than min (or the next integer greater than min
* if min isn't an integer) and no greater than max (or the next integer
* lower than max if max isn't an integer).
* Using Math.round() will give you a non-uniform distribution!
*/
function getRandomInt(min, max) {
arr = [ 1, 1, 2, 3, 5, 8, 13, 21, 34 ]
res = arr.bsearch do |val|
case when val < 19
then +1 when val > 23
then -1
else 0
end
end
res # => 21
@kleytonmr
kleytonmr / union.rb
Last active June 1, 2020 02:25
Union
# arr | other_array → an_array
%w[a b c] | %w[c d a] # => ["a", "b", "c", "d"]
@kleytonmr
kleytonmr / try_convert.rb
Last active June 1, 2020 02:02
Try convert
class Stooges
def to_ary
%w[larry Curly Moe]
end
end
a = Stooges.new # => #<Stooges:0x00007f92438f6678>
a.class # => Stooges
b = Array.try_convert(Stooges.new) # => ["larry", "Curly", "Moe"]
@kleytonmr
kleytonmr / repetition.rb
Last active June 1, 2020 02:15
Repetition
# arr * int → an_array
# arr * str → a_string
[1, 2, 3] * 3 # => [1, 2, 3, 1, 2, 3, 1, 2, 3]
[1, 2, 3] * "-" # => "1-2-3"
[1, 2, 3] * "--" # => "1--2--3"
[1, 2, 3] * "+" # => "1+2+3"
[1, 2, 3] * ";" # => "1;2;3"
@kleytonmr
kleytonmr / rassoc.rb
Last active June 1, 2020 03:08
Rassoc
# arr.rassoc( key ) → an_array or nil
a = [[1, 'one'], [2, 'two'], [3, 'threee'], ['ii', 'two']]
a.rassoc('two') # => [2, "two"]
a.rassoc('four') # => nil
@kleytonmr
kleytonmr / product.rb
Last active June 1, 2020 03:06
Product
# arr.product( ‹ arrays›* ) → result_array
# arr.product( ‹ arrays›* ) ‹{|combination| … }› → arr
suits = %w[ C D H S ]
ranks = [ *2..10, *%w{ J Q K A }]
card_deck = suits.product(ranks).shuffle
card_deck.first(13) # => [["H", "Q"], ["D", 7], ["S", "A"], ["S", "J"],
# .. ["D", 2], ["S", 10], ["D", 4], ["S", 9], ["C", 7],
# .. ["C", 4], ["H", 5], ["D", 5], ["S", 4]]
@kleytonmr
kleytonmr / pop.rb
Last active June 1, 2020 03:04
Pop
# arr.pop( ‹n›* pop ) → obj or nil
a = %w[ f r a b j o u s ]
a.pop # => "s"
a # => ["f", "r", "a", "b", "o", "u"]
a.pop(3) # => ["b", "o", "u"]
a # => ["f", "r", "a", "b"]