Skip to content

Instantly share code, notes, and snippets.

@yfuruyama
Last active June 17, 2017 12:08
Show Gist options
  • Select an option

  • Save yfuruyama/339da718a75a4c413f2c79d64e3d92e8 to your computer and use it in GitHub Desktop.

Select an option

Save yfuruyama/339da718a75a4c413f2c79d64e3d92e8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use feature qw/say/;
my $INSTAGRAM_EPOCH = 1314220021721; # Thu Aug 24 2011 21:07:01 GMT
my $id = $ARGV[0] or die 'id needed';
my $raw_timestamp = ($id >> 23) & ((1 << 41) - 1);
my $timestamp = $raw_timestamp + $INSTAGRAM_EPOCH;
my $shard = ($id >> 10) & ((1 << 13) - 1);
my $seq = $id & ((1 << 10) - 1);
say "timestamp: $timestamp";
say "shard: $shard";
say "sequence: $seq";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment