Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate a UUID in Visual Studio Code?

Is it possible to create a code snippet or a task runner (or anything else) that would allow me to generate a UUID in VSCode? This question can also be interpreted in a more generic way: Can I run an external tool/program and insert the result at the current cursor position.

Thanks.

like image 291
Gabe Perez Avatar asked Oct 08 '15 02:10

Gabe Perez


People also ask

How an UUID is generated?

UUID was standardized by the Open Software Foundation (OSF), becoming a part of the Distributed Computing Environment (DCE). Different versions of UUID follow the RFC 4122 specification. UUIDs are generated using an algorithm based on a timestamp and other factors such as the network address.

How are UUID V4 generated?

A Version 4 UUID is a universally unique identifier that is generated using random numbers. The Version 4 UUIDs produced by this site were generated using a secure random number generator.

How do you generate a UUID in Python?

UUID 1 to Generate a unique ID using MAC AddressThe uuid. uuid1() function is used to generate a UUID from the host ID, sequence number, and the current time. It uses the MAC address of a host as a source of uniqueness. The node and clock_seq are optional arguments.

What is UUID example?

Format. In its canonical textual representation, the 16 octets of a UUID are represented as 32 hexadecimal (base-16) digits, displayed in five groups separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters (32 hexadecimal characters and 4 hyphens). For example: 123e4567-e89b-12d3-a456-426614174000.


2 Answers

The following extension is super easy to use and does exactly what you want: https://github.com/heaths/vscode-guid (or get it here from the VS Marketplace)

like image 122
Simon Mattes Avatar answered Sep 18 '22 12:09

Simon Mattes


Regarding code sniper and uuid, consider that VSCode 1.53 (Jan. 2021) introduces an interesting feature:

New Snippet Variables

There are new snippet variables for inserting uuids and for inserting the relative path the current file.

The sample snippet below would print:

let someId = 'foo/test.js/c13d226f-1932-40e2-9fd9-10198c219e33'
// sample snippet using UUID and RELATIVE_FILEPATH
{
 "scope": "javascript",
 "prefix": "newVars",
 "body": "let someId = '${RELATIVE_FILEPATH}/${UUID}'$0"
}
like image 20
VonC Avatar answered Sep 22 '22 12:09

VonC