{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/normandy/pulls/comments/50189281","id":50189281,"diff_hunk":"@@ -0,0 +1,48 @@\n+import hashlib\n+\n+\n+def fraction_to_key(frac):\n+    \"\"\"Map from the range [0, 1] to [0, max(sha256)]. The result is a string.\"\"\"\n+    # SHA 256 hashes are 64 hexadecimal numbers. The largest possible SHA 256\n+    # hash is 2^64 - 1\n+\n+    if frac < 0 or frac > 1:\n+        raise ValueError('frac must be between 0 and 1 inclusive (got {})'.format(frac))\n+\n+    mult = 2 ** 256 - 1\n+    in_decimal = int(frac * mult)\n+\n+    assert in_decimal >= 0\n+\n+    hex_digits = hex(in_decimal)[2:]  # Strip off leading \"0x\"\n+    padded = \"{:0<64}\".format(hex_digits)\n+\n+    # Saturate at 2**256 - 1\n+    if len(padded) > 64:\n+        return 'f' * 64\n+    else:\n+        return padded\n+\n+\n+def deterministic_sample(rate, inputs):\n+    \"\"\"\n+    Deterministically choose True or False based for a set of inputs.\n+\n+    Internally, converts `rate` into a point in the sha256 hash space. If the\n+    hash of `inputs` is less than that point, it returns True.\n+\n+    @parameter rate The probability of returning True","path":"normandy/recipes/utils.py","position":34,"original_position":34,"commit_id":"c71a7fca0b31a05e027a53e840819e8a16b1e643","original_commit_id":"c71a7fca0b31a05e027a53e840819e8a16b1e643","user":{"login":"Osmose","id":193106,"avatar_url":"https://avatars.githubusercontent.com/u/193106?v=3","gravatar_id":"","url":"https://api.github.com/users/Osmose","html_url":"https://github.com/Osmose","followers_url":"https://api.github.com/users/Osmose/followers","following_url":"https://api.github.com/users/Osmose/following{/other_user}","gists_url":"https://api.github.com/users/Osmose/gists{/gist_id}","starred_url":"https://api.github.com/users/Osmose/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Osmose/subscriptions","organizations_url":"https://api.github.com/users/Osmose/orgs","repos_url":"https://api.github.com/users/Osmose/repos","events_url":"https://api.github.com/users/Osmose/events{/privacy}","received_events_url":"https://api.github.com/users/Osmose/received_events","type":"User","site_admin":false},"body":"What docstring style is this, again?","created_at":"2016-01-19T22:53:09Z","updated_at":"2016-01-19T22:53:09Z","html_url":"https://github.com/mozilla/normandy/pull/6#discussion_r50189281","pull_request_url":"https://api.github.com/repos/mozilla/normandy/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/mozilla/normandy/pulls/comments/50189281"},"html":{"href":"https://github.com/mozilla/normandy/pull/6#discussion_r50189281"},"pull_request":{"href":"https://api.github.com/repos/mozilla/normandy/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/normandy/pulls/6","id":56229582,"html_url":"https://github.com/mozilla/normandy/pull/6","diff_url":"https://github.com/mozilla/normandy/pull/6.diff","patch_url":"https://github.com/mozilla/normandy/pull/6.patch","issue_url":"https://api.github.com/repos/mozilla/normandy/issues/6","number":6,"state":"open","locked":false,"title":"Hash based sampling","user":{"login":"mythmon","id":305049,"avatar_url":"https://avatars.githubusercontent.com/u/305049?v=3","gravatar_id":"","url":"https://api.github.com/users/mythmon","html_url":"https://github.com/mythmon","followers_url":"https://api.github.com/users/mythmon/followers","following_url":"https://api.github.com/users/mythmon/following{/other_user}","gists_url":"https://api.github.com/users/mythmon/gists{/gist_id}","starred_url":"https://api.github.com/users/mythmon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mythmon/subscriptions","organizations_url":"https://api.github.com/users/mythmon/orgs","repos_url":"https://api.github.com/users/mythmon/repos","events_url":"https://api.github.com/users/mythmon/events{/privacy}","received_events_url":"https://api.github.com/users/mythmon/received_events","type":"User","site_admin":false},"body":"@Osmose r?","created_at":"2016-01-15T22:25:35Z","updated_at":"2016-01-19T22:53:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7e10fcafafb5d68eef4d37e3784eb87379d5632f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/normandy/pulls/6/commits","review_comments_url":"https://api.github.com/repos/mozilla/normandy/pulls/6/comments","review_comment_url":"https://api.github.com/repos/mozilla/normandy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla/normandy/issues/6/comments","statuses_url":"https://api.github.com/repos/mozilla/normandy/statuses/c71a7fca0b31a05e027a53e840819e8a16b1e643","head":{"label":"mythmon:hash-based-sampling","ref":"hash-based-sampling","sha":"c71a7fca0b31a05e027a53e840819e8a16b1e643","user":{"login":"mythmon","id":305049,"avatar_url":"https://avatars.githubusercontent.com/u/305049?v=3","gravatar_id":"","url":"https://api.github.com/users/mythmon","html_url":"https://github.com/mythmon","followers_url":"https://api.github.com/users/mythmon/followers","following_url":"https://api.github.com/users/mythmon/following{/other_user}","gists_url":"https://api.github.com/users/mythmon/gists{/gist_id}","starred_url":"https://api.github.com/users/mythmon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mythmon/subscriptions","organizations_url":"https://api.github.com/users/mythmon/orgs","repos_url":"https://api.github.com/users/mythmon/repos","events_url":"https://api.github.com/users/mythmon/events{/privacy}","received_events_url":"https://api.github.com/users/mythmon/received_events","type":"User","site_admin":false},"repo":{"id":49591352,"name":"normandy","full_name":"mythmon/normandy","owner":{"login":"mythmon","id":305049,"avatar_url":"https://avatars.githubusercontent.com/u/305049?v=3","gravatar_id":"","url":"https://api.github.com/users/mythmon","html_url":"https://github.com/mythmon","followers_url":"https://api.github.com/users/mythmon/followers","following_url":"https://api.github.com/users/mythmon/following{/other_user}","gists_url":"https://api.github.com/users/mythmon/gists{/gist_id}","starred_url":"https://api.github.com/users/mythmon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mythmon/subscriptions","organizations_url":"https://api.github.com/users/mythmon/orgs","repos_url":"https://api.github.com/users/mythmon/repos","events_url":"https://api.github.com/users/mythmon/events{/privacy}","received_events_url":"https://api.github.com/users/mythmon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mythmon/normandy","description":"Self-Repair 2","fork":true,"url":"https://api.github.com/repos/mythmon/normandy","forks_url":"https://api.github.com/repos/mythmon/normandy/forks","keys_url":"https://api.github.com/repos/mythmon/normandy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mythmon/normandy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mythmon/normandy/teams","hooks_url":"https://api.github.com/repos/mythmon/normandy/hooks","issue_events_url":"https://api.github.com/repos/mythmon/normandy/issues/events{/number}","events_url":"https://api.github.com/repos/mythmon/normandy/events","assignees_url":"https://api.github.com/repos/mythmon/normandy/assignees{/user}","branches_url":"https://api.github.com/repos/mythmon/normandy/branches{/branch}","tags_url":"https://api.github.com/repos/mythmon/normandy/tags","blobs_url":"https://api.github.com/repos/mythmon/normandy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mythmon/normandy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mythmon/normandy/git/refs{/sha}","trees_url":"https://api.github.com/repos/mythmon/normandy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mythmon/normandy/statuses/{sha}","languages_url":"https://api.github.com/repos/mythmon/normandy/languages","stargazers_url":"https://api.github.com/repos/mythmon/normandy/stargazers","contributors_url":"https://api.github.com/repos/mythmon/normandy/contributors","subscribers_url":"https://api.github.com/repos/mythmon/normandy/subscribers","subscription_url":"https://api.github.com/repos/mythmon/normandy/subscription","commits_url":"https://api.github.com/repos/mythmon/normandy/commits{/sha}","git_commits_url":"https://api.github.com/repos/mythmon/normandy/git/commits{/sha}","comments_url":"https://api.github.com/repos/mythmon/normandy/comments{/number}","issue_comment_url":"https://api.github.com/repos/mythmon/normandy/issues/comments{/number}","contents_url":"https://api.github.com/repos/mythmon/normandy/contents/{+path}","compare_url":"https://api.github.com/repos/mythmon/normandy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mythmon/normandy/merges","archive_url":"https://api.github.com/repos/mythmon/normandy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mythmon/normandy/downloads","issues_url":"https://api.github.com/repos/mythmon/normandy/issues{/number}","pulls_url":"https://api.github.com/repos/mythmon/normandy/pulls{/number}","milestones_url":"https://api.github.com/repos/mythmon/normandy/milestones{/number}","notifications_url":"https://api.github.com/repos/mythmon/normandy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mythmon/normandy/labels{/name}","releases_url":"https://api.github.com/repos/mythmon/normandy/releases{/id}","created_at":"2016-01-13T17:54:36Z","updated_at":"2016-01-13T17:54:36Z","pushed_at":"2016-01-15T23:24:28Z","git_url":"git://github.com/mythmon/normandy.git","ssh_url":"git@github.com:mythmon/normandy.git","clone_url":"https://github.com/mythmon/normandy.git","svn_url":"https://github.com/mythmon/normandy","homepage":"http://normandy.readthedocs.org/","size":48,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mozilla:master","ref":"master","sha":"8f92dbe6ba6a890db9e7f203c0f324afcc6a7a4d","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":48456638,"name":"normandy","full_name":"mozilla/normandy","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/normandy","description":"Self-Repair 2","fork":false,"url":"https://api.github.com/repos/mozilla/normandy","forks_url":"https://api.github.com/repos/mozilla/normandy/forks","keys_url":"https://api.github.com/repos/mozilla/normandy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/normandy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/normandy/teams","hooks_url":"https://api.github.com/repos/mozilla/normandy/hooks","issue_events_url":"https://api.github.com/repos/mozilla/normandy/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/normandy/events","assignees_url":"https://api.github.com/repos/mozilla/normandy/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/normandy/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/normandy/tags","blobs_url":"https://api.github.com/repos/mozilla/normandy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/normandy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/normandy/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/normandy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/normandy/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/normandy/languages","stargazers_url":"https://api.github.com/repos/mozilla/normandy/stargazers","contributors_url":"https://api.github.com/repos/mozilla/normandy/contributors","subscribers_url":"https://api.github.com/repos/mozilla/normandy/subscribers","subscription_url":"https://api.github.com/repos/mozilla/normandy/subscription","commits_url":"https://api.github.com/repos/mozilla/normandy/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/normandy/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/normandy/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/normandy/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/normandy/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/normandy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/normandy/merges","archive_url":"https://api.github.com/repos/mozilla/normandy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/normandy/downloads","issues_url":"https://api.github.com/repos/mozilla/normandy/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/normandy/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/normandy/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/normandy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/normandy/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/normandy/releases{/id}","created_at":"2015-12-22T22:18:19Z","updated_at":"2016-01-11T21:36:33Z","pushed_at":"2016-01-15T23:24:30Z","git_url":"git://github.com/mozilla/normandy.git","ssh_url":"git@github.com:mozilla/normandy.git","clone_url":"https://github.com/mozilla/normandy.git","svn_url":"https://github.com/mozilla/normandy","homepage":"http://normandy.readthedocs.org/","size":41,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":1,"forks":2,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/normandy/pulls/6"},"html":{"href":"https://github.com/mozilla/normandy/pull/6"},"issue":{"href":"https://api.github.com/repos/mozilla/normandy/issues/6"},"comments":{"href":"https://api.github.com/repos/mozilla/normandy/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/normandy/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/normandy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla/normandy/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/normandy/statuses/c71a7fca0b31a05e027a53e840819e8a16b1e643"}}}}