Created
December 16, 2014 09:09
-
-
Save lajlev/dc8108326069276497fe to your computer and use it in GitHub Desktop.
How do I capitalize the words?
This file contains hidden or 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
#!/usr/bin/ruby | |
tmp = "{query}" | |
# If there was a query, then parse the query | |
unless tmp.nil? || tmp == 0 | |
args = tmp.split | |
num = args.at(0) | |
char_limit = args.at(1) | |
else | |
# There was no query, so set the defaults | |
num = 4 | |
char_limit = 30 | |
end | |
if num.nil? || num == 0 | |
# Check to make sure num is set, otherwise set default | |
num = 4 | |
end | |
if char_limit.nil? || char_limit == 0 | |
# Check to make sure char_limit is set, otherwise set default | |
char_limit = 30 | |
end | |
# Make sure that num is an integer; if not or if 0, then set to default | |
if num.is_a? String | |
num = num.strip.to_i | |
if num.is_a? Integer | |
if num == 0 | |
num = 4 | |
end | |
end | |
end | |
# Make sure that char_limit is an integer; if not or if 0, then set to default | |
if char_limit.is_a? String | |
char_limit = char_limit.strip.to_i | |
if char_limit.is_a? Integer | |
if char_limit == 0 | |
char_limit = 30 | |
end | |
end | |
end | |
# We have the wordlist in a file, so open and read into an array | |
passphrase_wordlist = Array.new | |
File.open("passphrase_wordlist", "r").each_line do |line| | |
passphrase_wordlist.push(line.strip) | |
end | |
items = [] | |
num.times do | |
begin loc = rand(passphrase_wordlist.length) end while items.include?(loc) | |
items << loc | |
end | |
words = items.collect {|loc| passphrase_wordlist[loc]}.join(' ') | |
size = 0 | |
text = words.split().reject do |token| | |
size+=token.size() | |
size>char_limit | |
end.join("") | |
# Cut off the last word if it's over the char limit | |
text = text[0...text.rindex(' ')] if text.size > char_limit | |
printf(text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is this? And which words?