Skip to content

Instantly share code, notes, and snippets.

Avatar

stephan.com stephancom

View GitHub Profile
@stephancom
stephancom / thank_you.txt
Created Mar 11, 2019
ascii thank you suitable for facebook response even on mobile
View thank_you.txt
!!!
┏┓┏┓╋╋╋╋╋╋┏┓
┃┗┫┗┳━┓┏━┳┫┣┓
┃┏┫┃┃╋┗┫┃┃┃━┫
┗━┻┻┻━━┻┻━┻┻┛
╋╋╋╋╋╋┏┳┓
┏┳┳━┳┳┫┃┃
┃┃┃╋┃┃┃┃┃
┣┓┣━┻━╋╋┫
┗━┛╋╋╋┗┻┛
@stephancom
stephancom / destructive.rake
Last active May 7, 2019
guard for destructive rake tasks
View destructive.rake
# _ _ _ _
# __| | ___ ___| |_ _ __ _ _ ___| |_(_)_ _____
# / _` |/ _ \/ __| __| '__| | | |/ __| __| \ \ / / _ \
# | (_| | __/\__ \ |_| | | |_| | (__| |_| |\ V / __/
# \__,_|\___||___/\__|_| \__,_|\___|\__|_| \_/ \___|
# handy guard for destructive rake tasks
# just include this before any troublesome task
# typical usage:
# task :riskytask, [:destructive, :environment] do
@stephancom
stephancom / stdio.rb
Created Feb 11, 2019
Handy stdio helpers for Rspec - suppress output and fake input
View stdio.rb
# _ _ _ _ _
# ___| |_ __| (_) ___ | |__ ___| |_ __ ___ _ __ ___
# / __| __/ _` | |/ _ \ | '_ \ / _ \ | '_ \ / _ \ '__/ __|
# \__ \ || (_| | | (_) | | | | | __/ | |_) | __/ | \__ \
# |___/\__\__,_|_|\___/ |_| |_|\___|_| .__/ \___|_| |___/
# |_| by stephan.com
# especially handy for testing interactive rake tasks
# best in an rspec around block, and can even be chained eg:
#
View table_helpers.rb
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/
@stephancom
stephancom / phone_format.rb
Last active Jan 16, 2019
Phone Format test
View phone_format.rb
#! /usr/bin/ruby
# _ _
# ___| |_ ___ _ __ | |__ __ _ _ __ ___ ___ _ __ ___
# / __| __/ _ \ '_ \| '_ \ / _` | '_ \ / __/ _ \| '_ ` _ \
# \__ \ || __/ |_) | | | | (_| | | | || (_| (_) | | | | | |
# |___/\__\___| .__/|_| |_|\__,_|_| |_(_)___\___/|_| |_| |_|
# |_|
# coding challenge for Simplero
@stephancom
stephancom / asciify-fonts.js
Created Aug 10, 2018
show all asciify fonts in node.js
View asciify-fonts.js
asciify = require('asciify');
asciify.getFonts(function (err, fonts) { fonts.forEach(function(f) { asciify(f, { font: f }, function(e, r) { console.log(r); }) }) });
@stephancom
stephancom / obscure_email.rb
Created Apr 13, 2018
Obscures an email address with asterisks
View obscure_email.rb
# 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
@stephancom
stephancom / valid_values.rb
Created Mar 27, 2018
Get valid values for a field with :inclusion validation via inspection
View valid_values.rb
def valid_values(klass, kolumn)
klass.validators_on(kolumn).select { |v| v.is_a? ActiveModel::Validations::InclusionValidator }.first.options[:in].map(&:to_s)
end
@stephancom
stephancom / valid_values.rb
Created Mar 27, 2018
Get valid values for a field with :inclusion validation via inspection
View valid_values.rb
def valid_values(klass, kolumn)
klass.validators_on(kolumn).select { |v| v.is_a? ActiveModel::Validations::InclusionValidator }.first.options[:in].map(&:to_s)
end
@stephancom
stephancom / fliptext-vue.js
Created Nov 4, 2017
ǝnʌ-ʇxǝʇdıןɟ
View fliptext-vue.js
// __ _ _ _ _
// / _| (_) | | | |
// | |_| |_ _ __ | |_ _____ _| |_ ________ ___ _ ___
// | _| | | '_ \| __/ _ \ \/ / __|______\ \ / / | | |/ _ \
// | | | | | |_) | || __/> <| |_ \ V /| |_| | __/
// |_| |_|_| .__/ \__\___/_/\_\\__| \_/ \__,_|\___|
// | |
// |_| by stephan@stephan.com
//
// a vue filter for fliptext
You can’t perform that action at this time.