Skip to content

Instantly share code, notes, and snippets.

View pschanely's full-sized avatar

Phillip Schanely pschanely

View GitHub Profile
@pschanely
pschanely / main.py
Created December 19, 2025 17:00
Shared via CrossHair Playground
from dataclasses import dataclass
class HasConsistentHash:
'''
A mixin to enforce that classes have hash methods that are consistent
with thier equality checks.
'''
def __eq__(self, other: object) -> bool:
'''
post: implies(__return__, hash(self) == hash(other))
@pschanely
pschanely / main.py
Created December 18, 2025 10:27
Shared via CrossHair Playground
def make_bigger(n: int) -> int:
'''
post: __return__ != 0
'''
return 2 * n + 10
@pschanely
pschanely / main.py
Created December 12, 2025 07:35
Shared via CrossHair Playground
def make_bigger(n: int) -> int:
'''
post: __return__ %2 == 0
'''
sum = 0
for i in range(n):
sum += 2
return sum
@pschanely
pschanely / main.py
Created December 12, 2025 06:58
Shared via CrossHair Playground
from typing import List
def average(numbers: List[float]) -> float:
'''
pre: len(numbers) > 0
post: min(numbers) <= __return__ <= max(numbers)
'''
return sum(numbers) / len(numbers)
@pschanely
pschanely / main.py
Created December 11, 2025 13:52
Shared via CrossHair Playground
from dataclasses import dataclass
class HasConsistentHash:
'''
A mixin to enforce that classes have hash methods that are consistent
with thier equality checks.
'''
def __eq__(self, other: object) -> bool:
'''
post: implies(__return__, hash(self) == hash(other))
@pschanely
pschanely / main.py
Created December 10, 2025 17:37
Shared via CrossHair Playground
def make_bigger(n: int) -> int:
'''
post: __return__ % 2 == 0
'''
sum = 0
for i in range(n):
sum += 2
return sum
@pschanely
pschanely / main.py
Created November 28, 2025 12:47
Shared via CrossHair Playground
def make_bigger(n: int) -> int:
'''
post: __return__ != 0
'''
return 2 * n + 10
@pschanely
pschanely / main.py
Created November 26, 2025 12:30
Shared via CrossHair Playground
import dataclasses
from typing import List
@dataclasses.dataclass
class AverageableQueue:
'''
A queue of numbers with a O(1) average() operation.
inv: self._total == sum(self._values)
'''
_values: List[int]
@pschanely
pschanely / main.py
Created November 16, 2025 19:43
Shared via CrossHair Playground
import dataclasses
from typing import List
@dataclasses.dataclass
class AverageableQueue:
'''
A queue of numbers with a O(1) average() operation.
inv: self._total == sum(self._values)
'''
_values: List[int]
@pschanely
pschanely / main.py
Created November 15, 2025 03:03
Shared via CrossHair Playground
def make_bigger(n: int) -> int:
'''
post: __return__ != 0
'''
return 2 * n + 10