Skip to content

Instantly share code, notes, and snippets.

Avatar

So Awesome Man awesome

View GitHub Profile
View guide: use puma-dev as proxy.md
View ruby-require-a-local-file-or-gem-in-irb.rb
# via https://stackoverflow.com/questions/43519292/load-file-from-local-gem-in-irb#46941281
#
# If you want to require a local file or gem in irb, I like this method:
#
# irb -I lib -r usps_countries
# This allows you to then require the module in your new irb instance:
#
# require 'usps_countries'
# Options used:
#
View gist:b592620313d4ff8712800b40d1e1511b
Originall From: Posted 2015-05-29 http://ubwg.net/b/full-list-of-ffmpeg-flags-and-options
This is the complete list that’s outputted by ffmpeg when running ffmpeg -h full.
usage: ffmpeg [options] [[infile options] -i infile]… {[outfile options] outfile}…
Getting help:
-h — print basic options
-h long — print more options
-h full — print all options (including all format and codec specific options, very long)
@awesome
awesome / ruby-regexp-uuid-and-dash-optional.rb
Last active Sep 5, 2022
UUID pure regexp and dash/hyphen is optional; return only full uuid matched
View ruby-regexp-uuid-and-dash-optional.rb
# 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})/
@awesome
awesome / ruby-hash-with-or-without-rockets-to-javascript-object-notation-aka-json-style-howto-by-soawesomeman.rb
Created Jun 28, 2022
ruby-hash-with-or-without-rockets-to-javascript-object-notation-aka-json-style.rb
View ruby-hash-with-or-without-rockets-to-javascript-object-notation-aka-json-style-howto-by-soawesomeman.rb
# 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#",
@awesome
awesome / format-ticket-title-to-git-branch-name.rb
Created Jun 21, 2022
format ticket title to git branch name
View format-ticket-title-to-git-branch-name.rb
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"
@awesome
awesome / pad-an-array-to-be-a-certain-size.rb
Created Dec 17, 2021
Pad An Array To Be A Certain Size in Ruby
View pad-an-array-to-be-a-certain-size.rb
# 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
@awesome
awesome / ruby-url-to-hash-and-query-to-hash.rb
Created Dec 9, 2021
Ruby: URL-to-Hash & Query-to-Hash
View ruby-url-to-hash-and-query-to-hash.rb
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
@awesome
awesome / ruby-securerandom-fake-string-of-alphanumeric-characters-always-lead-with-alphabetic-characters.rb
Created Sep 14, 2021
Ruby SecureRandom fake string of alphanumeric characters; always lead with alphabetic characters.
View ruby-securerandom-fake-string-of-alphanumeric-characters-always-lead-with-alphabetic-characters.rb
#
# "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
@awesome
awesome / ERB-h_html--j_json--t_textile--u_url.rb
Created Dec 4, 2020
2020 ERB escape and text-transformation
View ERB-h_html--j_json--t_textile--u_url.rb
##
# 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