Skip to content

Instantly share code, notes, and snippets.

View sancau's full-sized avatar

Alexander Tatchin sancau

View GitHub Profile
@sancau
sancau / excel_series_to_datetime.py
Last active October 31, 2016 13:49
Parsing excel timestamp format with Python
EXCEL_TIME = 42607.5234143519
# way 1
import datetime
def xldate_as_datetime(xldate, datemode):
# datemode: 0 for 1900-based, 1 for 1904-based
return (
datetime.datetime(1899, 12, 30)
+ datetime.timedelta(days=xldate + 1462 * datemode)
)
@sancau
sancau / dbms_interaction.py
Created January 20, 2017 09:40
DBMS interaction cases (ORACLE, POSTGRESQL, SQLACLHEMY)
# RAW CX_ORACLE
import cx_Oracle
import os
DB_USERNAME = '...'
DB_PASSWORD = '...'
DB_SID = '...' # basicaly a schema
DB_IP = '...'
DB_PORT = int
@sancau
sancau / cx_oracle.md
Last active February 6, 2017 12:21 — forked from kimus/cx_oracle.md
Installing python cx_oracle on Ubuntu

First of all, it just seems like doing anything with Oracle is obnoxiously painful for no good reason. It's the nature of the beast I suppose. cx_oracle is a python module that allows you to connect to an Oracle Database and issue queries, inserts, updates..usual jazz.

Linux

Step 1:

sudo apt-get install build-essential unzip python-dev libaio-dev

Step 2. Click here to download the appropriate zip files required for this. You'll need:

@sancau
sancau / animated_3d_histogram.py
Created February 7, 2017 13:59
Example of building animated 3D histogram with Python (Python 3.6 used)
# coding=utf-8
# github.com/sancau
from collections import Counter
from collections import namedtuple
from random import randint
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as p3
@sancau
sancau / pipeline.py
Created March 22, 2017 16:46
Simple class for building async / blocking execution pipelines
# coding=utf-8
"""
Minimalistic util for building async pipelines of functions in Python
(c) github.com/sancau
"""
from multiprocessing.dummy import Pool as ThreadPool
from multiprocessing import Pool as ProcessPool
@sancau
sancau / gist:907da9d1593702f3077daa791938e039
Last active March 30, 2017 07:58
Totaly and recursively shared directory in Linux (even for newly created files and dirs)
!# /bin/sh
sudo mkdir /shared
sudo chmod a+rwxs /shared
sudo setfacl -d -m o:rwx /shared
@sancau
sancau / task.md
Last active December 18, 2018 21:52
Test task (Python)

Тестовое задание (разработчик Python)

Есть файл Excel содержащий следующий набор данных:

  • Список URL, колонка "url"
  • Текстовые метки, колонка "label"
  • Сооветствующие каждой URL флаги, колонка "fetch" (ИСТИНА или ЛОЖЬ)

Требуется реализовать скрипт который:

@sancau
sancau / script.sh
Created July 31, 2018 15:59
Allow to choose specific pipenv kernel in Jupyter
pipenv shell
pipenv install ipykernel
python -m ipykernel install --user --name=VENV_NAME
jupyter lab
@sancau
sancau / comparator.ipynb
Created October 26, 2018 08:31
Windowed comparison in Pandas
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sancau
sancau / df_sparse.py
Created December 18, 2018 21:44
Sparse pd.DataFrame
data = [
['User', 'Content Type', 'File', 'Mb'],
['User 1', 'Text', 'F1', 0.1],
['User 1', 'Text', 'F2', 0.5],
['User 1', 'Video', 'V1', 100],
['User 2', 'Text', 'F1', 2],
['User 2', 'Video', 'V1', 75],
['User 3', 'Video', 'V2', 60],
]