Skip to content

Instantly share code, notes, and snippets.

View awesome's full-sized avatar

So Awesome Man awesome

View GitHub Profile
@awesome
awesome / gsub-string-parse-number-with-comma-and-decimal.rb
Created December 5, 2022 23:52
gsub-string-parse-number-with-comma-and-decimal.rb
str = "Czech Republic,CZK,139,000.00"
str.gsub(/[^\d\.,]/, '').gsub(/^,+/,'')
# => "139,000.00"
@awesome
awesome / guide: use puma-dev as proxy.md
Created October 26, 2022 18:32 — forked from rcugut/guide: use puma-dev as proxy.md
guide: use puma-dev as proxy
# 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:
#
@awesome
awesome / gist:b592620313d4ff8712800b40d1e1511b
Created September 15, 2022 19:17 — forked from tayvano/gist:6e2d456a9897f55025e25035478a3a50
complete list of ffmpeg flags / commands
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 September 5, 2022 14:14
UUID pure regexp and dash/hyphen is optional; return only full uuid matched
# 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 June 28, 2022 22:58
ruby-hash-with-or-without-rockets-to-javascript-object-notation-aka-json-style.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 June 21, 2022 22:17
format ticket title to git branch name
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 / jq-json-to-associative-array-command-line-example.txt
Created August 22, 2018 20:10
jq parse JSON to bash4 associative array! "jq is like sed for JSON data" https://stedolan.github.io/jq/
admin@ip-172-31-90-86:~$ json=$(
cat <<- EOF
{
"foo": "baru-1",
"su": "baru-2",
"dive": "baru-3"
}
EOF
)
admin@ip-172-31-90-86:~$ echo $json
@awesome
awesome / pad-an-array-to-be-a-certain-size.rb
Created December 17, 2021 23:55
Pad An Array To Be A Certain Size in Ruby
# 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 December 9, 2021 19:49
Ruby: URL-to-Hash & Query-to-Hash
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