Skip to content

Instantly share code, notes, and snippets.

@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)
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 = 'kevin.melchert@gmail.com'
s.summary = 'Month of Year.'
s.description = 'Super simple Month of Year implementation.'
s.files = ['month.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 / 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 = 'kevin.melchert@gmail.com'
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 / 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
@max-power
max-power / sinatra_mongo_api.rb
Last active October 29, 2017 14:42
Sinatra + MongoDB + JSON
require "sinatra"
require "mongo"
require "json"
class SimpleMongoApi < Sinatra::Base
set :mongo, Mongo::Client.new("mongodb://my.mongo.host/database")
def collection
settings.mongo["things"]
end