top | item 23536166

Show HN: Givemeguid.com – CLI/curl friendly GUIDs

32 points| deweyair | 5 years ago |givemeguid.com

46 comments

order

tkfu|5 years ago

I'm having trouble imagining who would want to use this. What's the environment where you would have curl and a need for generating UUIDs, but wouldn't have access to uuidgen or similar?

kelnos|5 years ago

Yeah, I'm just really confused. If you're at a CLI, you probably have uuidgen. And I'd assume there's something similar on Windows.

If you're writing some kind of application, pretty much every language/framework can generate UUIDs, and even if yours doesn't, just generate a 128-bit number, stamp the v4 UUID bits into it, reformat it, and you're done. Calling out to a 3rd-party service is insane for that use case anyway.

deweyair|5 years ago

Understandable! I made it for the few times I'm manually testing an API using Swagger or something similar and need a valid(ish) GUID to stand in for some field being sent to the api.

There's no shortage of ways to generate GUIDs, that's for sure!

p4bl0|5 years ago

This, and also, are GUID that pose a problem with CLI/curl really a thing?

MrGilbert|5 years ago

Maybe a JS App which is made completely out of third party APIs, without anything self-hosted? Not discussing wether this is a good idea or not, though...

I was surprised to see that there is no "built-in" mechanism in JS to generate a GUID. As a C# dev, I'm used to Guid.NewGuid()

fyfy18|5 years ago

Maybe a NPM module for generating UUIDs? /s

speedgoose|5 years ago

If you use Linux:

cat /proc/sys/kernel/random/uuid

aranw|5 years ago

This doesn't work on macOS :(

cat: /proc/sys/kernel/random/uuid: No such file or directory

raxxorrax|5 years ago

Is this just a "random" UUID or does it meet specs of RFC 4122? I have seen countless times when it was just generated as {8}-{4}-{4}-{4}-{12} with complete random numbers. Well, works for most applications...

queuep|5 years ago

This is what I use to generate guids with autohotkey: ::;guid:: guid := GUID() StringLower, guid, guid Clipboard := guid SendInput,^v return

GUID() { format = %A_FormatInteger% ; save original integer format SetFormat Integer, Hex ; for converting bytes to hex VarSetCapacity(A,16) DllCall("rpcrt4\UuidCreate","Str",A) Address := &A Loop 16 { x := 256 + *Address ; get byte in hex, set 17th bit StringTrimLeft x, x, 3 ; remove 0x1 h = %x%%h% ; in memory: LS byte first Address++ } SetFormat Integer, %format% ; restore original format h := SubStr(h,1,8) . "-" . SubStr(h,9,4) . "-" . SubStr(h,13,4) . "-" . SubStr(h,17,4) . "-" . SubStr(h,21,12) return h }

politelemon|5 years ago

I remember several years ago using https://newguid.com which was pretty much the same thing - no page furniture, just the new guid. Sadly the domain seems to be on sale now!

There's also https://www.newguid.org/

berkes|5 years ago

> Sadly the domain seems to be on sale now!

Which is a perfect example why it is bad to rely on a service like this to generate your IDs.

What if I bought it and started emitting predictable IDs? Or non-unique IDs?

patricjansson|5 years ago

Usage information in response headers, me like :)

aranw|5 years ago

Nice! I think this will still have a use and is a nice addition to add another alternative way to generate uuids

I use the following alias to generate uuids

   function uuid() { uuidgen | tr "[:upper:]" "[:lower:]" | tr -d "\n\r" }
I then pair it with pbcopy on the mac

   uuidgen | pbcopy

jcelerier|5 years ago

one of my most used non-trivial shell commands must be

    uuidgen | awk '{ printf "\"" $1 "\"" }' | xclip -selection clipboard

plasma|5 years ago

If you use Visual Studio, typing the word (with quotes) “nguid” in the code IDE generates one for you.

deweyair|5 years ago

I spend a fair amount of my day in Visual Studio and didn't know this, thanks!

thinkingkong|5 years ago

If you need a unique identifier on the command line there are a few ways to do it.

uuidgen is one. My personal favorite is this snippet.

$ id=$(openssl rand 1000 | openssl sha1) && printf "%s${id:0:8}\n"

mormegil|5 years ago

Why would you want to hash random bytes? The only thing you could theoretically achieve by that would be decreasing entropy. Just do openssl rand -hex 20 (or any other number of bytes as needed, or -base64 for another encoding).

santiagobasulto|5 years ago

I have uuidgen in my Mac, but also have a tiny alias:

    alias uuid='python -c "import uuid;print(str(uuid.uuid4()))"'

redact207|5 years ago

Thanks I'll probably use this. I often want to get a static uuid - usually for adding as static data in a test.

antiufo|5 years ago

Or from PowerShell: [Guid]::NewGuid()

Jaruzel|5 years ago

Which is in turn, derivated from .NETs 'Guid.NewGuid()'

eterm|5 years ago

> New-Guid

Is shorter and easier.