Skip to content

Instantly share code, notes, and snippets.

View ilkersen3's full-sized avatar
🏠
Working from home

İlker Şen ilkersen3

🏠
Working from home
View GitHub Profile
module MockSnowflake
TWEPOCH = 1142974214000
WORKERIDBITS = 5
DATACENTERIDBITS = 5
MAXWORKERID = -1 ^ (-1 << WORKERIDBITS)
SEQUENCEBITS = 12
WORKERIDSHIFT = SEQUENCEBITS
DATACENTERIDSHIFT = SEQUENCEBITS + WORKERIDBITS
TIMESTAMPLEFTSHIFT = SEQUENCEBITS + WORKERIDBITS + DATACENTERIDBITS
@hayesdavis
hayesdavis / blizzard.rb
Created October 19, 2010 17:09
Fun with snowflake
#First tweet on 21 Mar 2006 at 20:50:14.000 GMT (in ms)
TWEPOCH = 1288834974657
#High 42 bytes are timestamp, low 22 are worker, datacenter and sequence bits
SHIFT = 22
# Give it a snowflake id, it tells you what time it was created
# Will fail for very high ids because Ruby Time can only represent up to
# Jan 18, 2038 at 19:14:07 UTC (max signed int in seconds since unix epoch)
def what_time?(id)