Skip to content

Instantly share code, notes, and snippets.

@ripiuk
ripiuk / remove_non_ascii.py
Last active April 1, 2018 14:29
Remove non-ASCII characters
import string
def _remove_non_ascii(text: str):
return ''.join(ch for ch in filter(lambda x: x in string.printable, text)) if isinstance(text, str) else text
_remove_non_ascii('¬äº‹é”æ—店 - 西門店 (台北市) Wonstar - Ximen') # output: ' - () Wonstar - Ximen'
@ripiuk
ripiuk / spotify_get_music_info.py
Last active January 5, 2020 11:16
Parse your spotify music pages and save all the artist, album and song names in the relevant csv files.
"""
requirements: requests-html==0.9.0
runtime: python-3.6
How to use:
1. Download these spotify pages as html source from your browser: albums (https://open.spotify.com/collection/albums),
artists (https://open.spotify.com/collection/artists) and songs (https://open.spotify.com/collection/tracks)
to the relevant directories (scroll all the pages in advance).
2. Enter your local paths to the pages under the constant values (ARTISTS_PAGE_PATH, ALBUMS_PAGE_PATH, SONGS_PAGE_PATH).
3. Run the script.
@ripiuk
ripiuk / send_table_in_gmail.py
Last active March 4, 2023 02:46
Send HTML table as gmail body in Python
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
SENDER_EMAIL = '[email protected]'
SENDER_PASSWORD = 'some_password'
SERVER = 'smtp.gmail.com:587'
RECEIVER_EMAIL = '[email protected]'
SUBJECT = 'BLA-bla'
@ripiuk
ripiuk / statistic_first_kz.py
Created May 30, 2018 21:53
Get probability using triangle distribution, trapezoidal distribution or triangle from trapeze distribution
from math import sqrt
from random import uniform
from decimal import Decimal
c_min = 20
c_max = 125
max_count = 1000000
c1 = 145
c2 = 70
c3 = 80
@ripiuk
ripiuk / scanapi_client.py
Created July 11, 2018 12:49
Pytest mock requests.get() using monkeypatch
import requests
def get_scan_id(url: str) -> int:
"""
Response example:
>>>requests.get('http://.../sequence/v1/generateid?sequenceName=assignments')
{"counter":{"_id":"assignments","seq":401865077},"message":"ok"}
"""
try:
@ripiuk
ripiuk / binary_search.py
Created August 3, 2018 20:23
Binary search implementation with python
import time
from collections import namedtuple
MASS = range(1000000000)
SEARCHED_ITEM = 256879
def binary_search(my_list: list, searched_item: int) -> int or None:
start = 0
end = len(my_list) - 1
@ripiuk
ripiuk / selection_sort.py
Created August 9, 2018 18:18
Selection sort implementation with python
from time import clock
from random import randint
MASS = [randint(0, 9456) for i in range(10000)]
def find_the_smallest_index(mass: list) -> int:
the_smallest_index = 0
for index in range(len(mass)):
if mass[index] < mass[the_smallest_index]:
@ripiuk
ripiuk / factorial.py
Created August 9, 2018 18:53
Factorial calculation implementation with python
from time import clock
from collections import namedtuple
FACTORIAL_NUMBER = 12
def factorial(x: int) -> int:
if x < 1:
raise Exception('The number should be grater than 1')
@ripiuk
ripiuk / selection_vs_quick_sort.py
Created August 9, 2018 19:46
Comparison. Selection sort vs Quick sort. Big O.
from time import clock
from random import randint
from collections import namedtuple
MASS = [randint(0, 9456) for i in range(10000)]
def find_the_smallest_index(mass: list) -> int:
the_smallest_index = 0
for index in range(len(mass)):
@ripiuk
ripiuk / exercise-errors.go
Created January 29, 2019 20:46
go tour exercise (methods/20)
package main
import (
"fmt"
"math"
)
const (
diff = 0.00000001
)