UUIDGenerator

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

UUIDGenerator

horrido
Is there even one shred of documentation anywhere that shows how to use UUIDGenerator? A thorough Google search reveals nothing! All I find are reference materials. I'd like to see just one working code sample, no matter how simple.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: UUIDGenerator

Holger Freyther

> On 17. Jun 2017, at 20:51, horrido <[hidden email]> wrote:


Hey!


>
> Is there even one shred of documentation anywhere that shows how to use
> UUIDGenerator? A thorough Google search reveals nothing! All I find are
> reference materials. I'd like to see just one working code sample, no matter
> how simple.

in these cases I use "Analyze->Class refs" on the class and it brings up the test case for the UUIDGenerator. Have a look at the >>#setUp and then the tests?

have a nice weekend

        holger
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: UUIDGenerator

Sven Van Caekenberghe-2
In reply to this post by horrido

> On 17 Jun 2017, at 14:51, horrido <[hidden email]> wrote:
>
> Is there even one shred of documentation anywhere that shows how to use
> UUIDGenerator? A thorough Google search reveals nothing! All I find are
> reference materials. I'd like to see just one working code sample, no matter
> how simple.

Apart from the fact that it is a very simple class to use, what is wrong with the class comment ?

============

I am UUIDGenerator, I generate UUIDs.

An RFC4122 Universally Unique Identifier (UUID) is an opaque 128-bit number that can be used for identification purposes. Concretely, a UUID is a 16 element byte array.

The intent of UUIDs is to enable distributed systems to uniquely identify information without significant central coordination. In this context the word unique should be taken to mean "practically unique" rather than "guaranteed unique".
 
I generate UUIDs similar, in spirit, to those defined in RFC4122, though I use version 0 to indicate that I follow none of the defined versions. This does not matter much, if at all, in practice.

I try to conform to the following aspects:
 - each 'node' (machine, image, instance) should generate unique UUIDs
 - even when generating UUIDs at a very fast rate, they should remain unique
 - be fast and efficient

To achieve this goal, I
- take several aspects into account to generate a unique node ID
- combine a clock, a counter and some random bits
- hold a state, protected for multi user access

I can generate about 500K UUIDs per second.

Implementation:

