Generate a Safari style random password with ruby.
I like the passwords that the new versions of safari provide. One problem however, is not all sites allow it. Really? That’s annoying. I decided to create a simple ruby script that I can run from the cli (since I basically live on the cli anyway). It would also allow me to use this type of password for other things (database passwords for use with rails, etc..). I took a quick and dirty approach at first:
That works, but I don’t know, there is probably a nicer looking solution.
…better. Am I able to fit it within the viewable area of a Mou code block(96 characters wide)?
…why, yes I am. Am I able to get it down to one line?
…yes, but not without breaking the 96 character width limitation. Another approach perhaps?
…that works for me! I enjoyed this little exercise. It wasn’t a test driven approach, it was more like code golf and had me think about things slightly differently each time.
Can you do better?
How I use it
Shameless plug warning!
I have my development environment setup a certain way. Since I work on different *nix machines, I needed a way to replicate it quick and easy. I am actually in the process of creating a ruby cli application. Its pretty bare right now, but I plan on creating a good readme, documentation, and more functionality soon. Check it out and give me some feedback.
Basically I make the script, which in my case lives in ~/developer/private/ruby
executable.
Add a shebang #!
line to the top of the file:
and chmod it:
next I symlink the executable to somewhere in my path and shorten it:
lastly, since I don’t want to have to copy from the terminal just to paste it where I need to use it I alias it to:
Now I simply run safari-pass
and the password is copied to my clipboard. I should I am on a Mac, to do this on linux you can probably just do:
…and I only say probably since I have not yet actually tried it myself.