Skip to content

Instantly share code, notes, and snippets.

@gruzovator
gruzovator / inotify_monitor.cpp
Last active July 18, 2016 19:36
inotify files modifications monitor
/** files modifications monitoring via inotify
Attention: inotify monitoring of a file have some problems.
E.g. some editors rm then creates files with sthe same name when editing.
So, it's a more robust to monitor entire dir
*/
#include <iostream>
#include <string>
#include <functional>
#include <stdexcept>
//ldflags="-lboost_filesystem -lboost_system"
#include <iostream>
#include <locale>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <boost/utility/string_ref.hpp>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" задачка """
a = [1,2,3]
def aggregator(accum, item):
""" пример ф-ции 'аккумулятора' для обработки части данных в распределённом фрейморке
@gruzovator
gruzovator / pagination_model.py
Last active December 17, 2016 10:27
pagination for periodically updated collection of sorted docs
# coding: utf-8
"""
Pagination model for sorted docs collection, that is periodically updated.
The key ideas:
- all docs have sequential id
- docs are sorted by composite key (weight, sequential id)
- response to page request containse 'next_offset' (a composite key) that should be used to get next page
"""
@gruzovator
gruzovator / struct_meta.py
Last active December 28, 2016 07:56
structure metaclass
from types import NoneType
class Field(object):
def __init__(self, expected_types, *default):
self.name = None # set by metaclass
self.internal_name = None # set by metaclass
self.expected_types = expected_types
if default:
self.default = default[0]
@gruzovator
gruzovator / schema-partitioning-1.sql
Last active August 3, 2020 16:15
postgres partition by month exmaple
-- partition by month
-- https://www.postgresql.org/docs/9.5/static/ddl-partitioning.html
begin;
drop trigger if exists insert_master_trigger on master;
drop function if exists master_insert();
drop table if exists master cascade;
create table master(
id bigserial primary key,
@gruzovator
gruzovator / schema-partitioning-2.sql
Created March 4, 2017 08:45
posrgresql partition by seq id
-- partition by month
-- https://www.postgresql.org/docs/9.5/static/ddl-partitioning.html
begin;
drop trigger if exists insert_master_trigger on master;
drop function if exists master_insert();
drop table if exists master cascade;
create table master(
id bigserial primary key,
@gruzovator
gruzovator / translit.cpp
Created March 17, 2017 06:18
icu translit sketch
#include <unicode/translit.h>
class TranslitConverter
{
static const UnicodeString TRANSLITERATION_RULES;
public:
TranslitConverter()
{
UErrorCode status = U_ZERO_ERROR;
LOCATIONS = """
country
UK
city
London
Guildford
county
Surray
Sussex
Belgium
package main
import (
"encoding/json"
"errors"
"fmt"
"github.com/go-redis/redis"
"log"
"reflect"
)