Convert boost::uuid to char*

Just in case, there is also boost::uuids::to_string, that works as follows: #include <boost/uuid/uuid.hpp> #include <boost/uuid/uuid_io.hpp> boost::uuids::uuid a = …; const std::string tmp = boost::uuids::to_string(a); const char* value = tmp.c_str();

MySQL set default id UUID

MySQL 5.7, 8.0.12 and older MySQL as of 5.7 or 8.0.12 does not support using a function or expression as the default value of a column. The DEFAULT value clause in a data type specification indicates a default value for a column. With one exception, the default value must be a constant; it cannot be … Read more

How can I generate UUID in c++, without using boost library?

This will do, if you’re using modern C++. #include <random> #include <sstream> namespace uuid { static std::random_device rd; static std::mt19937 gen(rd()); static std::uniform_int_distribution<> dis(0, 15); static std::uniform_int_distribution<> dis2(8, 11); std::string generate_uuid_v4() { std::stringstream ss; int i; ss << std::hex; for (i = 0; i < 8; i++) { ss << dis(gen); } ss << “-“; … Read more

convert uuid to byte, that works when using UUID.nameUUIDFromBytes(b)

public class UuidUtils { public static UUID asUuid(byte[] bytes) { ByteBuffer bb = ByteBuffer.wrap(bytes); long firstLong = bb.getLong(); long secondLong = bb.getLong(); return new UUID(firstLong, secondLong); } public static byte[] asBytes(UUID uuid) { ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return bb.array(); } } @Test public void verifyUUIDBytesCanBeReconstructedBackToOriginalUUID() { UUID u = UUID.randomUUID(); byte[] uBytes … Read more

How to mock uuid with Jest

I figure I might as well add my solution here, for posterity. None of the above was exactly what I needed: jest.mock(‘uuid’, () => ({ v4: () => ‘123456789’ })); By the way, using a variable instead of ‘123456789’ breaks it. This should be mocked where we have the imports and it does not require … Read more

GUID / UUID type in typescript

You could create a wrapper around a string and pass that around: class GUID { private str: string; constructor(str?: string) { this.str = str || GUID.getNewGUIDString(); } toString() { return this.str; } private static getNewGUIDString() { // your favourite guid generation function could go here // ex: http://stackoverflow.com/a/8809472/188246 let d = new Date().getTime(); if (window.performance … Read more