Skip to content

Instantly share code, notes, and snippets.

@w495
w495 / graphite-log-parser.py
Last active November 11, 2015 13:12
Graphite log simple parser for enhancing functions' calls and its' arguments from nginx log.
# -*- coding: utf8 -*-
#
# Graphite log simple parser.
# It parse functions and its arguments using python ast-tree.
#
# For each log line like:
# {
# 192.168.14.20 [23/Jul/2015:15:44:11 +0100]
# "GET /render?from=-4hours&noCache=True&hideLegend=False
@w495
w495 / sliding_window.py
Last active January 20, 2021 18:19
Sliding window as deque. Yet another implementation of sliding (rolling) window iterator in Python. This is based on answers of http://stackoverflow.com/questions/6822725/rolling-or-sliding-window-iterator-in-python. It is improved with "overlapping" and two window types: soft and strict.
# -*- coding: utf8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
import collections
import types
import itertools
class SlidingWindow(collections.deque):
# encoding: utf8
[Base Component]
| # self:constructor(), — очень нужен; если не переопределено, то error("Not implemented")
| # self:render(), — очень нужен; если не переопределено, то error("Not implemented")
|
|-> [Base Field]
| | # self:constructor(), — очень нужен
| | # self:render(), — отрисовка
| |
@w495
w495 / find_cycles_in_list.cpp
Created June 27, 2016 12:25
find_cycles_in_list.cpp
#include <iostream>
#include <set>
struct node{
int id;
node* next;
};
void func ( node* head )
# 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
@w495
w495 / pyav_example.py
Last active June 15, 2019 21:20
Пример работы с видео в Python. В примере из видео достают кадры и конвертируют их в numpy-вектора размером `32 X 32`. После из полученных векторов собирают новое видео. Создано по мотивам http://ru.stackoverflow.com/questions/519636/#551344
import av
from av.video.frame import VideoFrame
from av.video.stream import VideoStream
# В этом списке будем хранить кадры в виде numpy-векторов.
array_list = []
# Откроем контейнер на чтение
input_container = av.open('input.mp4')
@w495
w495 / process_pool_executor_example.py
Last active April 21, 2017 00:30
Example for concurrent.futures.ProcessPoolExecutor. One of the key ideas to use `as_completed` to get un-ordered result. If a sequence order is import, you should sort result by yourself. This is part of https://github.com/w495/python-video-shot-detector
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
@w495
w495 / dict_to_xml.py
Created October 10, 2016 16:42
Dumps python dict to xml string. Current example is suitable for dumping OVS-XML format from python dictionay
# -*- 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]
@w495
w495 / bashline.sty
Last active October 24, 2016 22:13
bashline.sty — simple implementation of command line calls for [Xe]LaTeX.
% !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}}
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])