Skip to content

Instantly share code, notes, and snippets.

@yammesicka
yammesicka / DigitalWhisperDownloader.py
Last active May 17, 2016 19:23
Digital Whisper - Download all issues.
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()
@yammesicka
yammesicka / safe_opener.py
Last active January 28, 2017 04:12
Safe opener - trying to take the fun from spamming Facebook with useless riddles :(
GIVEN_CLUES = (
# Number, bulls, cows
('073', 1, 0),
('041', 0, 1),
('360', 0, 2),
('827', 0, 0),
('786', 0, 1)
)
@yammesicka
yammesicka / bad_martingale.py
Last active February 3, 2017 10:45
Show that Martingale doesn't work.
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
@yammesicka
yammesicka / states_single_row.py
Last active August 9, 2017 08:29
Which states can be spelled out using a single keyboard row
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))
@yammesicka
yammesicka / DigitsSolver.py
Last active September 9, 2017 11:46
A solution for "use the following digits and basic operators to get the result X"
import itertools
from typing import (Sequence, Iterable, Iterator,
Union, Optional,
List, NamedTuple)
ALLOWED_OPERATORS = ('*', '/', '+', '-') # , '**)
REPEAT_NUMBERS = False
DigitsSequence = Union[str, Sequence[Union[str, int]]]
@yammesicka
yammesicka / morse_bruteforce.py
Created October 2, 2018 01:47
Morse code bruteforce
MORSE_TRANSLATION = {
".-": "A",
"-...": "B",
"-.-.": "C",
"-..": "D",
".": "E",
"..-.": "F",
"--.": "G",
"....": "H",
"..": "I",
@yammesicka
yammesicka / blame.sh
Created July 10, 2019 10:10
How ruined my Python repo (flake8 + git)
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'
@yammesicka
yammesicka / convert_txt.py
Last active November 16, 2019 05:42
Delete unwanted characters from txt files, and convert them to valid text files
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:
@yammesicka
yammesicka / mass_filename_changer.py
Last active April 27, 2020 17:44
Mass filename changer (using regex, case sensitivity included)
from functools import partial
from pathlib import Path
import re
REGEX_REPLACE = 'cow'
PATH = r'C:\Users\Yam'
DRY = False
@yammesicka
yammesicka / chaos_game.py
Last active June 4, 2020 04:15
Yam's Chaos game
import random
import matplotlib.pyplot as plt
import numpy as np
class Point:
def __init__(self, x, y):
self.x = x
self.y = y