Skip to content

Instantly share code, notes, and snippets.

@max-power
max-power / chinese_zodiac_animal.rb
Last active February 23, 2025 17:44
Chinese Zodiac Animals
ZodiacAnimal = Data.define(:icon, :name, :chinese_name, :earthly_branch, :element, :trine, :yin) do
def self.all
[
new( icon: "🐭", name: "Rat", chinese_name: "鼠", earthly_branch: "子", element: "Water", trine: 1, yin: false ),
new( icon: "🐂", name: "Ox", chinese_name: "牛", earthly_branch: "丑", element: "Earth", trine: 2, yin: true ),
new( icon: "🐅", name: "Tiger", chinese_name: "虎", earthly_branch: "寅", element: "Wood" , trine: 3, yin: false ),
new( icon: "🐇", name: "Rabbit", chinese_name: "兔", earthly_branch: "卯", element: "Wood" , trine: 4, yin: true ),
new( icon: "🐉", name: "Dragon", chinese_name: "龙", earthly_branch: "辰", element: "Earth", trine: 1, yin: false),
new( icon: "🐍", name: "Snake", chinese_name: "蛇", earthly_branch: "巳", element: "Fire" , trine: 2, yin: true ),
new( icon: "🐎", name: "Horse", chinese_name: "马", earthly_branch: "午", element: "Fire" , trine: 3, yin: false),
@max-power
max-power / tag.rb
Last active March 29, 2024 12:18
Very simple HTML-Tags in Ruby
class Tag
def initialize(name, content = nil, **attributes, &block)
@name = name
@content = block_given? ? yield : content
@attributes = attributes
end
def to_s
"<#{@name}#{attributes}>#{@content}</#{@name}>"
end
@max-power
max-power / base.css
Created March 7, 2024 11:11
Basic starter CSS
*, *::after, *::before {
box-sizing: border-box;
}
body { margin: 0; }
[hidden] { display: none; }
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
@max-power
max-power / timer.rb
Last active December 8, 2023 22:06
Simple timing functions. Include it or use as standalone module
module Timer
module_function
def time unit = :microsecond
Process.clock_gettime(Process::CLOCK_MONOTONIC, unit)
end
def time_it start = time
yield
time_diff start
@max-power
max-power / age.rb
Last active December 10, 2017 18:45
Ruby Age Calculation
class Age
def initialize(dob)
@dob = dob
end
def now
at Time.now
end
def at(date)
@max-power
max-power / number_with_unit.rb
Last active November 11, 2017 04:36
Number with Unit
require 'delegate'
class NumberWithUnit < SimpleDelegator
def initialize(number, unit)
super number
@unit = unit
end
def to_s
"#{super}#{@unit}"
@max-power
max-power / phonetic.gemspec
Last active November 10, 2017 05:48
Phonetic Spelling: NATO, LAPD and lots more
Gem::Specification.new do |s|
s.name = 'phonetic'
s.version = '0.0.1'
s.platform = Gem::Platform::RUBY
s.author = 'Kevin Melchert'
s.email = '[email protected]'
s.summary = 'Papa - Hotel - Oscar - November - Echo - Tango - India - Charlie - Sierra - Papa - Echo - Lima - Lima - India - November - Golf'
s.description = 'Phonetic Spelling: NATO, LAPD and lots more'
s.files = ['phonetic.rb']
@max-power
max-power / din.css
Last active November 13, 2017 00:43
DIN.css
.DIN.A0 { width:841mm; height:1189mm; }
.DIN.A1 { width:594mm; height: 841mm; }
.DIN.A2 { width:420mm; height: 297mm; }
.DIN.A3 { width:297mm; height: 420mm; }
.DIN.A4 { width:210mm; height: 297mm; }
.DIN.A5 { width:148mm; height: 210mm; }
.DIN.A6 { width:105mm; height: 148mm; }
.DIN.A7 { width: 74mm; height: 105mm; }
.DIN.A8 { width: 52mm; height: 74mm; }
.DIN.A9 { width: 37mm; height: 52mm; }
@max-power
max-power / attributes.rb
Last active November 5, 2017 22:13
Ruby attribute initialiser
class Attributes < Module
def initialize(*attr_names)
@attr_names = attr_names
define_method :attributes { attr_names }
end
private
def included(base)
super
Gem::Specification.new do |s|
s.name = 'power-month'
s.version = '0.0.4'
s.platform = Gem::Platform::RUBY
s.author = 'Kevin Melchert'
s.email = '[email protected]'
s.summary = 'Month of Year.'
s.description = 'Super simple Month of Year implementation.'
s.files = ['month.rb']