java.util.UUID.randomUUID().toString() length

Does java.util.UUID.randomUUID().toString() length always equal to 36? Yes!! it is. A UUID actually a 128 bit value (2 long). To represent 128 bit into hex string there will be 128/4=32 char (each char is 4bit long). In string format it also contains 4 (-) that’s why the length is 36. Example: 54947df8-0e9e-4471-a2f9-9af509fb5889 32 hex char … Read more

Creating a UUID from a string with no dashes

tl;dr java.util.UUID.fromString( “5231b533ba17478798a3f2df37de2aD7” .replaceFirst( “(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)”, “$1-$2-$3-$4-$5” ) ).toString() 5231b533-ba17-4787-98a3-f2df37de2ad7 Or parse each half of the hexadecimal string as long integer numbers, and pass to constructor of UUID. UUID uuid = new UUID ( long1 , long2 ) ; Bits, Not Text A UUID is a 128-bit value. A UUID is not actually made up of … Read more

Why are there dashes in a .NET GUID?

Technically, there are no “dashes” in a GUID. A GUID is a 128-bit value which is usually stored in the following manner (using C# here to represent the structure): public struct Guid { public ulong Data1; public ushort Data2; public ushort Data3; public fixed byte Data4[8]; } The dashes are in the string representation of … Read more

UUID(‘…’) is not JSON serializable

There is a bug ticket on Django regarding this issue however a custom so called ‘complex encoder’ by python docs can help you. import json from uuid import UUID class UUIDEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, UUID): # if the obj is uuid, we simply return the value of uuid return obj.hex return json.JSONEncoder.default(self, obj) … Read more

How do I represent a UUID in a protobuf message?

You should probably use string or bytes to represent a UUID. Use string if it is most convenient to keep the UUID in human-readable format (e.g. “de305d54-75b4-431b-adb2-eb6b9e546014”) or use bytes if you are storing the 128-bit value raw. (If you aren’t sure, you probably want string.) Wrapping the value in a message type called UUID … Read more

How to preserve identifierForVendor in ios after uninstalling ios app on device?

You may keep it in KeyChain -(NSString *)getUniqueDeviceIdentifierAsString { NSString *appName=[[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey]; NSString *strApplicationUUID = [SSKeychain passwordForService:appName account:@”incoding”]; if (strApplicationUUID == nil) { strApplicationUUID = [[[UIDevice currentDevice] identifierForVendor] UUIDString]; [SSKeychain setPassword:strApplicationUUID forService:appName account:@”incoding”]; } return strApplicationUUID; }

UUID to unique integer id?

You are going to have a problem since the UUID is 128 bits and the int is only 32bit. You’ll either have to accept the risk of collisions and try to fudge it to a smaller space (hashCode is probably a good way to do that) or find an alternative (use the UUID directly, map … Read more

Laravel UUID generation

After laravel 5.6 a new helper was added to generate Universal Unique Identifiers (UUID) use Illuminate\Support\Str; return (string) Str::uuid(); return (string) Str::orderedUuid(); The methods return a Ramsey\Uuid\Uuid object The orderedUuid() method will generate a timestamp first UUID for easier and more efficient database indexing.