Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit d5ba7db

Browse files
Add math class
1 parent 3b18f44 commit d5ba7db

File tree

2 files changed

+150
-0
lines changed

2 files changed

+150
-0
lines changed

api/gen_ai/math.py

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import math
2+
from statistics import mean, variance
3+
from datetime import datetime
4+
5+
# Basic arithmetic functions
6+
def add(a, b):
7+
return a + b
8+
9+
def subtract(a, b):
10+
return a - b
11+
12+
def divide(a, b):
13+
if b == 0:
14+
raise ValueError("Division by zero is not allowed")
15+
return a / b
16+
17+
# Factorial using iterative approach
18+
def factorial(n):
19+
if n < 0:
20+
raise ValueError("Negative numbers do not have factorials")
21+
result = 1
22+
for i in range(1, n + 1):
23+
result *= i
24+
return result
25+
26+
# Check if a number is prime
27+
def is_prime(n):
28+
if n <= 1:
29+
return False
30+
if n <= 3:
31+
return True
32+
if n % 2 == 0 or n % 3 == 0:
33+
return False
34+
i = 5
35+
while i * i <= n:
36+
if n % i == 0 or n % (i + 2) == 0:
37+
return False
38+
i += 6
39+
return True
40+
41+
# Fibonacci number generator (nth number)
42+
def fibonacci(n):
43+
if n < 0:
44+
raise ValueError("n must be a non-negative integer")
45+
if n == 0:
46+
return 0
47+
elif n == 1:
48+
return 1
49+
a, b = 0, 1
50+
for _ in range(2, n + 1):
51+
a, b = b, a + b
52+
return b
53+
54+
# Calculator class with memory
55+
class Calculator:
56+
def __init__(self):
57+
self.memory = 0
58+
59+
def add(self, a, b):
60+
return a + b
61+
62+
def subtract(self, a, b):
63+
return a - b
64+
65+
def multiply(self, a, b):
66+
return a * b
67+
68+
def divide(self, a, b):
69+
if b == 0:
70+
raise ValueError("Cannot divide by zero")
71+
return a / b
72+
73+
def store(self, value):
74+
self.memory = value
75+
76+
def recall(self):
77+
return self.memory
78+
79+
# String manipulation functions
80+
class StringManipulator:
81+
@staticmethod
82+
def reverse_string(s):
83+
return s[::-1]
84+
85+
@staticmethod
86+
def is_palindrome(s):
87+
cleaned = ''.join(c.lower() for c in s if c.isalnum())
88+
return cleaned == cleaned[::-1]
89+
90+
# Data processing class for numerical lists
91+
class DataProcessor:
92+
def __init__(self, data):
93+
if not data:
94+
raise ValueError("Data list cannot be empty")
95+
self.data = data
96+
97+
def get_mean(self):
98+
return mean(self.data)
99+
100+
def get_variance(self):
101+
if len(self.data) < 2:
102+
raise ValueError("At least two data points are required to compute variance")
103+
return variance(self.data)
104+
105+
def normalize(self):
106+
m = self.get_mean()
107+
try:
108+
std_dev = math.sqrt(variance(self.data))
109+
except Exception:
110+
raise ValueError("Could not compute standard deviation")
111+
if std_dev == 0:
112+
raise ValueError("Standard deviation is zero, cannot normalize")
113+
return [(x - m) / std_dev for x in self.data]
114+
115+
# Date parsing function with a default format
116+
def parse_date(date_str, fmt="%Y-%m-%d"):
117+
try:
118+
return datetime.strptime(date_str, fmt)
119+
except ValueError:
120+
raise ValueError("Incorrect date format, should be YYYY-MM-DD")
121+
122+
# Safe access to list elements with default value
123+
def safe_list_access(lst, index, default=None):
124+
try:
125+
return lst[index]
126+
except IndexError:
127+
return default
128+
129+
# Merge two dictionaries recursively
130+
def merge_dicts(dict1, dict2):
131+
result = dict1.copy()
132+
for key, value in dict2.items():
133+
if key in result and isinstance(result[key], dict) and isinstance(value, dict):
134+
result[key] = merge_dicts(result[key], value)
135+
else:
136+
result[key] = value
137+
return result
138+

