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
# https://ihateregex.io/expr/uuid/ | |
/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/ | |
# https://rubular.com/r/sXJ27X08h7tKZ2 refactor by soawesomeman | |
/([0-9a-fA-F]{8}-?(?:[0-9a-fA-F]{4}-?){2}[0-9a-fA-F]{4}-?[0-9a-fA-F]{12})/ | |
# https://rubular.com/r/lIO6HeHPlHcTl3 further refactor by soawesomeman | |
# see: https://stackoverflow.com/questions/15205896/matching-any-character-except-an-underscore-using-regex#15206584 | |
/((?:(?!_)[\w\d]){8}-?(?:(?:(?!_)[\w\d]){4}-?){3}-?(?:(?!_)[\w\d]){12})/ |
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
# ruby-hash-with-or-without-rockets-to-javascript-object-notation-aka-json-style.rb | |
# | |
# - context: https://alwayscoding.ca/momentos/2012/06/15/ruby-hash-syntax-hashrocket-vs-json-style | |
# - regex by SoAwesomeMane: https://rubular.com/r/9wlDeHLHejZvuB | |
# - regex research: https://sadique.io/blog/2013/09/29/named-capture-groups-in-regular-expressions | |
# - more regex research: https://www.regular-expressions.info/refquick.html "\k Named backreference" | |
# - json schema from https://www.liquid-technologies.com/online-json-to-schema-converter | |
# - 🍻🍻🍻 | |
hash = {"$schema"=>"http://json-schema.org/draft-04/schema#", |
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
str = "ZZZ://ZZZZZZ (ZZZZ allocation - slider does not automatically reflect the entered Stop value and requires a click outside o | |
f the Stop input field)" | |
str.downcase.gsub(/\W/, '-').squeeze('-')[0..45].chomp('-') | |
# => "zzz-zzzzzz-zzzz-allocation-slider-does-not-aut" |
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
# https://stackoverflow.com/questions/5608918/pad-an-array-to-be-a-certain-size#16180695 | |
def rpad(item, padding, num) | |
Array(item).fill padding, Array(item).size, num | |
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
RX_URL = Regexp.new('^((?<protocol>https?):\/\/)?(?<host>[^\/]+)(\/(?<path>[^\?#]+))?(\?(?<query>[^#]+))?(#(?<fragment>.*))?', 'i') | |
# @see http://stackoverflow.com/questions/18825669/how-to-do-named-capture-in-ruby#18825787 | |
# @param url_str [String] URL string with or without `https://`, `http://` | |
# @return [Hash] hash with keys: `:protocol, :host, :path, :query, :fragment` | |
def url_to_hash(url_str) | |
m = url_str.match(RX_URL) | |
m.names.map(&:to_sym).zip(m.captures).to_h | |
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
# | |
# "generate a string with 0-9a-z (36 characters) that is ALWAYS 12 characters long. Change 12 to whatever length you want." | |
# -- Gerry Shaw via https://stackoverflow.com/questions/88311/how-to-generate-a-random-string-in-ruby#comment35392122_1619602 | |
# | |
# min length is 6 | |
def fake_code(length = 12) | |
# always lead with four chars | |
str = SecureRandom.hex.gsub(/\d/, "")[0..3] | |
# followed by chars or int |
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
## | |
# Using Text Transformation Methods | |
# | |
# ERB provides optional methods for transforming text. | |
# To use these features your code must include the module ERB::Util. | |
# via "An Introduction to ERB templating" (July 01, 2016) https://www.stuartellis.name/articles/erb/#using-text-transformation-methods- | |
# | |
# ERB transformation has changed since 2016: "j" not defined as alias but still executes without error, albiet weird rendering |
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
#!/bin/bash | |
ts=$(date "+%Y%m%d%H%M%S") | |
da=~/Documents/Desktop_Archives/$ts | |
mkdir -p $da | |
mv ~/Desktop/* $da | |
echo "created $da" |
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
str1 = "11423!@#$!@_asdf+_1234__asfsdf" | |
str1.gsub(/\W/,'') | |
# => "11423_asdf_1234__asfsdf" (seems legit…) | |
str2 = "11423!@#$!@_asdf+_1234__asf-sdf" | |
str2.gsub(/\W/,'') | |
# => "11423_asdf_1234__asfsdf" (doesn't preserve dash) | |
str2.gsub(/[^-\w]/,'') | |
# => "11423_asdf_1234__asf-sdf" (profit!) |
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
[7] pry(#<#<Class:0x007fbefaceac00>>)> rows_per_page, items_per_row = PdfBuilder.rows_per_page_items_per_row("image_large") | |
=> [3, 2] | |
[8] pry(#<#<Class:0x007fbefaceac00>>)> array = 8.times.map(&:to_s) | |
=> ["0", "1", "2", "3", "4", "5", "6", "7"] | |
[9] pry(#<#<Class:0x007fbefaceac00>>)> array.in_groups_of(items_per_row).in_groups_of(rows_per_page) | |
=> [[["0", "1"], ["2", "3"], ["4", "5"]], [["6", "7"], nil, nil]] | |
[10] pry(#<#<Class:0x007fbefaceac00>>)> array.in_groups_of(items_per_row, []).in_groups_of(rows_per_page, []) | |
=> [[["0", "1"], ["2", "3"], ["4", "5"]], [["6", "7"], [], []]] | |
[11] pry(#<#<Class:0x007fbefaceac00>>)> array.in_groups_of(items_per_row).in_groups_of(rows_per_page, []) | |
=> [[["0", "1"], ["2", "3"], ["4", "5"]], [["6", "7"], [], []]] |