Skip to content

Instantly share code, notes, and snippets.

View denisdefreyne's full-sized avatar

Denis Defreyne denisdefreyne

View GitHub Profile
@denisdefreyne
denisdefreyne / gist:15091779e5ada3374e3c42c42b516a81
Created December 28, 2023 08:11
rdiscount-2.2.7.2/gem_make.out
current directory: /Users/denis/.rubies/ruby-3.3.0/lib/ruby/gems/3.3.0/gems/rdiscount-2.2.7.2/ext
/Users/denis/.rubies/ruby-3.3.0/bin/ruby extconf.rb
checking for random()... yes
checking for srandom()... yes
checking for rand()... yes
checking for srand()... yes
checking size of unsigned long... 8
checking size of unsigned int... 4
checking size of unsigned int... 4
checking size of unsigned short... 2
@denisdefreyne
denisdefreyne / term-bg-brightness.rb
Created November 10, 2022 12:06
Calculating terminal background color in Ruby
require 'io/console'
# Query RGB background color
raw = STDIN.raw do |stdin|
print "\e]11;?\a"
stdin.read(25)
end
# Parse
r, g, b = raw.scan(/[0-9a-f]{4}/).map { |part| part.to_i(16) / 65_535.0 }
@denisdefreyne
denisdefreyne / README.md
Created October 16, 2022 07:34
Set #any? vs. not #empty?

Calling #any? on Set is much slower than calling #empty? and negating it! Take a look at these benchmarks.

Warming up --------------------------------------
               #any?   182.420k i/100ms
         not #empty?     2.432M i/100ms
Calculating -------------------------------------
               #any?      1.834M (± 1.3%) i/s -      9.303M in   5.073017s
         not #empty?     24.254M (± 0.3%) i/s -    121.597M in   5.013433s
@denisdefreyne
denisdefreyne / nanoc-photos.md
Created September 7, 2022 20:02
Nanoc example: Creating separate pages for each photo

content/photos/dog.jpg

content/photos/dog.yaml:

alt: A *very* good doggo. Who’s a good girl? woof woof yes you are YOU ARE

Rules:

class Score
include Comparable
# …
def <=>(other)
# …
end
end
class Score
# …
def <=>(other)
return nil unless other.class == self.class
@value <=> other.value
end
end
scores = [
Score.new(6),
Score.new(17),
Score.new(14),
Score.new(13),
Score.new(11),
]
p scores.min
p scores.max
class Score
attr_reader :value
def initialize(value)
@value = value
end
def grade
if @value < 10
"failing"
case "/home/denis"
when PathPattern.new("/home/*")
puts "Home sweet home"
else
puts "Somewhere, I guess"
end
bin_ruby = Path.new("bin", "ruby")
var_log = Path.new("var", "log")
pattern = PathPattern.new("/bin/*")
pattern === bin_ruby # => true
pattern === var_log # => false