webhook_handlers/views/script.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import hashlib
2+
import hmac
3+
4+
5+
key = b'8ec0774d5cef46049856b1468dad5558'
6+
body1 = b'{"action":"created","installation":{"id":61679742,"client_id":"Iv1.70d8e1cdb391508f","account":{"login":"Test-org-ai-codecov-1244","id":200814284,"node_id":"O_kgDOC_guzA","avatar_url":"https://avatars.githubusercontent.com/u/200814284?v=4","gravatar_id":"","url":"https://api.github.com/users/Test-org-ai-codecov-1244","html_url":"https://github.com/Test-org-ai-codecov-1244","followers_url":"https://api.github.com/users/Test-org-ai-codecov-1244/followers","following_url":"https://api.github.com/users/Test-org-ai-codecov-1244/following{/other_user}","gists_url":"https://api.github.com/users/Test-org-ai-codecov-1244/gists{/gist_id}","starred_url":"https://api.github.com/users/Test-org-ai-codecov-1244/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Test-org-ai-codecov-1244/subscriptions","organizations_url":"https://api.github.com/users/Test-org-ai-codecov-1244/orgs","repos_url":"https://api.github.com/users/Test-org-ai-codecov-1244/repos","events_url":"https://api.github.com/users/Test-org-ai-codecov-1244/events{/privacy}","received_events_url":"https://api.github.com/users/Test-org-ai-codecov-1244/received_events","type":"Organization","user_view_type":"public","site_admin":false},"repository_selection":"all","access_tokens_url":"https://api.github.com/app/installations/61679742/access_tokens","repositories_url":"https://api.github.com/installation/repositories","html_url":"https://github.com/organizations/Test-org-ai-codecov-1244/settings/installations/61679742","app_id":856346,"app_slug":"ai-review-private-r","target_id":200814284,"target_type":"Organization","permissions":{"members":"read","organization_administration":"read","organization_custom_properties":"read","organization_events":"read","organization_hooks":"read","organization_projects":"read","team_discussions":"write","actions":"write","checks":"read","issues":"write","metadata":"read","pull_requests":"write","repository_hooks":"write","statuses":"read"},"events":["check_run","check_suite","issues","issue_comment","pull_request","pull_request_review","pull_request_review_comment","pull_request_review_thread","repository","status","workflow_job","workflow_run"],"created_at":"2025-02-25T17:37:11.000-05:00","updated_at":"2025-02-25T17:37:11.000-05:00","single_file_name":null,"has_multiple_single_files":false,"single_file_paths":[],"suspended_by":null,"suspended_at":null},"repositories":[{"id":938868535,"node_id":"R_kgDON_X_Nw","name":"python-test","full_name":"Test-org-ai-codecov-1244/python-test","private":true}],"requester":null,"sender":{"login":"rohitvinnakota-codecov","id":148245014,"node_id":"U_kgDOCNYKFg","avatar_url":"https://avatars.githubusercontent.com/u/148245014?v=4","gravatar_id":"","url":"https://api.github.com/users/rohitvinnakota-codecov","html_url":"https://github.com/rohitvinnakota-codecov","followers_url":"https://api.github.com/users/rohitvinnakota-codecov/followers","following_url":"https://api.github.com/users/rohitvinnakota-codecov/following{/other_user}","gists_url":"https://api.github.com/users/rohitvinnakota-codecov/gists{/gist_id}","starred_url":"https://api.github.com/users/rohitvinnakota-codecov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rohitvinnakota-codecov/subscriptions","organizations_url":"https://api.github.com/users/rohitvinnakota-codecov/orgs","repos_url":"https://api.github.com/users/rohitvinnakota-codecov/repos","events_url":"https://api.github.com/users/rohitvinnakota-codecov/events{/privacy}","received_events_url":"https://api.github.com/users/rohitvinnakota-codecov/received_events","type":"User","user_view_type":"public","site_admin":false}}'
7+
8+
body2 = b'{"action":"created","installation":{"id":61679742,"client_id":"Iv1.70d8e1cdb391508f","account":{"login":"Test-org-ai-codecov-1244","id":200814284,"node_id":"O_kgDOC_guzA","avatar_url":"https://avatars.githubusercontent.com/u/200814284?v=4","gravatar_id":"","url":"https://api.github.com/users/Test-org-ai-codecov-1244","html_url":"https://github.com/Test-org-ai-codecov-1244","followers_url":"https://api.github.com/users/Test-org-ai-codecov-1244/followers","following_url":"https://api.github.com/users/Test-org-ai-codecov-1244/following{/other_user}","gists_url":"https://api.github.com/users/Test-org-ai-codecov-1244/gists{/gist_id}","starred_url":"https://api.github.com/users/Test-org-ai-codecov-1244/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Test-org-ai-codecov-1244/subscriptions","organizations_url":"https://api.github.com/users/Test-org-ai-codecov-1244/orgs","repos_url":"https://api.github.com/users/Test-org-ai-codecov-1244/repos","events_url":"https://api.github.com/users/Test-org-ai-codecov-1244/events{/privacy}","received_events_url":"https://api.github.com/users/Test-org-ai-codecov-1244/received_events","type":"Organization","user_view_type":"public","site_admin":false},"repository_selection":"all","access_tokens_url":"https://api.github.com/app/installations/61679742/access_tokens","repositories_url":"https://api.github.com/installation/repositories","html_url":"https://github.com/organizations/Test-org-ai-codecov-1244/settings/installations/61679742","app_id":856346,"app_slug":"ai-review-private-r","target_id":200814284,"target_type":"Organization","permissions":{"members":"read","organization_administration":"read","organization_custom_properties":"read","organization_events":"read","organization_hooks":"read","organization_projects":"read","team_discussions":"write","actions":"write","checks":"read","issues":"write","metadata":"read","pull_requests":"write","repository_hooks":"write","statuses":"read"},"events":["check_run","check_suite","issues","issue_comment","pull_request","pull_request_review","pull_request_review_comment","pull_request_review_thread","repository","status","workflow_job","workflow_run"],"created_at":"2025-02-25T17:37:11.000-05:00","updated_at":"2025-02-25T17:37:11.000-05:00","single_file_name":null,"has_multiple_single_files":false,"single_file_paths":[],"suspended_by":null,"suspended_at":null},"repositories":[{"id":938868535,"node_id":"R_kgDON_X_Nw","name":"python-test","full_name":"Test-org-ai-codecov-1244/python-test","private":true}],"requester":null,"sender":{"login":"rohitvinnakota-codecov","id":148245014,"node_id":"U_kgDOCNYKFg","avatar_url":"https://avatars.githubusercontent.com/u/148245014?v=4","gravatar_id":"","url":"https://api.github.com/users/rohitvinnakota-codecov","html_url":"https://github.com/rohitvinnakota-codecov","followers_url":"https://api.github.com/users/rohitvinnakota-codecov/followers","following_url":"https://api.github.com/users/rohitvinnakota-codecov/following{/other_user}","gists_url":"https://api.github.com/users/rohitvinnakota-codecov/gists{/gist_id}","starred_url":"https://api.github.com/users/rohitvinnakota-codecov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rohitvinnakota-codecov/subscriptions","organizations_url":"https://api.github.com/users/rohitvinnakota-codecov/orgs","repos_url":"https://api.github.com/users/rohitvinnakota-codecov/repos","events_url":"https://api.github.com/users/rohitvinnakota-codecov/events{/privacy}","received_events_url":"https://api.github.com/users/rohitvinnakota-codecov/received_events","type":"User","user_view_type":"public","site_admin":false}}'
9+
sig = "sha256=" + hmac.new(key, body1, digestmod=hashlib.sha256).hexdigest()
10+
sig2 = "sha256=" + hmac.new(key, body2, digestmod=hashlib.sha256).hexdigest()
11+
12+
print(sig, sig2)

0 commit comments

Comments
 (0)