Skip to content

Instantly share code, notes, and snippets.

View westscz's full-sized avatar
🎯
Focusing

Jarosław westscz

🎯
Focusing
View GitHub Profile
{
"basics": {
"name": "Jarosław Piszczała",
"label": "Python Developer",
"email": "[email protected]",
"url": "https://piszczala.pl/",
"location": {
"countryCode": "PL",
"address": "Poland",
"city": "Częstochowa"
from random import random
class Deck:
def __init__(self, cards):
self.cards = cards
def get_deck(self):
"""
Returns the deck 'updated', after shuffling it.
"""
sentence = "Words like herself and researcher also get censored but only her, should her."
new_words = []
for word in sentence.split():
if word.replace(',', "").replace('.', "") == 'her':
word = '***'+word[3:]
new_words.append(word)
new_sentence = " ".join(new_words)
print(new_sentence)
"""
Write a function that will sort a nested dictionary.
If there is list of dicts, sort by 'buzz' key
Extra:
- Make sorting list of dicts easy to extend
- Add rules to not sort some lists
For example:
from time import process_time
def primes(num):
def prim(n):
return len([i for i in range(2, n) if n % i == 0]) == 0
return [i for i in range(2, num) if prim(i)]
def prim(num):
def print_fifth_element(iterable):
passed = False
try:
print(iterable[4])
passed = True
except IndexError:
iterable.append(iterable[-1])
except TypeError:
iterable = [iterable]
except KeyError as e:
class GarageException(Exception):
"""Garage exceptions base"""
class NoSpaceAvailableError(GarageException):
"""Raises when no space available in garage"""
class Vehicle:
size = 0
@westscz
westscz / fib.py
Created February 16, 2020 15:33
fibonacci
from functools import lru_cache
@lru_cache(128)
def fibonaci(n):
if n > 2:
return fibonaci(n-1) + fibonaci(n-2)
if 0 < n <= 2:
return 1
if n == 0:
return 0
def str_to_ascii(s):
chars_to_ascii = [ord(e) for e in s]
reversed_ascii = chars_to_ascii[::-1] #or reversed(chars_to_ascii)
map_to_str = map(lambda x:str(x), reversed_ascii) #wymagane przez join aby kady element był stringiem
return "".join(map_to_str)
def ascii_to_str(s):
result = ""
while s: #póki nie przetworzymy wszystkiego
number_length = 3 if s[0]=='1' else 2 #sprawdzamy czy będzie cyfra 1XX czy 3X, 6-9X
@westscz
westscz / xiaomi_filename_change.py
Created May 26, 2018 08:30
Change filenames for Xiaomi 3S files to format 'yyyy-mm-dd hh-mm-ss'
"""
Change filenames for Xiaomi 3S files to format 'yyyy-mm-dd hh-mm-ss'
"""
import re
import os
def get_new_filename(filename):
result = re.search("\w*_(\d{4})(\d{2})(\d{2})_(\d{2})(\d{2})(\d{2})(?:_\w*?)\.(\w*)", filename)
if result: