Skip to content

Instantly share code, notes, and snippets.

View nokados's full-sized avatar
🦄
Unicorn shepherd

Nikita Furin nokados

🦄
Unicorn shepherd
  • CraftTalk
  • Moscow, Russia
View GitHub Profile
@nokados
nokados / bind.py
Created August 27, 2018 12:06
method that allows to bind some function or method to the current class
def bind(self, method):
def new_method(new_self, *args, **kwargs):
new_self.data = method(self.data, *args, **kwargs)
return new_self
setattr(self, method.__name__, types.MethodType(new_method, self))
import json, requests, time
import datetime
import pickle
from collections import Counter
from pyquery import PyQuery
from readability import Document
from lxml.etree import XMLSyntaxError, LxmlError
from readability.readability import Unparseable
from requests.adapters import MaxRetryError
from requests.exceptions import ConnectionError
@nokados
nokados / pandas_jupyter_paginator.py
Last active June 17, 2022 04:23
Paginator for pandas.DataFrame in Jupyter Notebook. UPD: use https://github.com/nvictus/pandas-jupyter-paginate instead
from IPython.core.display import display, HTML, clear_output
from ipywidgets import widgets, Layout
import math
PAGESIZE=10
class Paginator:
def __init__(self, df, pagesize = PAGESIZE, start_page = 0):
self.df = df
self.pagesize = pagesize
self.page = start_page
@nokados
nokados / jupyter.service
Last active March 31, 2020 12:48 — forked from whophil/jupyter.service
A systemd script for running a Jupyter notebook server.
# After Ubuntu 16.04, Systemd becomes the default.
# It is simpler than https://gist.github.com/Doowon/38910829898a6624ce4ed554f082c4dd
[Unit]
Description=Jupyter Notebook
[Service]
Type=simple
PIDFile=/run/jupyter.pid
ExecStart=/home/nokados/anaconda3/bin/jupyter-notebook --config=/home/nokados/.jupyter/jupyter_notebook_config.py --no-browser
@nokados
nokados / multilabel_stratified_train_test_split.py
Last active March 8, 2019 14:57
Analogue of sklearn's train_test_split for multilabel classification with stratification and shuffling. And also under/over sampling to make distributions of class lengths more flat.
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
def parallel_shuffle(*arrays):
length = arrays[0].shape[0]
for arr in arrays:
assert arr.shape[0] == length
p = np.random.permutation(length)
@nokados
nokados / gdrive.py
Created February 28, 2019 00:34
Download large files from Google Drive
import requests
def download_file_from_google_drive(id, destination):
def get_confirm_token(response):
for key, value in response.cookies.items():
if key.startswith('download_warning'):
return value
return None