Consider a list of strings you need to permanently assign a random color.
First you should turn the string into a hash.
var string = "string"
var hash = 0
emails = Customer.select(:email).map(&:email) | |
emails.map do |email| | |
grouping = emails | |
.group_by{|em| Levenshtein.distance(email, em) } | |
.select {|k,v| k < 5 && != 0 } # ignore exact matches and ones far off | |
if !grouping.empty? | |
[email, grouping] | |
end |
/* bling.js */ | |
window.$ = document.querySelector.bind(document); | |
window.$$ = document.querySelectorAll.bind(document); | |
Node.prototype.on = window.on = function(name, fn) { this.addEventListener(name, fn); }; | |
NodeList.prototype.__proto__ = Array.prototype; | |
NodeList.prototype.on = function(name, fn) { this.forEach((elem) => elem.on(name, fn)); }; |
def buckets | |
[ | |
'myapp-production-backups', | |
'myapp-staging-backups', | |
'myapp-s3-logs' | |
] | |
end | |
def test_buckets_subdomain_private | |
buckets.each do |bucket_name| |
# NullStorage provider for CarrierWave for use in tests. Doesn't actually | |
# upload or store files but allows test to pass as if files were stored and | |
# the use of fixtures. | |
class NullStorage | |
attr_reader :uploader | |
def initialize(uploader) | |
@uploader = uploader | |
end |
class Invoice < ActiveRecord::Base | |
before_validation :generate_number, on: :create | |
private | |
def generate_number | |
prefix = "R#{Date.today.strftime('%y')}-" | |
last_order_number_this_year = self.class.where("number LIKE ?", "#{prefix}%").order("number DESC").limit(1).pluck(:number).first | |
number = last_order_number_this_year ? last_order_number_this_year.match(/\A#{prefix}(\d+)\z/)[1].to_i : 0 |
body * { | |
-webkit-animation: fade-in 2s ease-out; | |
animation: fade-in 2s ease-out; | |
} |
div.description a.autolink | |
{ | |
display: inline-block; | |
max-width: 250px; | |
text-overflow: ellipsis; | |
overflow: hidden; | |
} |
# local PHP Server | |
server() { | |
url="localhost:${2:-8000}" | |
if [ -z "$1" ]; then | |
php -S $url & # run server in background | |
else | |
php -S $url -t $1 & | |
fi | |
sleep 0.3s # wait for server to start |
# locales/en.yml | |
en: | |
time: | |
formats: | |
ical: "%Y%m%dT%H%M%SZ" |