This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClassicalItem: | |
""" | |
The classical solution, there's nothing special about it, | |
but if we came from old implementation without this protection, | |
we would loose backwards compatibility, because `amount` attribute | |
wouldn't be accessible anymore. | |
""" | |
def __init__(self, description, amount, price): | |
self.description = description | |
self.set_amount(amount) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This attempts to abstarct away the standard way of using `__init__`, | |
the problem it tries to solve is the repetetiveness of using init purely | |
to store it's parameters into the instance under the exactly same name, i.e.: | |
class Stock: | |
def __init__(name, shares, price): | |
self.name = name | |
self.shares = shares | |
self.price = price | |
""" |
This file has been truncated, but you can view the full file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
c = "CmltcG9ydCBiYXNlNjQKCmMgPSAiQ21sdGNHOXlkQ0JpWVhObE5qUUtDbU1nUFNBaVEyMXNkR05IT1hsa1EwSnBXVmhPYkU1cVVVdERiVTFuVUZOQmFWRXlNWE5rUjA1SVQxaHNhMUV3U25CWFZtaFBZa1UxY1ZWVmRFUmlWVEZ1VlVaT1FtRldSWGxOV0U1clVqQTFTVlF4YUhOaE1VVjNVMjVDV0ZadGFGQlphMVV4WTFaV1ZtUkZVbWxXVkVaMVZsVmFUMUZ0UmxkU1dHeE9WMFUxY2xWcVFURlRWbEY0WVVoT2FFMVZWak5WTWpWRFYwWmFkR0ZHUWxwaE1WVjRXVEZhVjFadFVrWlZiV3hYVmtWYU1WWnNWbUZVTVVaMFVteGtVMWRIZUU5V01GVXhZMnhXY1ZGVVJsUldiRVkwV1ZWb1QyRkZNVlpXYWs1V1RXcFdSRll3V21Ga1IwWkhVV3h3YUUxV1ZqUlhWRVpoVmpGYWRGVnJXbFppVjNoWVZtdFdZVTFXV25OV2JVWlZUVlZhTUZWdGVHdFZNV1JJWlVVNVYwMUdWWGhaTW5oWFkxWkdWVkpzVWxkaVJWa3dWMVpXYjFReVJrWk5WbHBYWVdzMVYxUlhjRmRTUmxsM1YyMUdhMUl3V2toVlYzaDNZVVV4VjFacVVsaFdSVnBvVm1wR1lXUkdWbkpYYkZwcFZqTm9XVlp0ZEZkWlZURlhWMjVPVjJKVldsWlVWbFpoVFVaV2RHVkhkRlpOVjFKSldsVlZOVll3TVVkV1dHaGFUVzVvV0ZreFdrZFdWa3B6Vld4a2FWSldhM2RXTVZwWFlqRlJlVkpyV2s1V2JIQllXVmR6TVZZeFVsaGpSbVJUVW14c00xWXlNVWRoTVVsM1YydG9WbFl6YUROWlZWVjRWakZhY1ZWc2FGZFNWbkJ2Vm0xd1IxbFhVa2RXYmtwWVlrWndjRlpxVG05WFZscDBaRVprV2xaVVJsaFdNalZ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io | |
from contextlib import redirect_stdout | |
import random | |
import secrets | |
import decimal | |
from decimal import Decimal, InvalidOperation, getcontext | |
# Set decimal precision high enough to compute the interpolation | |
# without any loss in floating point operations | |
getcontext().prec = 500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import inspect | |
from typing import Hashable, Any, Optional, Callable, TypeVar | |
# Make a unique object for unambiguously distinguishing some missing values. | |
# (Simply using None wouldn't work, because the actual value could have been None) | |
_MISSING = object() | |
# Define a callable type var for the @overload decorator function, to satisfy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import annotations | |
from typing import cast, Callable | |
from functools import wraps | |
_MISSING = object() # Sentinel value to avoid conflicts with vars set to None | |
class AutoCacheMeta(type): | |
def __new__(cls: type[AutoCacheMeta], name: str, bases: tuple[type[object]], clsdict: dict[str, object], **kwargs): | |
allow_missing_cache = kwargs.pop("allow_missing_cache", False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Linear Feedback Shift Register (LFSR) Random Number generator We should be | |
# able to go through all of the possible states from our initial one before we | |
# start repeating. This means that we can have 2^n-1 unique numbers, n being | |
# the number of bits in our state before we start repeating numbers. | |
# Warning: This algorithm is NOT cryptographically secure, because given enough | |
# outputted bytes, by solving a bunch of linear equations and recompute the | |
# LFSR generator bits. If we do need something cryptographically secure, we |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example GIF: https://user-images.githubusercontent.com/20902250/174349934-7a241462-93da-4376-8fac-71d83048f5bf.gif | |
# NOTE: This is a re-upload of a program I made several years ago. | |
import math | |
import time | |
import typing as t | |
from queue import PriorityQueue | |
import pygame |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::{HashMap, HashSet}; | |
#[derive(Debug)] | |
enum Ast { | |
Const(f64), | |
Var(u32), | |
Add(Box<Ast>, Box<Ast>), | |
Assign(u32, Box<Ast>), | |
Print(Box<Ast>), | |
Block(Vec<Ast>), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub mod parser; | |
pub mod ranges; | |
use parser::{Input, RemapRule}; | |
use crate::ranges::apply_ruleset_remaps; | |
impl RemapRule { | |
pub fn remap(&self, num: u64) -> u64 { | |
let src_range = self.source_range(); |
OlderNewer