Skip to content

Instantly share code, notes, and snippets.

View worldmind's full-sized avatar

Alexey Shrub worldmind

View GitHub Profile
@worldmind
worldmind / asizeoflistds.py
Created October 9, 2019 13:20
Comparing of tuple, lis, array memory using
from array import array
from pympler.asizeof import asizeof
SIZE = 1000
the_array = array('i')
the_list = []
for_tuple = []
@worldmind
worldmind / url_compose.py
Last active September 25, 2019 14:11
Python Url type
from urllib.parse import quote, urlencode, ParseResult as Url
Url.__str__ = Url.geturl
bucket_name = 'something_with space'
file_name = 'data.txt'
url = Url(
scheme='https',
@worldmind
worldmind / muller_recurrence.py
Created September 17, 2019 14:14
Muller's recurrence
from decimal import Decimal
from fractions import Fraction
def muller_recurrence(y, z):
return 108 - ((815-1500/z)/y)
N = 25
@worldmind
worldmind / grace_stop.py
Created July 8, 2019 16:25
Multiprocessing graceful stop by SIGTERM
from time import sleep
import signal
import multiprocessing as mp
_SIGTERM = None
def sigterm_handler(signum, frame):
global _SIGTERM
import numpy as np
import pandas as pd
from sklearn.model_selection import GridSearchCV, train_test_split
from sklearn.metrics import roc_auc_score, precision_score, recall_score, f1_score, accuracy_score
import torch
from torch import nn, tensor, optim
from skorch import NeuralNetClassifier
def get_data():
@worldmind
worldmind / five_factor_test.py
Created June 11, 2019 12:44
Most science based 5 factor psychology test :)
from math import ceil, floor
import numpy as np
LEVELS = 10
CENTER = int(LEVELS/2)
FACTORS = [
'Agreeableness',
'Conscientiousness',
'Extraversion',
@worldmind
worldmind / loop_scope.py
Created April 3, 2019 06:55
Loop scope
def main():
y = 0
for k in range(1,3):
z = k
def inside_main():
print(y)
print(z)
print(k)
inside_main()
@worldmind
worldmind / testcase_assert_not_raises.py
Last active January 25, 2019 08:01
Python unittest: Testing an exception is not raised
import sys
import unittest
from contextlib import contextmanager
@contextmanager
def assert_not_raises(self, exc_type):
try:
yield None
except exc_type:
@worldmind
worldmind / objects_size.py
Created December 20, 2018 15:43
Ugly script for comparing objects with/without __slots__
from pympler import asizeof
def list_to_str(lst):
str = ''
for val in lst:
str = str + val + ', '
return str[0:len(str)-2]
@worldmind
worldmind / test2.py
Last active December 20, 2018 11:46
Compare object sizes in python 3.6
from pympler import asizeof
class Coordinates():
def __init__(self, x, y):
self.x = x
self.y = y
class CoordinatesSlots():
__slots__ = ('x', 'y')