Skip to content

Instantly share code, notes, and snippets.

Dmitry Litvinenko anti1869

Block or report user

Report or block anti1869

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@anti1869
anti1869 / nested_struct_join.go
Created Aug 4, 2018
Join two structs on foreign key relation with jmoiron/sqlx (nested json object from struct)
View nested_struct_join.go
/*
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 Jun 27, 2018
Flushes item into PostgreSQL table with fast upserts
View pg_flusher.py
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 Jul 19, 2017
Memoize for limited number of calls. After that - recalculate and save again
View memoize_times.py
import functools
__all__ = ("memoize", )
MEMOIZE_CACHE = {}
class _memoize(object):
@anti1869
anti1869 / gulpfile.js
Created Apr 25, 2017
example gulpfile
View gulpfile.js
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 Jan 29, 2017
peewee-async.manager.execute(Model.select()) loads everything into memory. Avoid that with this iterator
View iter_select.py
"""
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 Jan 6, 2017
Increment jsonb field by 1 + value in another column using Peewee
View jsonb-increment.py
# 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 Jul 14, 2016
Asynchronous Nano ORM
View nanorm.py
"""
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 Jan 4, 2016
How To Add Colour To Logs And Terminal
View color-logs.py
#!/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 Dec 21, 2015
How To Call Shell Commands From Python In Parallel With Asyncio
View parallel-script.py
#!/usr/bin/env python
"""
Test parallel scripts running with asyncio executors.
Requires at least Python 3.4 to run.
"""
import asyncio
import os
View async_download_publish.py
#!/usr/bin/env python
"""
Playground for mocking asynchronous downloads and later publishing some stuff.
"""
import asyncio
import time
from functools import partial
You can’t perform that action at this time.