Skip to content

Instantly share code, notes, and snippets.

@EdwardDiehl
Forked from firedev/colors.rb
Created April 15, 2016 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EdwardDiehl/cafd3b0c78ad9883eefe839bdd42ddc9 to your computer and use it in GitHub Desktop.
Save EdwardDiehl/cafd3b0c78ad9883eefe839bdd42ddc9 to your computer and use it in GitHub Desktop.
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