Skip to content

Instantly share code, notes, and snippets.

View anti1869's full-sized avatar

Dmitry Litvinenko anti1869

View GitHub Profile
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fssp="http://www.fssprus.ru/namespace/incoming/2019/1" targetNamespace="http://www.fssprus.ru/namespace/incoming/2019/1" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:simpleType name="DAccountType">
<xs:annotation>
<xs:documentation>номер счета в кредитной организации</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:maxLength value="20"/>
</xs:restriction>
</xs:simpleType>
@anti1869
anti1869 / nested_struct_join.go
Created August 4, 2018 19:27
Join two structs on foreign key relation with jmoiron/sqlx (nested json object from struct)
/*
Note: I have db.MapperFunc(FromCamelCaseToUnderScore)
This will make nested json like this
{
"likes": [
{
"chat_id": 155636374,
"created": "2018-08-04T10:52:36.360217Z",
@anti1869
anti1869 / pg_flusher.py
Created June 27, 2018 08:10
Flushes item into PostgreSQL table with fast upserts
import logging
from typing import Any, Dict, Optional, Sequence, Tuple, List
import simplejson as json
from psycopg2 import IntegrityError
from django.core.serializers.json import DjangoJSONEncoder
from django.db import connection
from django.db.utils import ProgrammingError
@anti1869
anti1869 / memoize_times.py
Created July 19, 2017 12:19
Memoize for limited number of calls. After that - recalculate and save again
import functools
__all__ = ("memoize", )
MEMOIZE_CACHE = {}
class _memoize(object):
@anti1869
anti1869 / gulpfile.js
Created April 25, 2017 07:41
example gulpfile
const gulp = require('gulp');
const stylus = require('gulp-stylus');
const sourcemaps = require('gulp-sourcemaps');
const seq = require('gulp-sequence');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const del = require('del');
gulp.task('clean', (clb) => {
return del(['./dist/**/*'], clb);
@anti1869
anti1869 / iter_select.py
Created January 29, 2017 14:44
peewee-async.manager.execute(Model.select()) loads everything into memory. Avoid that with this iterator
"""
peewee-async.manager.execute(Model.select()) loads everything into memory. Avoid that with this iterator
Usage::
q = Item.select()
async for item in IterSelect(manager_instance, q):
print(item.id)
DISCLAIMERS: Untested and seems slow
@anti1869
anti1869 / jsonb-increment.py
Created January 6, 2017 20:28
Increment jsonb field by 1 + value in another column using Peewee
# Suppose table like this
#
# item
# ----
# like_count INTEGER
# snippet JSONB
#
# You want 'like_count' key in snippet also
# and now there is a time to increment
@anti1869
anti1869 / nanorm.py
Last active July 14, 2016 07:22
Asynchronous Nano ORM
"""
Some kind of Nano-ORM. Just playing along
"""
import asyncio
from collections import OrderedDict
import logging
import re
from motor import motor_asyncio
@anti1869
anti1869 / color-logs.py
Created January 4, 2016 10:41
How To Add Colour To Logs And Terminal
#!/usr/bin/env python
"""
Colour logs, printing colour escape codes and some ASCII.
You need to ``pip install colorlog`` to run this.
"""
import logging
from logging.config import dictConfig
@anti1869
anti1869 / parallel-script.py
Created December 21, 2015 19:28
How To Call Shell Commands From Python In Parallel With Asyncio
#!/usr/bin/env python
"""
Test parallel scripts running with asyncio executors.
Requires at least Python 3.4 to run.
"""
import asyncio
import os