Skip to content

Instantly share code, notes, and snippets.

View denisrasulev's full-sized avatar
🙂
Exploring Life

Denis Rasulev denisrasulev

🙂
Exploring Life
View GitHub Profile
@denisrasulev
denisrasulev / progress_bars.py
Created October 27, 2019 17:05
Python progress bars
# Progress Bar 1
import progressbar as pb
widg = ['Processed: ', pb.Counter(), ' lines (', pb.Timer(), ')']
pbar = pb.ProgressBar(widgets=widg)
for i in pbar(content):
some code
# Progress Bar 2
@denisrasulev
denisrasulev / detect_encoding.py
Last active October 6, 2019 08:22
Automatic file encoding detection
import chardet
import pandas as pd
def find_encoding(fname):
r_file = open(fname, 'rb').read()
result = chardet.detect(r_file)
charenc = result['encoding']
return charenc
@denisrasulev
denisrasulev / Multiprocessing.py
Created April 15, 2019 07:48
Multiprocessing using Python 3
#!/usr/bin/env python3
# Importing all needed modules
import multiprocessing
import random
import time
import timeit
print("Starting Multiprocessing...")
import torch
from torch import nn
cl_1 = nn.Conv2d(1, 64, 3)
mp_1 = nn.MaxPool2d(2)
cl_2 = nn.Conv2d(64, 128, 3)
mp_2 = nn.MaxPool2d(2)
cl_3 = nn.Conv2d(128, 512, 3)
# Convolutional neural network (two convolutional layers)
class ConvNet(nn.Module):
def __init__(self):
super(ConvNet, self).__init__()
self.network2D = nn.Sequential(
nn.Conv2d(1, 32, kernel_size=5, stride=1, padding=2),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2),
nn.Conv2d(32, 64, kernel_size=5, stride=1, padding=2),
nn.ReLU(),
@denisrasulev
denisrasulev / Humanize Bytes
Last active January 30, 2019 23:14
Humanize Bytes Function
def humanize_bytes(bytes, precision=1):
"""Return a humanized string representation of a number of bytes.
Assumes `from __future__ import division`.
>>> humanize_bytes(1)
'1 byte'
>>> humanize_bytes(1024)
'1.0 kB'
>>> humanize_bytes(1024*123)
'123.0 kB'
>>> humanize_bytes(1024*12342)
@denisrasulev
denisrasulev / tqdm
Created January 19, 2019 07:01
Progress Bar with tqdm
from tqdm import tqdm
l = ['this', 'is', 'a', 'list']
for word in tqdm(l):
do_something(word)