This should work in all versions of Ruby (YMMV)
'foo.bar.baz'.each_byte.map{|x| x}.join.to_i % 64511 + 1024
Trevor
On Wed, May 18, 2016 at 7:37 PM, p wrote:
> I'm doing this instead:
> module Puppet::Parser::Functions
> newfunction(:ip_port, :type => :rvalue) do |args|
> require 'zlib'
>
I'm doing this instead:
module Puppet::Parser::Functions
newfunction(:ip_port, :type => :rvalue) do |args|
require 'zlib'
Zlib.crc32(args[0]) % 64511 + 1024
end
end
On Wednesday, May 18, 2016 at 10:16:19 AM UTC-7, p wrote:
>
> Any suggestions on how I can get the hash of the string
Any suggestions on how I can get the hash of the string content itself so I
can get this function to work? I really just don't want to manage ports
anymore.
On Wednesday, May 18, 2016 at 7:35:55 AM UTC-7, Trevor Vaughan wrote:
>
> Hi Peter,
>
> Object.hash in Ruby provides the hash of the Object
Thanks, Trevor. I did and as you had predicted they are different.
On Wednesday, May 18, 2016 at 7:35:55 AM UTC-7, Trevor Vaughan wrote:
>
> Hi Peter,
>
> Object.hash in Ruby provides the hash of the Object ID, not a consistent
> cryptographic hash of the string provided.
>
> Try it in two differ
Hi Peter,
Object.hash in Ruby provides the hash of the Object ID, not a consistent
cryptographic hash of the string provided.
Try it in two different IRB sessions and you'll see what I mean. It will
change between garbage collection runs and/or at every invocation of Puppet
if done in cron.
Trev