Create a gist now

Instantly share code, notes, and snippets.

@firedev /colors.rb
Last active Apr 15, 2016

What would you like to do?
Colors.rb – Functional programming in Ruby example
#!/usr/bin/env ruby
require 'paleta'
to_paleta = ->(color) { Paleta::Color.new(:hex, color) rescue nil }
to_div = ->(str) {
"<div style='font-family: sans-serif; width: 5em; height: 3em;
line-height: 3em; display: inline-block; text-align: center;
margin: 0.25em; border-radius: 0.25em; padding: 1em;
background: ##{str}'>
##{str}
</div>"
}
File.open('colors.html', 'w') do |file|
file.puts(
ARGF
.map(&:chomp)
.map(& to_paleta)
.compact
.sort_by(&:hue)
.map(&:hex)
.uniq
.map(& to_div)
)
end
`open colors.html`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment