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 random | |
import matplotlib.pyplot as plt | |
import numpy as np | |
class Point: | |
def __init__(self, x, y): | |
self.x = x | |
self.y = y |
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 functools import partial | |
from pathlib import Path | |
import re | |
REGEX_REPLACE = 'cow' | |
PATH = r'C:\Users\Yam' | |
DRY = 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
import re | |
PATH = r"C:\Projects\Notebooks\week4\resources\alice.txt" | |
with open(PATH, 'rb') as f: | |
text = f.read() | |
new_text = re.sub(br'[^a-zA-Z0-9_ ?!@#$%^&*\(\)+.,></\\[\]\n\r-]', br'', text) | |
with open(PATH, 'w') as f: |
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
flake8 | egrep .+?\:.+?:.+?:.+? | cut -d: -f1 | sort | uniq -c | sort -nr | head -n50 | awk ' { cmd = "git ls-tree -r -z --name-only HEAD -- " $2 " | xargs -0 -n1 git blame --line-porcelain HEAD |grep -oP \"^author \\K(.+)\"|sort|uniq -c|sort -nr|head -n1"; topDestroy = ((cmd | getline line) > 0 ? line : "failed"); close(cmd); print $1 "\t" $2 "\t" topDestroy; } ' | column -ts $'\t' |
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
MORSE_TRANSLATION = { | |
".-": "A", | |
"-...": "B", | |
"-.-.": "C", | |
"-..": "D", | |
".": "E", | |
"..-.": "F", | |
"--.": "G", | |
"....": "H", | |
"..": "I", |
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 itertools | |
from typing import (Sequence, Iterable, Iterator, | |
Union, Optional, | |
List, NamedTuple) | |
ALLOWED_OPERATORS = ('*', '/', '+', '-') # , '**) | |
REPEAT_NUMBERS = False | |
DigitsSequence = Union[str, Sequence[Union[str, int]]] | |
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 itertools | |
import string | |
import requests | |
STATES_URL = 'http://www.wefeelfine.org/data/files/states.txt' | |
KEYBOARD_ROWS = ('qwertyuiop', 'asdfghjkl', 'zxcvbnm') | |
KEYBOARD = tuple(map(set, KEYBOARD_ROWS)) | |
STATES = tuple(map(set, requests.get(STATES_URL).text.splitlines())) | |
assert set(string.ascii_lowercase) == set(''.join(KEYBOARD_ROWS)) |
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 random | |
import matplotlib.pyplot as plt | |
NUMBER_OF_ROUNDS = 10000 | |
POT_LIMIT = 500 | |
INITIAL_CASH_IN_HAND = 500 # Dollars | |
IS_ABLE_TO_OVERDRAFT = True | |
NUMBERS_IN_ROULETTE = 36 # 1 will be added to represent 0. | |
STARTING_BET_SIZE = 1 | |
BET_MULTIPLICATION_FACTOR = 2 |
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
GIVEN_CLUES = ( | |
# Number, bulls, cows | |
('073', 1, 0), | |
('041', 0, 1), | |
('360', 0, 2), | |
('827', 0, 0), | |
('786', 0, 1) | |
) | |
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 requests | |
def to_hex(decimal, padding=0, upper=False): | |
assert isinstance(decimal, int) | |
hex_part = hex(decimal).split("x")[1] | |
if padding and len(hex_part) < padding: | |
hex_part = "0"*(padding - len(hex_part)) + hex_part | |
if upper: | |
hex_part = hex_part.upper() |