Skip to content

Instantly share code, notes, and snippets.

@daniel-g
Created December 6, 2010 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save daniel-g/730671 to your computer and use it in GitHub Desktop.
Save daniel-g/730671 to your computer and use it in GitHub Desktop.
Common tasks in my linux
class Common < Thor
desc "passgen [LENGTH]", "generates passwords with a given length (defaults to 8)"
method_options :numeric => :boolean, :downcase => :boolean, :upcase => :boolean, :alphanumeric => :boolean
def passgen(len = 8)
chars = []
if (options.empty?)
chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
else
if options[:alphanumeric]
chars += ("a".."z").to_a + ("A".."Z").to_a
else
chars += ("a".."z").to_a if options[:downcase]
chars += ("A".."Z").to_a if options[:upcase]
end
chars += ("0".."9").to_a if options[:numeric]
end
newpass = ""
1.upto(len.to_i) { |i| newpass << chars[rand(chars.size-1)] }
puts newpass
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment