Skip to content

Instantly share code, notes, and snippets.

@drosenstark
Created May 8, 2016 15:48
Show Gist options
  • Save drosenstark/245a4d4e545ce96969a57dee9cef6d52 to your computer and use it in GitHub Desktop.
Save drosenstark/245a4d4e545ce96969a57dee9cef6d52 to your computer and use it in GitHub Desktop.
Unique ID to Clipboard for Workflowy (or whatever), OSX
#!/usr/bin/env ruby
# uiqueid generates a 4 character unique ID and puts it in the clipboard
# configurable variables
prefix = "WF-"
totalChars = 4
startPoint = 97 # use 65 for upper, 97 for lower
def pbcopy(input)
str = input.to_s
IO.popen('pbcopy', 'w') { |f| f << str }
str
end
def pbpaste
`pbpaste`
end
if __FILE__ == $0
thing = (0...totalChars).map { (startPoint + rand(26)).chr }.join
pbcopy "#{prefix}#{thing}"
end
@drosenstark
Copy link
Author

This is pseudo-unique. Chances of collision are 26totalChars, so in this example it's 1 in 456,976.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment