repo
stringlengths
7
90
file_url
stringlengths
81
315
file_path
stringlengths
4
228
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 14:38:15
2026-01-05 02:33:18
truncated
bool
2 classes
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/hashing/tests/__init__.py
data_structures/hashing/tests/__init__.py
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/hashing/number_theory/prime_numbers.py
data_structures/hashing/number_theory/prime_numbers.py
#!/usr/bin/env python3 """ module to operations with prime numbers """ import math def is_prime(number: int) -> bool: """Checks to see if a number is a prime in O(sqrt(n)). A number is prime if it has exactly two factors: 1 and itself. >>> is_prime(0) False >>> is_prime(1) False >>> is_...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/hashing/number_theory/__init__.py
data_structures/hashing/number_theory/__init__.py
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/linked_list/singly_linked_list.py
data_structures/linked_list/singly_linked_list.py
from __future__ import annotations from collections.abc import Iterator from dataclasses import dataclass from typing import Any @dataclass class Node: """ Create and initialize Node class instance. >>> Node(20) Node(20) >>> Node("Hello, world!") Node(Hello, world!) >>> Node(None) Nod...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/linked_list/floyds_cycle_detection.py
data_structures/linked_list/floyds_cycle_detection.py
""" Floyd's cycle detection algorithm is a popular algorithm used to detect cycles in a linked list. It uses two pointers, a slow pointer and a fast pointer, to traverse the linked list. The slow pointer moves one node at a time while the fast pointer moves two nodes at a time. If there is a cycle in the linked list, t...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/linked_list/swap_nodes.py
data_structures/linked_list/swap_nodes.py
from __future__ import annotations from collections.abc import Iterator from dataclasses import dataclass from typing import Any @dataclass class Node: data: Any next_node: Node | None = None @dataclass class LinkedList: head: Node | None = None def __iter__(self) -> Iterator: """ ...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/linked_list/from_sequence.py
data_structures/linked_list/from_sequence.py
""" Recursive Program to create a Linked List from a sequence and print a string representation of it. """ class Node: def __init__(self, data=None): self.data = data self.next = None def __repr__(self): """Returns a visual representation of the node and all its following nodes.""" ...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/linked_list/circular_linked_list.py
data_structures/linked_list/circular_linked_list.py
from __future__ import annotations from collections.abc import Iterator from dataclasses import dataclass from typing import Any @dataclass class Node: data: Any next_node: Node | None = None @dataclass class CircularLinkedList: head: Node | None = None # Reference to the head (first node) tail: N...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/linked_list/doubly_linked_list_two.py
data_structures/linked_list/doubly_linked_list_two.py
""" - A linked list is similar to an array, it holds values. However, links in a linked list do not have indexes. - This is an example of a double ended, doubly linked list. - Each link references the next link and the previous one. - A Doubly Linked List (DLL) contains an extra pointer, typically called previous ...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/linked_list/is_palindrome.py
data_structures/linked_list/is_palindrome.py
from __future__ import annotations from dataclasses import dataclass @dataclass class ListNode: val: int = 0 next_node: ListNode | None = None def is_palindrome(head: ListNode | None) -> bool: """ Check if a linked list is a palindrome. Args: head: The head of the linked list. Ret...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/linked_list/has_loop.py
data_structures/linked_list/has_loop.py
from __future__ import annotations from typing import Any class ContainsLoopError(Exception): pass class Node: def __init__(self, data: Any) -> None: self.data: Any = data self.next_node: Node | None = None def __iter__(self): node = self visited = set() while n...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/linked_list/middle_element_of_linked_list.py
data_structures/linked_list/middle_element_of_linked_list.py
from __future__ import annotations class Node: def __init__(self, data: int) -> None: self.data = data self.next = None class LinkedList: def __init__(self): self.head = None def push(self, new_data: int) -> int: new_node = Node(new_data) new_node.next = self.hea...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/linked_list/rotate_to_the_right.py
data_structures/linked_list/rotate_to_the_right.py
from __future__ import annotations from dataclasses import dataclass @dataclass class Node: data: int next_node: Node | None = None def print_linked_list(head: Node | None) -> None: """ Print the entire linked list iteratively. This function prints the elements of a linked list separat...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/linked_list/deque_doubly.py
data_structures/linked_list/deque_doubly.py
""" Implementing Deque using DoublyLinkedList ... Operations: 1. insertion in the front -> O(1) 2. insertion in the end -> O(1) 3. remove from the front -> O(1) 4. remove from the end -> O(1) """ class _DoublyLinkedBase: """A Private class (to be inherited)""" class _Node: __slots__ =...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/linked_list/__init__.py
data_structures/linked_list/__init__.py
""" Linked Lists consists of Nodes. Nodes contain data and also may link to other nodes: - Head Node: First node, the address of the head node gives us access of the complete list - Last node: points to null """ from __future__ import annotations from typing import Any class Node: def _...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/linked_list/reverse_k_group.py
data_structures/linked_list/reverse_k_group.py
from __future__ import annotations from collections.abc import Iterable, Iterator from dataclasses import dataclass @dataclass class Node: data: int next_node: Node | None = None class LinkedList: def __init__(self, ints: Iterable[int]) -> None: self.head: Node | None = None for i in in...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/linked_list/skip_list.py
data_structures/linked_list/skip_list.py
""" Based on "Skip Lists: A Probabilistic Alternative to Balanced Trees" by William Pugh https://epaperpress.com/sortsearch/download/skiplist.pdf """ from __future__ import annotations from itertools import pairwise from random import random from typing import TypeVar KT = TypeVar("KT") VT = TypeVar("VT") class No...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/linked_list/merge_two_lists.py
data_structures/linked_list/merge_two_lists.py
""" Algorithm that merges two sorted linked lists into one sorted linked list. """ from __future__ import annotations from collections.abc import Iterable, Iterator from dataclasses import dataclass test_data_odd = (3, 9, -11, 0, 7, 5, 1, -1) test_data_even = (4, 6, 2, 0, 8, 10, 3, -2) @dataclass class Node: d...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/linked_list/doubly_linked_list.py
data_structures/linked_list/doubly_linked_list.py
""" https://en.wikipedia.org/wiki/Doubly_linked_list """ class Node: def __init__(self, data): self.data = data self.previous = None self.next = None def __str__(self): return f"{self.data}" class DoublyLinkedList: def __init__(self): self.head = None sel...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/data_structures/linked_list/print_reverse.py
data_structures/linked_list/print_reverse.py
from __future__ import annotations from collections.abc import Iterable, Iterator from dataclasses import dataclass @dataclass class Node: data: int next_node: Node | None = None class LinkedList: """A class to represent a Linked List. Use a tail pointer to speed up the append() operation. """ ...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/fuzzy_logic/fuzzy_operations.py
fuzzy_logic/fuzzy_operations.py
""" By @Shreya123714 https://en.wikipedia.org/wiki/Fuzzy_set """ from __future__ import annotations from dataclasses import dataclass import matplotlib.pyplot as plt import numpy as np @dataclass class FuzzySet: """ A class for representing and manipulating triangular fuzzy sets. Attributes: n...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/fuzzy_logic/__init__.py
fuzzy_logic/__init__.py
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/searches/sentinel_linear_search.py
searches/sentinel_linear_search.py
""" This is pure Python implementation of sentinel linear search algorithm For doctests run following command: python -m doctest -v sentinel_linear_search.py or python3 -m doctest -v sentinel_linear_search.py For manual testing run: python sentinel_linear_search.py """ def sentinel_linear_search(sequence, target): ...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/searches/simulated_annealing.py
searches/simulated_annealing.py
# https://en.wikipedia.org/wiki/Simulated_annealing import math import random from typing import Any from .hill_climbing import SearchProblem def simulated_annealing( search_prob, find_max: bool = True, max_x: float = math.inf, min_x: float = -math.inf, max_y: float = math.inf, min_y: float =...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/searches/hill_climbing.py
searches/hill_climbing.py
# https://en.wikipedia.org/wiki/Hill_climbing import math class SearchProblem: """ An interface to define search problems. The interface will be illustrated using the example of mathematical function. """ def __init__(self, x: int, y: int, step_size: int, function_to_optimize): """ ...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/searches/simple_binary_search.py
searches/simple_binary_search.py
""" Pure Python implementation of a binary search algorithm. For doctests run following command: python3 -m doctest -v simple_binary_search.py For manual testing run: python3 simple_binary_search.py """ from __future__ import annotations def binary_search(a_list: list[int], item: int) -> bool: """ >>> test...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/searches/quick_select.py
searches/quick_select.py
""" A Python implementation of the quick select algorithm, which is efficient for calculating the value that would appear in the index of a list if it would be sorted, even if it is not already sorted https://en.wikipedia.org/wiki/Quickselect """ import random def _partition(data: list, pivot) -> tuple: """ ...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/searches/double_linear_search_recursion.py
searches/double_linear_search_recursion.py
def search(list_data: list, key: int, left: int = 0, right: int = 0) -> int: """ Iterate through the array to find the index of key using recursion. :param list_data: the list to be searched :param key: the key to be searched :param left: the index of first element :param right: the index of las...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/searches/fibonacci_search.py
searches/fibonacci_search.py
""" This is pure Python implementation of fibonacci search. Resources used: https://en.wikipedia.org/wiki/Fibonacci_search_technique For doctests run following command: python3 -m doctest -v fibonacci_search.py For manual testing run: python3 fibonacci_search.py """ from functools import lru_cache @lru_cache def ...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/searches/double_linear_search.py
searches/double_linear_search.py
from __future__ import annotations def double_linear_search(array: list[int], search_item: int) -> int: """ Iterate through the array from both sides to find the index of search_item. :param array: the array to be searched :param search_item: the item to be searched :return the index of search_it...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/searches/ternary_search.py
searches/ternary_search.py
""" This is a type of divide and conquer algorithm which divides the search space into 3 parts and finds the target value based on the property of the array or list (usually monotonic property). Time Complexity : O(log3 N) Space Complexity : O(1) """ from __future__ import annotations # This is the precision for th...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/searches/median_of_medians.py
searches/median_of_medians.py
""" A Python implementation of the Median of Medians algorithm to select pivots for quick_select, which is efficient for calculating the value that would appear in the index of a list if it would be sorted, even if it is not already sorted. Search in time complexity O(n) at any rank deterministically https://en.wikiped...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/searches/exponential_search.py
searches/exponential_search.py
#!/usr/bin/env python3 """ Pure Python implementation of exponential search algorithm For more information, see the Wikipedia page: https://en.wikipedia.org/wiki/Exponential_search For doctests run the following command: python3 -m doctest -v exponential_search.py For manual testing run: python3 exponential_search....
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/searches/jump_search.py
searches/jump_search.py
""" Pure Python implementation of the jump search algorithm. This algorithm iterates through a sorted collection with a step of n^(1/2), until the element compared is bigger than the one searched. It will then perform a linear search until it matches the wanted number. If not found, it returns -1. https://en.wikipedia...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/searches/__init__.py
searches/__init__.py
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/searches/linear_search.py
searches/linear_search.py
""" This is pure Python implementation of linear search algorithm For doctests run following command: python3 -m doctest -v linear_search.py For manual testing run: python3 linear_search.py """ def linear_search(sequence: list, target: int) -> int: """A pure Python implementation of a linear search algorithm ...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/searches/binary_search.py
searches/binary_search.py
#!/usr/bin/env python3 """ Pure Python implementations of binary search algorithms For doctests run the following command: python3 -m doctest -v binary_search.py For manual testing run: python3 binary_search.py """ from __future__ import annotations import bisect def bisect_left( sorted_collection: list[int]...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/searches/interpolation_search.py
searches/interpolation_search.py
""" This is pure Python implementation of interpolation search algorithm """ def interpolation_search(sorted_collection: list[int], item: int) -> int | None: """ Searches for an item in a sorted collection by interpolation search algorithm. Args: sorted_collection: sorted list of integers ...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/searches/tabu_search.py
searches/tabu_search.py
""" This is pure Python implementation of Tabu search algorithm for a Travelling Salesman Problem, that the distances between the cities are symmetric (the distance between city 'a' and city 'b' is the same between city 'b' and city 'a'). The TSP can be represented into a graph. The cities are represented by nodes and ...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/searches/binary_tree_traversal.py
searches/binary_tree_traversal.py
""" This is pure Python implementation of tree traversal algorithms """ from __future__ import annotations import queue class TreeNode: def __init__(self, data): self.data = data self.right = None self.left = None def build_tree() -> TreeNode: print("\n********Press N to stop enter...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/least_recently_used.py
other/least_recently_used.py
from __future__ import annotations import sys from collections import deque from typing import TypeVar T = TypeVar("T") class LRUCache[T]: """ Page Replacement Algorithm, Least Recently Used (LRU) Caching. >>> lru_cache: LRUCache[str | int] = LRUCache(4) >>> lru_cache.refer("A") >>> lru_cache.r...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/nested_brackets.py
other/nested_brackets.py
""" The nested brackets problem is a problem that determines if a sequence of brackets are properly nested. A sequence of brackets s is considered properly nested if any of the following conditions are true: - s is empty - s has the form (U) or [U] or {U} where U is a properly nested string - s has the fo...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/davis_putnam_logemann_loveland.py
other/davis_putnam_logemann_loveland.py
#!/usr/bin/env python3 """ Davis-Putnam-Logemann-Loveland (DPLL) algorithm is a complete, backtracking-based search algorithm for deciding the satisfiability of propositional logic formulae in conjunctive normal form, i.e, for solving the Conjunctive Normal Form SATisfiability (CNF-SAT) problem. For more information ...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/linear_congruential_generator.py
other/linear_congruential_generator.py
__author__ = "Tobias Carryer" from time import time class LinearCongruentialGenerator: """ A pseudorandom number generator. """ # The default value for **seed** is the result of a function call, which is not # normally recommended and causes ruff to raise a B008 error. However, in this case, ...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/password.py
other/password.py
import secrets from random import shuffle from string import ascii_letters, ascii_lowercase, ascii_uppercase, digits, punctuation def password_generator(length: int = 8) -> str: """ Password Generator allows you to generate a random password of length N. >>> len(password_generator()) 8 >>> len(pa...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/bankers_algorithm.py
other/bankers_algorithm.py
# A Python implementation of the Banker's Algorithm in Operating Systems using # Processes and Resources # { # "Author: "Biney Kingsley (bluedistro@github.io), bineykingsley36@gmail.com", # "Date": 28-10-2018 # } """ The Banker's algorithm is a resource allocation and deadlock avoidance algorithm developed by Edsger Di...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/lfu_cache.py
other/lfu_cache.py
from __future__ import annotations from collections.abc import Callable from typing import TypeVar T = TypeVar("T") U = TypeVar("U") class DoubleLinkedListNode[T, U]: """ Double Linked List Node built specifically for LFU Cache >>> node = DoubleLinkedListNode(1,1) >>> node Node: key: 1, val: 1,...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/maximum_subsequence.py
other/maximum_subsequence.py
from collections.abc import Sequence def max_subsequence_sum(nums: Sequence[int] | None = None) -> int: """Return the maximum possible sum amongst all non - empty subsequences. Raises: ValueError: when nums is empty. >>> max_subsequence_sum([1,2,3,4,-2]) 10 >>> max_subsequence_sum([-2, -3,...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/guess_the_number_search.py
other/guess_the_number_search.py
""" guess the number using lower,higher and the value to find or guess solution works by dividing lower and higher of number guessed suppose lower is 0, higher is 1000 and the number to guess is 355 >>> guess_the_number(10, 1000, 17) started... guess the number : 17 details : [505, 257, 133, 71, 40, 25, 17] """ d...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/magicdiamondpattern.py
other/magicdiamondpattern.py
# Python program for generating diamond pattern in Python 3.7+ # Function to print upper half of diamond (pyramid) def floyd(n): """ Print the upper half of a diamond pattern with '*' characters. Args: n (int): Size of the pattern. Examples: >>> floyd(3) ' * \\n * * \\n* * *...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/alternative_list_arrange.py
other/alternative_list_arrange.py
def alternative_list_arrange(first_input_list: list, second_input_list: list) -> list: """ The method arranges two lists as one list in alternative forms of the list elements. :param first_input_list: :param second_input_list: :return: List >>> alternative_list_arrange([1, 2, 3, 4, 5], ["A", "B"...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/gauss_easter.py
other/gauss_easter.py
""" https://en.wikipedia.org/wiki/Computus#Gauss'_Easter_algorithm """ import math from datetime import UTC, datetime, timedelta def gauss_easter(year: int) -> datetime: """ Calculation Gregorian easter date for given year >>> gauss_easter(2007) datetime.datetime(2007, 4, 8, 0, 0, tzinfo=datetime.ti...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/h_index.py
other/h_index.py
""" Task: Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper, return compute the researcher's h-index. According to the definition of h-index on Wikipedia: A scientist has an index h if h of their n papers have at least h citations each, and the...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/word_search.py
other/word_search.py
""" Creates a random wordsearch with eight different directions that are best described as compass locations. @ https://en.wikipedia.org/wiki/Word_search """ from random import choice, randint, shuffle # The words to display on the word search - # can be made dynamic by randonly selecting a certain number of # words...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/majority_vote_algorithm.py
other/majority_vote_algorithm.py
""" This is Booyer-Moore Majority Vote Algorithm. The problem statement goes like this: Given an integer array of size n, find all elements that appear more than ⌊ n/k ⌋ times. We have to solve in O(n) time and O(1) Space. URL : https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_vote_algorithm """ from collect...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/quine.py
other/quine.py
#!/bin/python3 # ruff: noqa: PLC3002 """ Quine: A quine is a computer program which takes no input and produces a copy of its own source code as its only output (disregarding this docstring and the shebang). More info on: https://en.wikipedia.org/wiki/Quine_(computing) """ print((lambda quine: quine % quine)("print(...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/sdes.py
other/sdes.py
def apply_table(inp, table): """ >>> apply_table("0123456789", list(range(10))) '9012345678' >>> apply_table("0123456789", list(range(9, -1, -1))) '8765432109' """ res = "" for i in table: res += inp[i - 1] return res def left_shift(data): """ >>> left_shift("012345...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/tower_of_hanoi.py
other/tower_of_hanoi.py
def move_tower(height, from_pole, to_pole, with_pole): """ >>> move_tower(3, 'A', 'B', 'C') moving disk from A to B moving disk from A to C moving disk from B to C moving disk from A to B moving disk from C to A moving disk from C to B moving disk from A to B """ if height >=...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/scoring_algorithm.py
other/scoring_algorithm.py
""" | developed by: markmelnic | original repo: https://github.com/markmelnic/Scoring-Algorithm Analyse data using a range based percentual proximity algorithm and calculate the linear maximum likelihood estimation. The basic principle is that all values supplied will be broken down to a range from ``0`` to ``1`` and ...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/greedy.py
other/greedy.py
class Things: def __init__(self, name, value, weight): self.name = name self.value = value self.weight = weight def __repr__(self): return f"{self.__class__.__name__}({self.name}, {self.value}, {self.weight})" def get_value(self): return self.value def get_name...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/doomsday.py
other/doomsday.py
#!/bin/python3 # Doomsday algorithm info: https://en.wikipedia.org/wiki/Doomsday_rule DOOMSDAY_LEAP = [4, 1, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5] DOOMSDAY_NOT_LEAP = [3, 7, 7, 4, 2, 6, 4, 1, 5, 3, 7, 5] WEEK_DAY_NAMES = { 0: "Sunday", 1: "Monday", 2: "Tuesday", 3: "Wednesday", 4: "Thursday", 5: "Frida...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/__init__.py
other/__init__.py
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/lru_cache.py
other/lru_cache.py
from __future__ import annotations from collections.abc import Callable from typing import TypeVar T = TypeVar("T") U = TypeVar("U") class DoubleLinkedListNode[T, U]: """ Double Linked List Node built specifically for LRU Cache >>> DoubleLinkedListNode(1,1) Node: key: 1, val: 1, has next: False, ha...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/graham_scan.py
other/graham_scan.py
""" This is a pure Python implementation of the Graham scan algorithm Source: https://en.wikipedia.org/wiki/Graham_scan For doctests run following command: python3 -m doctest -v graham_scan.py """ from __future__ import annotations from collections import deque from enum import Enum from math import atan2, degrees f...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/activity_selection.py
other/activity_selection.py
"""The following implementation assumes that the activities are already sorted according to their finish time""" """Prints a maximum set of activities that can be done by a single person, one at a time""" # n --> Total number of activities # start[]--> An array that contains start time of all activities # finish[] -->...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/number_container_system.py
other/number_container_system.py
""" A number container system that uses binary search to delete and insert values into arrays with O(log n) write times and O(1) read times. This container system holds integers at indexes. Further explained in this leetcode problem > https://leetcode.com/problems/minimum-cost-tree-from-leaf-values """ class Number...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/other/fischer_yates_shuffle.py
other/fischer_yates_shuffle.py
#!/usr/bin/python """ The Fisher-Yates shuffle is an algorithm for generating a random permutation of a finite sequence. For more details visit wikipedia/Fischer-Yates-Shuffle. """ import random from typing import Any def fisher_yates_shuffle(data: list) -> list[Any]: for _ in range(len(data)): a = rando...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/fractals/julia_sets.py
fractals/julia_sets.py
"""Author Alexandre De Zotti Draws Julia sets of quadratic polynomials and exponential maps. More specifically, this iterates the function a fixed number of times then plots whether the absolute value of the last iterate is greater than a fixed threshold (named "escape radius"). For the exponential map this is not ...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/fractals/mandelbrot.py
fractals/mandelbrot.py
""" The Mandelbrot set is the set of complex numbers "c" for which the series "z_(n+1) = z_n * z_n + c" does not diverge, i.e. remains bounded. Thus, a complex number "c" is a member of the Mandelbrot set if, when starting with "z_0 = 0" and applying the iteration repeatedly, the absolute value of "z_n" remains bounded...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/fractals/sierpinski_triangle.py
fractals/sierpinski_triangle.py
""" Author Anurag Kumar | anuragkumarak95@gmail.com | git/anuragkumarak95 Simple example of fractal generation using recursion. What is the Sierpiński Triangle? The Sierpiński triangle (sometimes spelled Sierpinski), also called the Sierpiński gasket or Sierpiński sieve, is a fractal attractive fixed set with the...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/fractals/__init__.py
fractals/__init__.py
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/fractals/koch_snowflake.py
fractals/koch_snowflake.py
""" Description The Koch snowflake is a fractal curve and one of the earliest fractals to have been described. The Koch snowflake can be built up iteratively, in a sequence of stages. The first stage is an equilateral triangle, and each successive stage is formed by adding outward bends to each side of ...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
TheAlgorithms/Python
https://github.com/TheAlgorithms/Python/blob/2c15b8c54eb8130e83640fe1d911c10eb6cd70d4/fractals/vicsek.py
fractals/vicsek.py
"""Authors Bastien Capiaux & Mehdi Oudghiri The Vicsek fractal algorithm is a recursive algorithm that creates a pattern known as the Vicsek fractal or the Vicsek square. It is based on the concept of self-similarity, where the pattern at each level of recursion resembles the overall pattern. The algorithm involves di...
python
MIT
2c15b8c54eb8130e83640fe1d911c10eb6cd70d4
2026-01-04T14:38:15.231112Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/run_evals.py
backend/run_evals.py
# Load environment variables first from dotenv import load_dotenv load_dotenv() import asyncio from evals.runner import run_image_evals async def main(): await run_image_evals() # async def text_main(): # OUTPUT_DIR = EVALS_DIR + "/outputs" # GENERAL_TEXT_V1 = [ # "Login form", # "Sim...
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/custom_types.py
backend/custom_types.py
from typing import Literal InputMode = Literal[ "image", "video", "text", ]
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/run_image_generation_evals.py
backend/run_image_generation_evals.py
import asyncio import os from typing import List, Optional, Literal from dotenv import load_dotenv import aiohttp from image_generation.core import process_tasks EVALS = [ "Romantic Background", "Company logo: A stylized green sprout emerging from a circle", "Placeholder image of a PDF cover with abstract ...
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/llm.py
backend/llm.py
from enum import Enum from typing import TypedDict # Actual model versions that are passed to the LLMs and stored in our logs class Llm(Enum): GPT_4_VISION = "gpt-4-vision-preview" GPT_4_TURBO_2024_04_09 = "gpt-4-turbo-2024-04-09" GPT_4O_2024_05_13 = "gpt-4o-2024-05-13" GPT_4O_2024_08_06 = "gpt-4o-202...
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/video_to_app.py
backend/video_to_app.py
# Load environment variables first from dotenv import load_dotenv load_dotenv() import base64 import mimetypes import time import subprocess import os import asyncio from datetime import datetime from prompts.claude_prompts import VIDEO_PROMPT from utils import pprint_prompt from config import ANTHROPIC_API_KEY fro...
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/start.py
backend/start.py
import uvicorn if __name__ == "__main__": uvicorn.run("main:app", port=7001, reload=True)
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/main.py
backend/main.py
# Load environment variables first from dotenv import load_dotenv load_dotenv() from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from routes import screenshot, generate_code, home, evals app = FastAPI(openapi_url=None, docs_url=None, redoc_url=None) # Configure CORS settings app.add_m...
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/utils.py
backend/utils.py
import copy import json from typing import List from openai.types.chat import ChatCompletionMessageParam def pprint_prompt(prompt_messages: List[ChatCompletionMessageParam]): print(json.dumps(truncate_data_strings(prompt_messages), indent=4)) def format_prompt_summary(prompt_messages: List[ChatCompletionMessage...
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/config.py
backend/config.py
# Useful for debugging purposes when you don't want to waste GPT4-Vision credits # Setting to True will stream a mock response instead of calling the OpenAI API # TODO: Should only be set to true when value is 'True', not any abitrary truthy value import os NUM_VARIANTS = 4 # LLM-related OPENAI_API_KEY = os.environ.g...
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/mock_llm.py
backend/mock_llm.py
import asyncio from typing import Awaitable, Callable from custom_types import InputMode from llm import Completion STREAM_CHUNK_SIZE = 20 async def mock_completion( process_chunk: Callable[[str, int], Awaitable[None]], input_mode: InputMode ) -> Completion: code_to_return = ( TALLY_FORM_VIDEO_PROM...
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
true
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/fs_logging/core.py
backend/fs_logging/core.py
from datetime import datetime import json import os from openai.types.chat import ChatCompletionMessageParam def write_logs(prompt_messages: list[ChatCompletionMessageParam], completion: str): # Get the logs path from environment, default to the current working directory logs_path = os.environ.get("LOGS_PATH"...
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/fs_logging/__init__.py
backend/fs_logging/__init__.py
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/codegen/test_utils.py
backend/codegen/test_utils.py
import unittest from codegen.utils import extract_html_content class TestUtils(unittest.TestCase): def test_extract_html_content_with_html_tags(self): text = "<html><body><p>Hello, World!</p></body></html>" expected = "<html><body><p>Hello, World!</p></body></html>" result = extract_html_...
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/codegen/utils.py
backend/codegen/utils.py
import re def extract_html_content(text: str): # Use regex to find content within <html> tags and include the tags themselves match = re.search(r"(<html.*?>.*?</html>)", text, re.DOTALL) if match: return match.group(1) else: # Otherwise, we just send the previous HTML over prin...
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/codegen/__init__.py
backend/codegen/__init__.py
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/evals/runner.py
backend/evals/runner.py
from typing import Any, Coroutine, List, Optional, Tuple import asyncio import os from datetime import datetime import time from llm import Llm from prompts.types import Stack from .core import generate_code_for_image from .utils import image_to_data_url from .config import EVALS_DIR async def generate_code_and_time(...
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/evals/core.py
backend/evals/core.py
from config import ANTHROPIC_API_KEY, GEMINI_API_KEY, OPENAI_API_KEY from llm import Llm, ANTHROPIC_MODELS, GEMINI_MODELS from models import ( stream_claude_response, stream_gemini_response, stream_openai_response, ) from prompts import assemble_prompt from prompts.types import Stack from openai.types.chat ...
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/evals/utils.py
backend/evals/utils.py
import base64 async def image_to_data_url(filepath: str): with open(filepath, "rb") as image_file: encoded_string = base64.b64encode(image_file.read()).decode() return f"data:image/png;base64,{encoded_string}"
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/evals/config.py
backend/evals/config.py
EVALS_DIR = "./evals_data"
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/evals/__init__.py
backend/evals/__init__.py
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/tests/test_model_selection.py
backend/tests/test_model_selection.py
import pytest from unittest.mock import AsyncMock from routes.generate_code import ModelSelectionStage from llm import Llm class TestModelSelectionAllKeys: """Test model selection when all API keys are present.""" def setup_method(self): """Set up test fixtures.""" mock_throw_error = AsyncMoc...
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/tests/test_prompt_summary.py
backend/tests/test_prompt_summary.py
import io import sys from utils import format_prompt_summary, print_prompt_summary def test_format_prompt_summary(): messages = [ {"role": "system", "content": "lorem ipsum dolor sit amet"}, { "role": "user", "content": [ {"type": "text", "text": "hello worl...
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/tests/test_prompts.py
backend/tests/test_prompts.py
import pytest from unittest.mock import patch, MagicMock import sys from typing import Any, Dict, List, TypedDict from openai.types.chat import ChatCompletionMessageParam # Mock moviepy before importing prompts sys.modules["moviepy"] = MagicMock() sys.modules["moviepy.editor"] = MagicMock() from prompts import create...
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/tests/test_prompts_additional.py
backend/tests/test_prompts_additional.py
import pytest from unittest.mock import patch, MagicMock import sys from typing import Any, Dict, List, TypedDict from openai.types.chat import ChatCompletionMessageParam # Mock moviepy before importing prompts sys.modules["moviepy"] = MagicMock() sys.modules["moviepy.editor"] = MagicMock() from prompts import create...
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/tests/__init__.py
backend/tests/__init__.py
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/tests/test_screenshot.py
backend/tests/test_screenshot.py
import pytest from routes.screenshot import normalize_url class TestNormalizeUrl: """Test cases for URL normalization functionality.""" def test_url_without_protocol(self): """Test that URLs without protocol get https:// added.""" assert normalize_url("example.com") == "https://example.co...
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false
abi/screenshot-to-code
https://github.com/abi/screenshot-to-code/blob/c4893b3a7072f38f05280df5491846f0f0318306/backend/routes/home.py
backend/routes/home.py
from fastapi import APIRouter from fastapi.responses import HTMLResponse router = APIRouter() @router.get("/") async def get_status(): return HTMLResponse( content="<h3>Your backend is running correctly. Please open the front-end URL (default is http://localhost:5173) to use screenshot-to-code.</h3>" ...
python
MIT
c4893b3a7072f38f05280df5491846f0f0318306
2026-01-04T14:38:17.893599Z
false