Test if string is a guid without throwing exceptions?

Performance Benchmarks Catch exception: 10,000 good: 63,668 ticks 10,000 bad: 6,435,609 ticks Regex Pre-Screen: 10,000 good: 637,633 ticks 10,000 bad: 717,894 ticks COM Interop CLSIDFromString 10,000 good: 126,120 ticks 10,000 bad: 23,134 ticks COM Intertop (Fastest) Answer: /// <summary> /// Attempts to convert a string to a guid. /// </summary> /// <param name=”s”>The string to … Read more

Best way to create unique token in Rails?

— Update — As of January 9th, 2015. the solution is now implemented in Rails 5 ActiveRecord’s secure token implementation. — Rails 4 & 3 — Just for future reference, creating safe random token and ensuring it’s uniqueness for the model (when using Ruby 1.9 and ActiveRecord): class ModelName < ActiveRecord::Base before_create :generate_token protected def … Read more

How do I create a GUID / UUID?

[Edited 2021-10-16 to reflect latest best-practices for producing RFC4122-compliant UUIDs] Most readers here will want to use the uuid module. It is well-tested and supported. The crypto.randomUUID() function is an emerging standard that is supported in Node.js and an increasing number of browsers. If neither of those work for you, there is this method (based … Read more

How to Create Deterministic Guids

As mentioned by @bacar, RFC 4122 §4.3 defines a way to create a name-based UUID. The advantage of doing this (over just using a MD5 hash) is that these are guaranteed not to collide with non-named-based UUIDs, and have a very (very) small possibility of collision with other name-based UUIDs. There’s no native support in … Read more

How to create a GUID/UUID using iOS

[[UIDevice currentDevice] uniqueIdentifier] Returns the Unique ID of your iPhone. EDIT: -[UIDevice uniqueIdentifier] is now deprecated and apps are being rejected from the App Store for using it. The method below is now the preferred approach. If you need to create several UUID, just use this method (with ARC): + (NSString *)GetUUID { CFUUIDRef theUUID … Read more