This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def valid_values(klass, kolumn) | |
klass.validators_on(kolumn).select { |v| v.is_a? ActiveModel::Validations::InclusionValidator }.first.options[:in].map(&:to_s) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def valid_values(klass, kolumn) | |
klass.validators_on(kolumn).select { |v| v.is_a? ActiveModel::Validations::InclusionValidator }.first.options[:in].map(&:to_s) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# hide email, eg john.doe@gmail.com -> j******o@g*******m | |
def obscure_email(email) | |
midstars = -> (s) { s.length > 2 ? s[0] + '*' * (s.length - 2) + s[-1] : s[0]+'*' } | |
email.split('@').map { |p| midstars.call(p) }.join('@') | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
asciify = require('asciify'); | |
asciify.getFonts(function (err, fonts) { fonts.forEach(function(f) { asciify(f, { font: f }, function(e, r) { console.log(r); }) }) }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/ruby | |
# _ _ | |
# ___| |_ ___ _ __ | |__ __ _ _ __ ___ ___ _ __ ___ | |
# / __| __/ _ \ '_ \| '_ \ / _` | '_ \ / __/ _ \| '_ ` _ \ | |
# \__ \ || __/ |_) | | | | (_| | | | || (_| (_) | | | | | | | |
# |___/\__\___| .__/|_| |_|\__,_|_| |_(_)___\___/|_| |_| |_| | |
# |_| | |
# coding challenge for Simplero |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TableHelpers | |
module ArrayMethods | |
def find_row(expected_row) | |
find_index do |row| | |
expected_row.all? do |expected_column| | |
first_column = row.find_index { |column| | |
content = normalize_content(column.content) | |
expected_content = normalize_content(expected_column) | |
matching_parts = expected_content.split(/\s*\*\s*/, -1).collect { |part| Regexp.escape(part) } | |
matching_expression = /\A#{matching_parts.join(".*")}\z/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# _ _ _ _ _ | |
# ___| |_ __| (_) ___ | |__ ___| |_ __ ___ _ __ ___ | |
# / __| __/ _` | |/ _ \ | '_ \ / _ \ | '_ \ / _ \ '__/ __| | |
# \__ \ || (_| | | (_) | | | | | __/ | |_) | __/ | \__ \ | |
# |___/\__\__,_|_|\___/ |_| |_|\___|_| .__/ \___|_| |___/ | |
# |_| by stephan.com | |
# especially handy for testing interactive rake tasks | |
# best in an rspec around block, and can even be chained eg: | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!!! | |
┏┓┏┓╋╋╋╋╋╋┏┓ | |
┃┗┫┗┳━┓┏━┳┫┣┓ | |
┃┏┫┃┃╋┗┫┃┃┃━┫ | |
┗━┻┻┻━━┻┻━┻┻┛ | |
╋╋╋╋╋╋┏┳┓ | |
┏┳┳━┳┳┫┃┃ | |
┃┃┃╋┃┃┃┃┃ | |
┣┓┣━┻━╋╋┫ | |
┗━┛╋╋╋┗┻┛ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-.-. .-. # | |
# / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / \ \ / / # | |
# `-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' `-`-' # | |
# .-------. ,-----. .-------. ___ _ .---. ____ ,---------. .-''-. # | |
# \ _(`)_ \ .' .-, '. \ _(`)_ \.' | | | | ,_| .' __ `.\ \ .'_ _ \ # | |
# | (_ o._)| / ,-.| \ _ \ | (_ o._)|| .' | |,-./ ) / ' \ \`--. ,---'/ ( ` ) ' # | |
# | (_,_) /; \ '_ / | :| (_,_) /.' '_ | |\ '_ '`) |___| / | | \ . (_ o _) | # | |
# | '-.-' | _`,/ \ _/ || '-.-' ' ( \.-.| > (_) ) _.-` | :_ _: | (_,_)___| # | |
# | | : ( '\_/ \ ;| | ' (`. _` /|( . .-' .' _ | (_I_) ' \ .---. # | |
# | | \ `"/ \ ) / | | | (_ (_) _) `-'`-'|___ | _( )_ | (_(=)_) \ `-' / # |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BlockQueue | |
def initialize(name) | |
@name = name | |
@blocks = [] | |
end | |
def run_later(&block) | |
Progress.log "queueing job for #{@name}" | |
@blocks << block | |
end |