Skip to content

Instantly share code, notes, and snippets.

View denisdefreyne's full-sized avatar

Denis Defreyne denisdefreyne

View GitHub Profile
@denisdefreyne
denisdefreyne / leftpad.py
Last active October 21, 2024 18:50 — forked from lf-/leftpad.py
leftpad.py with prime indents (2, 3, 5, 7)
class left_pad:
def __init__(this,PadChar=' ',width=4):
this.PadChar=PadChar
this.width = width
def LeftPad(this,stringToPadWithChar):
charsToPad=this.width-len(stringToPadWithChar)
OutStr=''
if(charsToPad>0):
for i in range(0,charsToPad):
OutStr=OutStr+this.PadChar
# UNTESTED
# In lib/ somewhere
Nanoc::Filter.new(:fetch_snapshot_textual) do |content, params|
item = @items[params.fetch(:item)]
rep = item.reps[params.fetch(:rep, :default)]
compiled_content = rep.compiled_content(snapshot: params.fetch(:snapshot))
compiled_content
end
/***********************************************************
* config
*/
:root {
--base-size: 0.3625rem;
--size-1: calc(1 * var(--base-size));
--size-2: calc(2 * var(--base-size));
--size-3: calc(4 * var(--base-size));
@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