Skip to content

Instantly share code, notes, and snippets.

View stevendaniels's full-sized avatar
👋

Steven Daniels stevendaniels

👋
View GitHub Profile
@stevendaniels
stevendaniels / extract_timestamp_from_hibernate_uuid.rb
Created April 25, 2014 08:57
Extract a timestamp from a UUID created by Hibernate's uuid.hex function.
def extract_timestamp_from_hibernate_uuid(str)
Time.at(str[16,12].to_i(16) / 1000)
end
@stevendaniels
stevendaniels / check-navigator-platform-benchmark.js
Created January 20, 2013 03:16
Is it faster to use regex to detect a browser's os, or indexOf?
//methodology: ran the test 4 times and took the slowest time.
checkOSRegex = function(){
var os = navigator.platform;
return /[wl]in/i.test(os) ? /win/i.test(os) ? 'linux' : 'windows' : 'mac'; //slightly confusing, but 26% faster than
}
checkOSRegexStart = Date.now();
for(var i = 0; i < 1000000; i++){
checkOSRegex('MacIntel');