Skip to content

Instantly share code, notes, and snippets.

@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 )
# encoding: utf8
[Base Component]
| # self:constructor(), — очень нужен; если не переопределено, то error("Not implemented")
| # self:render(), — очень нужен; если не переопределено, то error("Not implemented")
|
|-> [Base Field]
| | # self:constructor(), — очень нужен
| | # self:render(), — отрисовка
| |
@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):
@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 / simple-console-video-player.go
Created May 31, 2015 21:22
Простой символьный консольный видео-плеер. Написан с помощью библиотеки GMF https://github.com/3d0c/gmf
// Простой текстовый консольный видео-плеер.
// Выводит кадры в символьном представлении на стандартный вывод.
// Поддержки звука нет.
//
// Как пользоваться:
//
// $> go run simple-console-video-player.go /путь/до/видео-файла.mp4
//
package main
@w495
w495 / simple-console-video-player.py
Created May 17, 2015 22:21
Простой символьный консольный видео-плеер. Написан с помощью библиотеки PyAV http://mikeboers.github.io/PyAV/
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Простой текстовый консольный видео-плеер.
Выводит кадры в символьном представлении на стандартный вывод.
Поддержки звука нет.
Как пользоваться:
@w495
w495 / uploader.py
Last active August 29, 2015 14:21
Very simple API for uploding texts to Old Mediawiki Sites (MediaWiki ~ 1.5). See http://webi.2in2.ru/API:Client_code. It won't work with new versions of MediaWiki. For new versions use http://www.mediawiki.org/wiki/API:Client_code
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
import requests
import json
import copy
def get_in_dict(dict_, path):
@w495
w495 / dict_list_sum_groupby.py
Last active August 29, 2015 14:14
Реализация `select sum(...) fom group by ...` на Python. На вход подается список словарей, и списки полей (всех, и по которым нужно суммировать).
from itertools import groupby
def dlist_sum_group(
target_dlist,
groupby_field_list = [],
sum_field_list = [],
field_list = [],
convert = tolong,
):
return dlist_agregate_group(
@w495
w495 / big-sharded-db.sql
Last active August 29, 2015 14:12
Пример того, как можно конструировать SQL запросы во время выполнения. Скрипт делает выборку из шардированной базы данных. Выборка выполняется за один запрос.
set session group_concat_max_len = 9223372036854775807;
set @expr = (
select
group_concat(
concat(
'C.Expression REGEXP "P',PatternID, '[^0-9]"'
)
SEPARATOR ' or '
)
{% load i18n %}
{% load i18n admin_urls admin_static admin_list %}
{{ spec.form.media }}
{% block extrahead %}
<style>
.calendarbox {
margin-left: -200px;