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
# Ruby opposite of array intersection... or maybe the method is missing from my brain bc not enough coffee | |
# http://twitter.com/soawesomeman/status/8035087261 | |
def awesome(ar_1, ar_2) | |
(ar_1 + ar_2) - (ar_1 & ar_2) | |
end | |
awesome([1,2,3,4], [3,4,5,6]) # => [1, 2, 5, 6] | |
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"], [], []]] |
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
$ brew install bash-completion | |
==> Downloading http://bash-completion.alioth.debian.org/files/bash-completion-1.3.tar.bz2 | |
######################################################################## 100.0% | |
==> ./configure --prefix=/usr/local/Cellar/bash-completion/1.3 | |
==> make install | |
==> Caveats | |
Add the following lines to your ~/.bash_profile file: | |
if [ -f `brew --prefix`/etc/bash_completion ]; then | |
. `brew --prefix`/etc/bash_completion | |
fi |
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
Dpkg: check that unix package is installed. Bash script: install package if not present | |
By neokrates, written on May 21, 2010 | |
Was the package already installed or it still needs to be? | |
Software: | |
✔ Ubuntu * | |
dpkg -s can be used. |
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
def format_join(string, joiner=' ') | |
string.split(/\W/).reject(&:empty?).join(joiner.to_s) | |
end | |
# $ ruby -v | |
# ruby 2.1.9p490 (2016-03-30 revision 54437) [x86_64-darwin18.0] | |
# | |
# $ irb | |
# irb(main):001:0> def format_join(string, joiner=' ') | |
# irb(main):002:1> string.split(/\W/).reject(&:empty?).join(joiner.to_s) |
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 -v | |
# ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18] | |
# $ pwd | |
# /Users/dev/Documents/Github/Gists/awesome/ | |
# $ echo "puts File.expand_path(__FILE__)" > how-to-get-the-name-of-the-current-file-with-directory-filepath-using-ruby.rb | |
# $ echo "puts File.absolute_path(__FILE__)" >> how-to-get-the-name-of-the-current-file-with-directory-filepath-using-ruby.rb | |
# $ cat how-to-get-the-name-of-the-current-file-with-directory-filepath.rb | |
# puts File.expand_path(__FILE__) | |
# puts File.absolute_path(__FILE__) | |
# $ ruby how-to-get-the-name-of-the-current-file-with-directory-filepath-using-ruby.rb |