Skip to content

Instantly share code, notes, and snippets.

View pavelpy's full-sized avatar
🎯
Focusing

Pavel pavelpy

🎯
Focusing
View GitHub Profile
@pavelpy
pavelpy / is_dates_intersect.py
Created April 4, 2020 14:50
Check intersection of datetime ranges.
def is_dates_intersect(dt1_from, dt1_to, dt2_from, dt2_to):
"""Returns True if there is an intersection of datetime ranges."""
first_condition = (dt1_from <= dt2_from <= dt1_to)
second_condition = (dt2_from <= dt1_from <= dt2_to)
return first_condition or second_condition
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
@pavelpy
pavelpy / transform_xml_using_xslt.py
Last active October 18, 2019 11:39
Transform an XML file using XSLT in Python
import lxml.etree as ET
dom = ET.parse(xml_filename)
xslt = ET.parse(xsl_filename)
transform = ET.XSLT(xslt)
newdom = transform(dom)
print(str(newdom))
1. Книга Эрика Эванса "The Big Blue Book"
https://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215
Порядок чтения: https://twitter.com/renoirb/status/248847526910894081?lang=en
2. Книга Vaughn Vernon "The Red Book"
https://www.amazon.com/Implementing-Domain-Driven-Design-Vaughn-Vernon/dp/0321834577
3. Алексей Мерсон — Domain-driven design: рецепт для прагматика.
Свежий доклад с очень хорошим объяснением деталей. Упор на моделирование.
https://www.youtube.com/watch?v=CR9mLGN9jh0&list=PL48wL0ANkqzTgr6QBblkom0wg7IFXufn0&index=2&t=1990s
@pavelpy
pavelpy / youtube_channel_download.sh
Created March 21, 2019 13:20
Download youtube channel
#!/bin/bash
./youtube-dl --download-archive downloaded.txt -i -o "%(uploader)s/%(upload_date)s - %(title)s - (%(duration)ss) [%(resolution)s].%(ext)s" -f bestvideo[ext=mp4]+bestaudio --batch-file=channel_list.txt
# or
# usage: youtube_channel_download.sh videourl
LOGFILE="$PWD/$(date +"%Y-%m-%d-%H-%M-%S.%N").log"
exec 3>&1 4>&2 >>$LOGFILE 2>&1
youtube-dl --verbose --ignore-errors --no-continue --no-overwrites --keep-video --no-post-overwrites --download-archive archive.txt --write-description --write-info-json --write-annotations --write-thumbnail --all-subs --output "%(uploader)s (%(uploader_id)s)/%(id)s/%(title)s - %(upload_date)s.%(ext)s" -f bestvideo[ext=mp4]+bestaudio[ext=m4a] -- $1
@pavelpy
pavelpy / coursera_fix.py
Created February 15, 2019 13:27
Coursera Fix
raise type("Hello world :) ", (RuntimeError,), {})()
@pavelpy
pavelpy / rotate_2d_array.py
Created January 24, 2019 09:11
Rotate 2d array
rotated = zip(*original[::-1])
@pavelpy
pavelpy / bypass_arguments_in_other_class_methods.py
Created October 10, 2018 11:39
bypass arguments in other class methods
"""
>>> api_instance = BypassApiKey(RemoteServerApi())
>>> api_instance.method_that_need_access_token(1, 2, 3)
[(1, 2, 3), {'access_token': 'test'}]
"""
import functools
ACCESS_TOKEN = 'test'
class RemoteServerApi:
@pavelpy
pavelpy / cron_git_pull.sh
Created October 1, 2018 13:06
Task for cron for check if pull needed in Git
#!/bin/sh
# usage: cron_git_pull.sh [optional_branch_name]
git fetch
UPSTREAM=${1:-'@{u}'}
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse "$UPSTREAM")
BASE=$(git merge-base @ "$UPSTREAM")
if [ $LOCAL = $REMOTE ]; then
echo "Up-to-date"
@pavelpy
pavelpy / lru_cache_for_class_decorator.py
Last active April 11, 2024 08:57
python functools lru_cache with class methods
# origin: https://stackoverflow.com/questions/33672412/python-functools-lru-cache-with-class-methods-release-object
import functools
import weakref
def memoized_method(*lru_args, **lru_kwargs):
def decorator(func):
@functools.wraps(func)
def wrapped_func(self, *args, **kwargs):
# We're storing the wrapped method inside the instance. If we had
# a strong reference to self the instance would never die.