This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
class OneLineHandler(logging.StreamHandler): | |
def emit(self, record): | |
try: | |
msg = self.format(record) | |
stream = self.stream | |
stream.write('\u001b[1000D' + msg) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf8 -*- | |
import av | |
# Откроем ресурс на чтение | |
input_resource = av.open( | |
'rtmp://src_stream:1935/play' | |
) | |
# Откроем ресурс на запись. | |
output_resource = av.open( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
From http://harkablog.com/inside-the-django-orm-aggregates.html | |
with a couple of fixes. | |
Usage: MyModel.objects.all().annotate(new_attribute=GroupConcat('related__attribute', separator=':') | |
""" | |
from django.db.models import Aggregate | |
from django.db.models.sql.aggregates import Aggregate as SQLAggregate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf8 -*- | |
from __future__ import absolute_import, division, print_function | |
import socket | |
from urlparse import urlparse | |
class DnsResolverMiddleware(object): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from apps.genapi import models | |
class RegionTreeManager(models.Manager): | |
def handle_qs(self, qs): | |
not_detailed_query = "not find_in_set('detailed', Options)" | |
not_deleted_query = "not find_in_set('deleted', Options)" | |
qs = qs.extra(where=[not_detailed_query, not_deleted_query]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% !TeX encoding = UTF-8 | |
\ProvidesPackage{bashline}[2016/10/24 v. 0.1] | |
\makeatletter | |
\newcommand{\bashline@file@name}[1]{% | |
/tmp/${USER}-${HOSTNAME}-\jobname-#1.tex% | |
} | |
\newread\bashline@file | |
\newcommand{\bashline@command@one}[2][tmp]{% | |
\immediate\write18{#2 > \bashline@file@name{#1}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from __future__ import absolute_import, division, print_function | |
import lxml.etree as et | |
import six | |
def dumps(data): | |
name = data.keys()[0] | |
value = data[name] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
import multiprocessing as mp | |
from concurrent.futures import ProcessPoolExecutor, as_completed | |
from .base_extractor import BaseExtractor | |
class ParallelExtractor(BaseExtractor): | |
POOL_SIZE = mp.cpu_count() | |
IMAGE_GROUP_SIZE = 512 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import av | |
from av.video.frame import VideoFrame | |
from av.video.stream import VideoStream | |
# В этом списке будем хранить кадры в виде numpy-векторов. | |
array_list = [] | |
# Откроем контейнер на чтение | |
input_container = av.open('input.mp4') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 2.* only. For Python 3.* please use concurrent.futures.ProcessPoolExecutor | |
def map_parallel_pymp(obj_list, filter_list, **kwargs): | |
""" | |
Applies several filters from filter_seq | |
to video frames from obj_seq in parallel manner | |
using pymp (OpenMP for Python). | |
Under construction |