Skip to content

Instantly share code, notes, and snippets.

View stephancom's full-sized avatar

stephan.com stephancom

View GitHub Profile
@stephancom
stephancom / thank_you.txt
Created March 11, 2019 23:25
ascii thank you suitable for facebook response even on mobile
!!!
┏┓┏┓╋╋╋╋╋╋┏┓
┃┗┫┗┳━┓┏━┳┫┣┓
┃┏┫┃┃╋┗┫┃┃┃━┫
┗━┻┻┻━━┻┻━┻┻┛
╋╋╋╋╋╋┏┳┓
┏┳┳━┳┳┫┃┃
┃┃┃╋┃┃┃┃┃
┣┓┣━┻━╋╋┫
┗━┛╋╋╋┗┻┛
@stephancom
stephancom / destructive.rake
Last active September 29, 2022 04:25
guard for destructive rake tasks
# _ _ _ _
# __| | ___ ___| |_ _ __ _ _ ___| |_(_)_ _____
# / _` |/ _ \/ __| __| '__| | | |/ __| __| \ \ / / _ \
# | (_| | __/\__ \ |_| | | |_| | (__| |_| |\ 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 February 11, 2019 21:10
Handy stdio helpers for Rspec - suppress output and fake input
# _ _ _ _ _
# ___| |_ __| (_) ___ | |__ ___| |_ __ ___ _ __ ___
# / __| __/ _` | |/ _ \ | '_ \ / _ \ | '_ \ / _ \ '__/ __|
# \__ \ || (_| | | (_) | | | | | __/ | |_) | __/ | \__ \
# |___/\__\__,_|_|\___/ |_| |_|\___|_| .__/ \___|_| |___/
# |_| by stephan.com
# especially handy for testing interactive rake tasks
# best in an rspec around block, and can even be chained eg:
#
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 January 16, 2019 06:31
Phone Format test
#! /usr/bin/ruby
# _ _
# ___| |_ ___ _ __ | |__ __ _ _ __ ___ ___ _ __ ___
# / __| __/ _ \ '_ \| '_ \ / _` | '_ \ / __/ _ \| '_ ` _ \
# \__ \ || __/ |_) | | | | (_| | | | || (_| (_) | | | | | |
# |___/\__\___| .__/|_| |_|\__,_|_| |_(_)___\___/|_| |_| |_|
# |_|
# coding challenge for Simplero
@stephancom
stephancom / asciify-fonts.js
Created August 10, 2018 00:27
show all asciify fonts in node.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 April 13, 2018 18:16
Obscures an email address with asterisks
# 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 March 27, 2018 20:02
Get valid values for a field with :inclusion validation via inspection
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 March 27, 2018 20:02
Get valid values for a field with :inclusion validation via inspection
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 November 4, 2017 10:59
ǝnʌ-ʇxǝʇdıןɟ
// __ _ _ _ _
// / _| (_) | | | |
// | |_| |_ _ __ | |_ _____ _| |_ ________ ___ _ ___
// | _| | | '_ \| __/ _ \ \/ / __|______\ \ / / | | |/ _ \
// | | | | | |_) | || __/> <| |_ \ V /| |_| | __/
// |_| |_|_| .__/ \__\___/_/\_\\__| \_/ \__,_|\___|
// | |
// |_| by stephan@stephan.com
//
// a vue filter for fliptext