Although a UUID should be seen as totally opaque, here is the concrete way I generate one:
- the first 8 bytes are the microsecond clock value with the smallest quantity first; this means that the later of these 8 bytes will be identical when generated with small(er) timespans; within the same clock resolution interval, the full first 8 bytes will be identical
- the next 2 bytes represent a counter with safe overflow, held as protected state inside me; after 2*16 this value will repeat; the counter initalizes with a random value
- the next 2 bytes are simply random, based on the system PRNG, Random
- the final 4 bytes represent the node ID; the node ID is unique per instance of me, across OS environments where the image might run; the node ID is the MD5 hash of a string that is the concatenation of several elements (see #computeNodeIdentifier)
 
Some bits are set to some predefined value, to indicate the variant and version (see #setVariantAndVersion:)

Usage:

  UUIDGenerator next.
  UUIDGenerator current next.
  UUIDGenerator new next.

Sharing an instance is more efficient and correct.
Instances should be reset whenever the image comes up.

See also:

  http://en.wikipedia.org/wiki/UUID
  https://tools.ietf.org/html/rfc4122

=====

Furthermore, all public methods are commented.

Or do you have some specific question ?

Sven


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: UUIDGenerator

horrido
In reply to this post by horrido
Okay, I figured it out. Here's my method:

generateUUID
    | aStream hex s x |
    hex := '0123456789ABCDEF'.
    x := ByteArray new: 16.
    UUIDGenerator default generateBytes: x forVersion: 4.
    s := String new: 32.
    aStream := WriteStream on: s.
    x do: [ :each | aStream nextPut: (hex at: each // 16 + 1).
        aStream nextPut: (hex at: each \\ 16 + 1) ].
    ^ s

Works like a charm. It would've been nice if a similar example was available somewhere on the web.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: UUIDGenerator

Sven Van Caekenberghe-2
Why not just

  UUIDGenerator default next hex asUppercase.

Or even

  UUID new hex asUppercase.

?

Since you are using #generateBytes:forVersion: (which is an internal method BTW), you must be working in an older Pharo image (older than 6). We replaced the UUIDGenerator class, the class comment in from the newer version.

> On 17 Jun 2017, at 16:27, horrido <[hidden email]> wrote:
>
> Okay, I figured it out. Here's my method:
>
> generateUUID
>    | aStream hex s x |
>    hex := '0123456789ABCDEF'.
>    x := ByteArray new: 16.
>    UUIDGenerator default generateBytes: x forVersion: 4.
>    s := String new: 32.
>    aStream := WriteStream on: s.
>    x do: [ :each | aStream nextPut: (hex at: each // 16 + 1).
>        aStream nextPut: (hex at: each \\ 16 + 1) ].
>    ^ s
>
> Works like a charm. It would've been nice if a similar example was available
> /somewhere/ on the web.
>
>
>
> --
> View this message in context: http://forum.world.st/UUIDGenerator-tp4951725p4951731.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: UUIDGenerator

horrido
Message 'next' is not understood.

But yes,

UUID new hex asUppercase

works fine.

This is what happens when there is inadequate documentation: you end up doing things the hard way.

Thanks.


Sven Van Caekenberghe-2 wrote
Why not just

  UUIDGenerator default next hex asUppercase.

Or even

  UUID new hex asUppercase.

?

Since you are using #generateBytes:forVersion: (which is an internal method BTW), you must be working in an older Pharo image (older than 6). We replaced the UUIDGenerator class, the class comment in from the newer version.

> On 17 Jun 2017, at 16:27, horrido <[hidden email]> wrote:
>
> Okay, I figured it out. Here's my method:
>
> generateUUID
>    | aStream hex s x |
>    hex := '0123456789ABCDEF'.
>    x := ByteArray new: 16.
>    UUIDGenerator default generateBytes: x forVersion: 4.
>    s := String new: 32.
>    aStream := WriteStream on: s.
>    x do: [ :each | aStream nextPut: (hex at: each // 16 + 1).
>        aStream nextPut: (hex at: each \\ 16 + 1) ].
>    ^ s
>
> Works like a charm. It would've been nice if a similar example was available
> /somewhere/ on the web.
>
>
>
> --
> View this message in context: http://forum.world.st/UUIDGenerator-tp4951725p4951731.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: UUIDGenerator

Sven Van Caekenberghe-2

> On 17 Jun 2017, at 21:23, horrido <[hidden email]> wrote:
>
> Message 'next' is not understood.
>
> But yes,
>
> UUID new hex asUppercase
>
> works fine.
>
> This is what happens when there is inadequate documentation: you end up
> doing things the *hard* way.
>
> Thanks.

You are working in an older version, with less documentation.

> Sven Van Caekenberghe-2 wrote
>> Why not just
>>
>>  UUIDGenerator default next hex asUppercase.
>>
>> Or even
>>
>>  UUID new hex asUppercase.
>>
>> ?
>>
>> Since you are using #generateBytes:forVersion: (which is an internal
>> method BTW), you must be working in an older Pharo image (older than 6).
>> We replaced the UUIDGenerator class, the class comment in from the newer
>> version.
>>
>>> On 17 Jun 2017, at 16:27, horrido &lt;
>
>> horrido.hobbies@
>
>> &gt; wrote:
>>>
>>> Okay, I figured it out. Here's my method:
>>>
>>> generateUUID
>>>   | aStream hex s x |
>>>   hex := '0123456789ABCDEF'.
>>>   x := ByteArray new: 16.
>>>   UUIDGenerator default generateBytes: x forVersion: 4.
>>>   s := String new: 32.
>>>   aStream := WriteStream on: s.
>>>   x do: [ :each | aStream nextPut: (hex at: each // 16 + 1).
>>>       aStream nextPut: (hex at: each \\ 16 + 1) ].
>>>   ^ s
>>>
>>> Works like a charm. It would've been nice if a similar example was
>>> available
>>> /somewhere/ on the web.
>>>
>>>
>>>
>>> --
>>> View this message in context:
>>> http://forum.world.st/UUIDGenerator-tp4951725p4951731.html
>>> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>>>
>
>
>
>
>
> --
> View this message in context: http://forum.world.st/UUIDGenerator-tp4951725p4951743.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: UUIDGenerator

philippeback
In reply to this post by horrido
Spotting for hex is hardly complex.

Shift-Enter hex #im

--> implementors of hex, first one I see is in ByteArray.

Shit-Enter hex #se

--> senders of hex. First one is a test in ByteArray

testHex
"self debug: #testHex"
self assert: #[122 43 213 7] hex = '7a2bd507'.
self assert: #[151 193 242 221 249 32 153 72 179 41 49 154 48 193 99 134] hex = '97c1f2ddf9209948b329319a30c16386'.
self assert: (ByteArray readHexFrom: '7A2BD507') = #[122 43 213 7].
self assert: (ByteArray readHexFrom: '7a2bd507') = #[122 43 213 7].

From this test, one can spot readHexFrom: which uses lowercase or uppercase for reading.

And asUppercase, Shift-Enter upper, scrolll down as bit, find String>>#asUppercase

Spotter is really great at finding stuff, and coupled with tests and examples it helps in building understanding.

Agreed, this is not the same as looking for stuff as in, say, Java or Python. I find it better in the long run still.

Phil

On Sat, Jun 17, 2017 at 9:23 PM, horrido <[hidden email]> wrote:
Message 'next' is not understood.

But yes,

UUID new hex asUppercase

works fine.

This is what happens when there is inadequate documentation: you end up
doing things the *hard* way.

Thanks.



Sven Van Caekenberghe-2 wrote
> Why not just
>
>   UUIDGenerator default next hex asUppercase.
>
> Or even
>
>   UUID new hex asUppercase.
>
> ?
>
> Since you are using #generateBytes:forVersion: (which is an internal
> method BTW), you must be working in an older Pharo image (older than 6).
> We replaced the UUIDGenerator class, the class comment in from the newer
> version.
>
>> On 17 Jun 2017, at 16:27, horrido &lt;

> horrido.hobbies@

> &gt; wrote:
>>
>> Okay, I figured it out. Here's my method:
>>
>> generateUUID
>>    | aStream hex s x |
>>    hex := '0123456789ABCDEF'.
>>    x := ByteArray new: 16.
>>    UUIDGenerator default generateBytes: x forVersion: 4.
>>    s := String new: 32.
>>    aStream := WriteStream on: s.
>>    x do: [ :each | aStream nextPut: (hex at: each // 16 + 1).
>>        aStream nextPut: (hex at: each \\ 16 + 1) ].
>>    ^ s
>>
>> Works like a charm. It would've been nice if a similar example was
>> available
>> /somewhere/ on the web.
>>
>>
>>
>> --
>> View this message in context:
>> http://forum.world.st/UUIDGenerator-tp4951725p4951731.html
>> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>>





--
View this message in context: http://forum.world.st/UUIDGenerator-tp4951725p4951743.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: UUIDGenerator

horrido
I didn't know about the Spotter. That is so frickin' cool!!!

Thanks.

philippeback wrote
Spotting for hex is hardly complex.

Shift-Enter hex #im

--> implementors of hex, first one I see is in ByteArray.

Shit-Enter hex #se

--> senders of hex. First one is a test in ByteArray

testHex
"self debug: #testHex"
self assert: #[122 43 213 7] hex = '7a2bd507'.
self assert: #[151 193 242 221 249 32 153 72 179 41 49 154 48 193 99 134]
hex = '97c1f2ddf9209948b329319a30c16386'.
self assert: (ByteArray readHexFrom: '7A2BD507') = #[122 43 213 7].
self assert: (ByteArray readHexFrom: '7a2bd507') = #[122 43 213 7].

From this test, one can spot readHexFrom: which uses lowercase or uppercase
for reading.

And asUppercase, Shift-Enter upper, scrolll down as bit, find
String>>#asUppercase

Spotter is really great at finding stuff, and coupled with tests and
examples it helps in building understanding.

Agreed, this is not the same as looking for stuff as in, say, Java or
Python. I find it better in the long run still.

Phil

On Sat, Jun 17, 2017 at 9:23 PM, horrido <[hidden email]> wrote:

> Message 'next' is not understood.
>
> But yes,
>
> UUID new hex asUppercase
>
> works fine.
>
> This is what happens when there is inadequate documentation: you end up
> doing things the *hard* way.
>
> Thanks.
>
>
>
> Sven Van Caekenberghe-2 wrote
> > Why not just
> >
> >   UUIDGenerator default next hex asUppercase.
> >
> > Or even
> >
> >   UUID new hex asUppercase.
> >
> > ?
> >
> > Since you are using #generateBytes:forVersion: (which is an internal
> > method BTW), you must be working in an older Pharo image (older than 6).
> > We replaced the UUIDGenerator class, the class comment in from the newer
> > version.
> >
> >> On 17 Jun 2017, at 16:27, horrido <
>
> > horrido.hobbies@
>
> > > wrote:
> >>
> >> Okay, I figured it out. Here's my method:
> >>
> >> generateUUID
> >>    | aStream hex s x |
> >>    hex := '0123456789ABCDEF'.
> >>    x := ByteArray new: 16.
> >>    UUIDGenerator default generateBytes: x forVersion: 4.
> >>    s := String new: 32.
> >>    aStream := WriteStream on: s.
> >>    x do: [ :each | aStream nextPut: (hex at: each // 16 + 1).
> >>        aStream nextPut: (hex at: each \\ 16 + 1) ].
> >>    ^ s
> >>
> >> Works like a charm. It would've been nice if a similar example was
> >> available
> >> /somewhere/ on the web.
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >> http://forum.world.st/UUIDGenerator-tp4951725p4951731.html
> >> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
> >>
>
>
>
>
>
> --
> View this message in context: http://forum.world.st/UUIDGenerator-
> tp4951725p4951743.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: UUIDGenerator

Tim Mackinnon
It is in the Pharo help - however I have noticed that Help doesn’t have a convenient search box and the new Welcome screen that launches with Pharo possibly should have a shortcut to useful navigational features…. Sounds like something I can contributed.

Tim

On 19 Jun 2017, at 00:39, horrido <[hidden email]> wrote:

I didn't know about the Spotter. That is so frickin' cool!!!

Thanks.


philippeback wrote
Spotting for hex is hardly complex.

Shift-Enter hex #im

--> implementors of hex, first one I see is in ByteArray.

Shit-Enter hex #se

--> senders of hex. First one is a test in ByteArray

testHex
"self debug: #testHex"
self assert: #[122 43 213 7] hex = '7a2bd507'.
self assert: #[151 193 242 221 249 32 153 72 179 41 49 154 48 193 99 134]
hex = '97c1f2ddf9209948b329319a30c16386'.
self assert: (ByteArray readHexFrom: '7A2BD507') = #[122 43 213 7].
self assert: (ByteArray readHexFrom: '7a2bd507') = #[122 43 213 7].

From this test, one can spot readHexFrom: which uses lowercase or
uppercase
for reading.

And asUppercase, Shift-Enter upper, scrolll down as bit, find
String>>#asUppercase

Spotter is really great at finding stuff, and coupled with tests and
examples it helps in building understanding.

Agreed, this is not the same as looking for stuff as in, say, Java or
Python. I find it better in the long run still.

Phil

On Sat, Jun 17, 2017 at 9:23 PM, horrido &lt;

horrido.hobbies@

&gt; wrote:

Message 'next' is not understood.

But yes,

UUID new hex asUppercase

works fine.

This is what happens when there is inadequate documentation: you end up
doing things the *hard* way.

Thanks.



Sven Van Caekenberghe-2 wrote
Why not just

 UUIDGenerator default next hex asUppercase.

Or even

 UUID new hex asUppercase.

?

Since you are using #generateBytes:forVersion: (which is an internal
method BTW), you must be working in an older Pharo image (older than
6).
We replaced the UUIDGenerator class, the class comment in from the
newer
version.

On 17 Jun 2017, at 16:27, horrido &lt;

horrido.hobbies@

&gt; wrote:

Okay, I figured it out. Here's my method:

generateUUID
  | aStream hex s x |
  hex := '0123456789ABCDEF'.
  x := ByteArray new: 16.
  UUIDGenerator default generateBytes: x forVersion: 4.
  s := String new: 32.
  aStream := WriteStream on: s.
  x do: [ :each | aStream nextPut: (hex at: each // 16 + 1).
      aStream nextPut: (hex at: each \\ 16 + 1) ].
  ^ s

Works like a charm. It would've been nice if a similar example was
available
/somewhere/ on the web.



--
View this message in context:
http://forum.world.st/UUIDGenerator-tp4951725p4951731.html
Sent from the Pharo Smalltalk Users mailing list archive at
Nabble.com.






--
View this message in context: http://forum.world.st/UUIDGenerator-
tp4951725p4951743.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.








--
View this message in context: http://forum.world.st/UUIDGenerator-tp4951725p4951844.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: UUIDGenerator

philippeback
That being said, maybe one can do a spotter extension that looks into the help topics. 

I did one with windows (should be in Pharo7).

So one would ho to spotter and put a word followed by #help or #he

Maybe this is in already!
Phil

On Mon, Jun 19, 2017 at 10:43 AM, Tim Mackinnon <[hidden email]> wrote:
It is in the Pharo help - however I have noticed that Help doesn’t have a convenient search box and the new Welcome screen that launches with Pharo possibly should have a shortcut to useful navigational features…. Sounds like something I can contributed.

Tim

On 19 Jun 2017, at 00:39, horrido <[hidden email]> wrote:

I didn't know about the Spotter. That is so frickin' cool!!!

Thanks.


philippeback wrote
Spotting for hex is hardly complex.

Shift-Enter hex #im

--> implementors of hex, first one I see is in ByteArray.

Shit-Enter hex #se

--> senders of hex. First one is a test in ByteArray

testHex
"self debug: #testHex"
self assert: #[122 43 213 7] hex = '7a2bd507'.
self assert: #[151 193 242 221 249 32 153 72 179 41 49 154 48 193 99 134]
hex = '97c1f2ddf9209948b329319a30c16386'.
self assert: (ByteArray readHexFrom: '7A2BD507') = #[122 43 213 7].
self assert: (ByteArray readHexFrom: '7a2bd507') = #[122 43 213 7].

From this test, one can spot readHexFrom: which uses lowercase or
uppercase
for reading.

And asUppercase, Shift-Enter upper, scrolll down as bit, find
String>>#asUppercase

Spotter is really great at finding stuff, and coupled with tests and
examples it helps in building understanding.

Agreed, this is not the same as looking for stuff as in, say, Java or
Python. I find it better in the long run still.

Phil

On Sat, Jun 17, 2017 at 9:23 PM, horrido &lt;

horrido.hobbies@

&gt; wrote:

Message 'next' is not understood.

But yes,

UUID new hex asUppercase

works fine.

This is what happens when there is inadequate documentation: you end up
doing things the *hard* way.

Thanks.



Sven Van Caekenberghe-2 wrote
Why not just

 UUIDGenerator default next hex asUppercase.

Or even

 UUID new hex asUppercase.

?

Since you are using #generateBytes:forVersion: (which is an internal
method BTW), you must be working in an older Pharo image (older than
6).
We replaced the UUIDGenerator class, the class comment in from the
newer
version.

On 17 Jun 2017, at 16:27, horrido &lt;

horrido.hobbies@

&gt; wrote:

Okay, I figured it out. Here's my method:

generateUUID
  | aStream hex s x |
  hex := '0123456789ABCDEF'.
  x := ByteArray new: 16.
  UUIDGenerator default generateBytes: x forVersion: 4.
  s := String new: 32.
  aStream := WriteStream on: s.
  x do: [ :each | aStream nextPut: (hex at: each // 16 + 1).
      aStream nextPut: (hex at: each \\ 16 + 1) ].
  ^ s

Works like a charm. It would've been nice if a similar example was
available
/somewhere/ on the web.



--
View this message in context:
http://forum.world.st/UUIDGenerator-tp4951725p4951731.html
Sent from the Pharo Smalltalk Users mailing list archive at
Nabble.com.






--
View this message in context: http://forum.world.st/UUIDGenerator-
tp4951725p4951743.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.








--
View this message in context: http://forum.world.st/UUIDGenerator-tp4951725p4951844.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: UUIDGenerator

Tim Mackinnon
Damnit your right…. #help keyboard gives you the business… nice

I think the prompt to use Spotter should be in the welcome text though, as its a bit hidden - maybe is should be in the “Explore” section.

Tim


On 19 Jun 2017, at 11:30, [hidden email] wrote:

That being said, maybe one can do a spotter extension that looks into the help topics. 

I did one with windows (should be in Pharo7).

So one would ho to spotter and put a word followed by #help or #he

Maybe this is in already!
Phil

On Mon, Jun 19, 2017 at 10:43 AM, Tim Mackinnon <[hidden email]> wrote:
It is in the Pharo help - however I have noticed that Help doesn’t have a convenient search box and the new Welcome screen that launches with Pharo possibly should have a shortcut to useful navigational features…. Sounds like something I can contributed.

Tim

On 19 Jun 2017, at 00:39, horrido <[hidden email]> wrote:

I didn't know about the Spotter. That is so frickin' cool!!!

Thanks.


philippeback wrote
Spotting for hex is hardly complex.

Shift-Enter hex #im

--> implementors of hex, first one I see is in ByteArray.

Shit-Enter hex #se

--> senders of hex. First one is a test in ByteArray

testHex
"self debug: #testHex"
self assert: #[122 43 213 7] hex = '7a2bd507'.
self assert: #[151 193 242 221 249 32 153 72 179 41 49 154 48 193 99 134]
hex = '97c1f2ddf9209948b329319a30c16386'.
self assert: (ByteArray readHexFrom: '7A2BD507') = #[122 43 213 7].
self assert: (ByteArray readHexFrom: '7a2bd507') = #[122 43 213 7].

From this test, one can spot readHexFrom: which uses lowercase or
uppercase
for reading.

And asUppercase, Shift-Enter upper, scrolll down as bit, find
String>>#asUppercase

Spotter is really great at finding stuff, and coupled with tests and
examples it helps in building understanding.

Agreed, this is not the same as looking for stuff as in, say, Java or
Python. I find it better in the long run still.

Phil

On Sat, Jun 17, 2017 at 9:23 PM, horrido &lt;

horrido.hobbies@

&gt; wrote:

Message 'next' is not understood.

But yes,

UUID new hex asUppercase

works fine.

This is what happens when there is inadequate documentation: you end up
doing things the *hard* way.

Thanks.



Sven Van Caekenberghe-2 wrote
Why not just

 UUIDGenerator default next hex asUppercase.

Or even

 UUID new hex asUppercase.

?

Since you are using #generateBytes:forVersion: (which is an internal
method BTW), you must be working in an older Pharo image (older than
6).
We replaced the UUIDGenerator class, the class comment in from the
newer
version.

On 17 Jun 2017, at 16:27, horrido &lt;

horrido.hobbies@

&gt; wrote:

Okay, I figured it out. Here's my method:

generateUUID
  | aStream hex s x |
  hex := '0123456789ABCDEF'.
  x := ByteArray new: 16.
  UUIDGenerator default generateBytes: x forVersion: 4.
  s := String new: 32.
  aStream := WriteStream on: s.
  x do: [ :each | aStream nextPut: (hex at: each // 16 + 1).
      aStream nextPut: (hex at: each \\ 16 + 1) ].
  ^ s

Works like a charm. It would've been nice if a similar example was
available
/somewhere/ on the web.



--
View this message in context:
http://forum.world.st/UUIDGenerator-tp4951725p4951731.html
Sent from the Pharo Smalltalk Users mailing list archive at
Nabble.com.






--
View this message in context: http://forum.world.st/UUIDGenerator-
tp4951725p4951743.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.








--
View this message in context: http://forum.world.st/UUIDGenerator-tp4951725p4951844.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: UUIDGenerator

philippeback
Spotter rulez :-)

On Mon, Jun 19, 2017 at 6:02 PM, Tim Mackinnon <[hidden email]> wrote:
Damnit your right…. #help keyboard gives you the business… nice

I think the prompt to use Spotter should be in the welcome text though, as its a bit hidden - maybe is should be in the “Explore” section.

Tim


On 19 Jun 2017, at 11:30, [hidden email] wrote:

That being said, maybe one can do a spotter extension that looks into the help topics. 

I did one with windows (should be in Pharo7).

So one would ho to spotter and put a word followed by #help or #he

Maybe this is in already!
Phil

On Mon, Jun 19, 2017 at 10:43 AM, Tim Mackinnon <[hidden email]> wrote:
It is in the Pharo help - however I have noticed that Help doesn’t have a convenient search box and the new Welcome screen that launches with Pharo possibly should have a shortcut to useful navigational features…. Sounds like something I can contributed.

Tim

On 19 Jun 2017, at 00:39, horrido <[hidden email]> wrote:

I didn't know about the Spotter. That is so frickin' cool!!!

Thanks.


philippeback wrote
Spotting for hex is hardly complex.

Shift-Enter hex #im

--> implementors of hex, first one I see is in ByteArray.

Shit-Enter hex #se

--> senders of hex. First one is a test in ByteArray

testHex
"self debug: #testHex"
self assert: #[122 43 213 7] hex = '7a2bd507'.
self assert: #[151 193 242 221 249 32 153 72 179 41 49 154 48 193 99 134]
hex = '97c1f2ddf9209948b329319a30c16386'.
self assert: (ByteArray readHexFrom: '7A2BD507') = #[122 43 213 7].
self assert: (ByteArray readHexFrom: '7a2bd507') = #[122 43 213 7].

From this test, one can spot readHexFrom: which uses lowercase or
uppercase
for reading.

And asUppercase, Shift-Enter upper, scrolll down as bit, find
String>>#asUppercase

Spotter is really great at finding stuff, and coupled with tests and
examples it helps in building understanding.

Agreed, this is not the same as looking for stuff as in, say, Java or
Python. I find it better in the long run still.

Phil

On Sat, Jun 17, 2017 at 9:23 PM, horrido &lt;

horrido.hobbies@

&gt; wrote:

Message 'next' is not understood.

But yes,

UUID new hex asUppercase

works fine.

This is what happens when there is inadequate documentation: you end up
doing things the *hard* way.

Thanks.



Sven Van Caekenberghe-2 wrote
Why not just

 UUIDGenerator default next hex asUppercase.

Or even

 UUID new hex asUppercase.

?

Since you are using #generateBytes:forVersion: (which is an internal
method BTW), you must be working in an older Pharo image (older than
6).
We replaced the UUIDGenerator class, the class comment in from the
newer
version.

On 17 Jun 2017, at 16:27, horrido &lt;

horrido.hobbies@

&gt; wrote:

Okay, I figured it out. Here's my method:

generateUUID
  | aStream hex s x |
  hex := '0123456789ABCDEF'.
  x := ByteArray new: 16.
  UUIDGenerator default generateBytes: x forVersion: 4.
  s := String new: 32.
  aStream := WriteStream on: s.
  x do: [ :each | aStream nextPut: (hex at: each // 16 + 1).
      aStream nextPut: (hex at: each \\ 16 + 1) ].
  ^ s

Works like a charm. It would've been nice if a similar example was
available
/somewhere/ on the web.



--
View this message in context:
http://forum.world.st/UUIDGenerator-tp4951725p4951731.html
Sent from the Pharo Smalltalk Users mailing list archive at
Nabble.com.






--
View this message in context: http://forum.world.st/UUIDGenerator-
tp4951725p4951743.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.








--
View this message in context: http://forum.world.st/UUIDGenerator-tp4951725p4951844.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: UUIDGenerator

Stephane Ducasse-3
In reply to this post by horrido
May be you should have a look at the Pharo mooc.
Because we spent 8 months producing videos.
This is free and in two days you can cherry pick what you want.
Students like it a lot.

Stef

On Mon, Jun 19, 2017 at 1:39 AM, horrido <[hidden email]> wrote:

> I didn't know about the Spotter. That is so frickin' cool!!!
>
> Thanks.
>
>
> philippeback wrote
>> Spotting for hex is hardly complex.
>>
>> Shift-Enter hex #im
>>
>> --> implementors of hex, first one I see is in ByteArray.
>>
>> Shit-Enter hex #se
>>
>> --> senders of hex. First one is a test in ByteArray
>>
>> testHex
>> "self debug: #testHex"
>> self assert: #[122 43 213 7] hex = '7a2bd507'.
>> self assert: #[151 193 242 221 249 32 153 72 179 41 49 154 48 193 99 134]
>> hex = '97c1f2ddf9209948b329319a30c16386'.
>> self assert: (ByteArray readHexFrom: '7A2BD507') = #[122 43 213 7].
>> self assert: (ByteArray readHexFrom: '7a2bd507') = #[122 43 213 7].
>>
>> From this test, one can spot readHexFrom: which uses lowercase or
>> uppercase
>> for reading.
>>
>> And asUppercase, Shift-Enter upper, scrolll down as bit, find
>> String>>#asUppercase
>>
>> Spotter is really great at finding stuff, and coupled with tests and
>> examples it helps in building understanding.
>>
>> Agreed, this is not the same as looking for stuff as in, say, Java or
>> Python. I find it better in the long run still.
>>
>> Phil
>>
>> On Sat, Jun 17, 2017 at 9:23 PM, horrido &lt;
>
>> horrido.hobbies@
>
>> &gt; wrote:
>>
>>> Message 'next' is not understood.
>>>
>>> But yes,
>>>
>>> UUID new hex asUppercase
>>>
>>> works fine.
>>>
>>> This is what happens when there is inadequate documentation: you end up
>>> doing things the *hard* way.
>>>
>>> Thanks.
>>>
>>>
>>>
>>> Sven Van Caekenberghe-2 wrote
>>> > Why not just
>>> >
>>> >   UUIDGenerator default next hex asUppercase.
>>> >
>>> > Or even
>>> >
>>> >   UUID new hex asUppercase.
>>> >
>>> > ?
>>> >
>>> > Since you are using #generateBytes:forVersion: (which is an internal
>>> > method BTW), you must be working in an older Pharo image (older than
>>> 6).
>>> > We replaced the UUIDGenerator class, the class comment in from the
>>> newer
>>> > version.
>>> >
>>> >> On 17 Jun 2017, at 16:27, horrido &lt;
>>>
>>> > horrido.hobbies@
>>>
>>> > &gt; wrote:
>>> >>
>>> >> Okay, I figured it out. Here's my method:
>>> >>
>>> >> generateUUID
>>> >>    | aStream hex s x |
>>> >>    hex := '0123456789ABCDEF'.
>>> >>    x := ByteArray new: 16.
>>> >>    UUIDGenerator default generateBytes: x forVersion: 4.
>>> >>    s := String new: 32.
>>> >>    aStream := WriteStream on: s.
>>> >>    x do: [ :each | aStream nextPut: (hex at: each // 16 + 1).
>>> >>        aStream nextPut: (hex at: each \\ 16 + 1) ].
>>> >>    ^ s
>>> >>
>>> >> Works like a charm. It would've been nice if a similar example was
>>> >> available
>>> >> /somewhere/ on the web.
>>> >>
>>> >>
>>> >>
>>> >> --
>>> >> View this message in context:
>>> >> http://forum.world.st/UUIDGenerator-tp4951725p4951731.html
>>> >> Sent from the Pharo Smalltalk Users mailing list archive at
>>> Nabble.com.
>>> >>
>>>
>>>
>>>
>>>
>>>
>>> --
>>> View this message in context: http://forum.world.st/UUIDGenerator-
>>> tp4951725p4951743.html
>>> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>>>
>>>
>>>
>
>
>
>
>
> --
> View this message in context: http://forum.world.st/UUIDGenerator-tp4951725p4951844.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>

Loading...