Skip to content

Instantly share code, notes, and snippets.

View Sukonnik-Illia's full-sized avatar

Illia Sukonnik Sukonnik-Illia

View GitHub Profile
Sukonnik-Illia /
Created January 13, 2022 15:09
Run alembic cli from Python Click
import sys
import click
from alembic.config import main
def cli():
"""Hello cli app"""
Sukonnik-Illia /
Last active August 25, 2023 09:20
Python 3 Json with 2 decimals after comma
# We need to ensure that c encoder will not be launched
@patch('json.encoder.c_make_encoder', None)
def json_dumps_with_two_digit_float(some_object):
# saving original method
of = json.encoder._make_iterencode
def inner(*args, **kwargs):
args = list(args)
# fifth argument is float formater which will we replace
args[4] = lambda o: '{:.2f}'.format(o)
return of(*args, **kwargs)
Sukonnik-Illia /
Created September 21, 2020 14:57
builder with or without db saving and relational objects
# with relational objects and with sawing to database
# simple builder

Keybase proof

I hereby claim:

  • I am sukonnik-illia on github.
  • I am isukonnik ( on keybase.
  • I have a public key ASAfSYx5nDpmqS2A1Wq3o-5Ya9l_V66oohkaU0Snjj2c-Ao

To claim this, I am signing this object:

(defun set-window-width (n)
"Set the selected window's width."
(adjust-window-trailing-edge (selected-window) (- n (window-width)) t))
(defun set-80-columns ()
"Set the selected window to 80 columns."
(set-window-width 80))
(global-set-key (kbd "C-x ~") 'set-80-columns)
Sukonnik-Illia /
Created January 25, 2016 15:47
Python ictionary without empty fields
class DictNoNone(dict):
"""Delete empty fields from dictionary """
def __init__(self, initial_dict={}):
for key in initial_dict:
self.__setitem__(key, initial_dict[key])
def __setitem__(self, key, value):
if key in self or value:
dict.__setitem__(self, key, value)
Sukonnik-Illia /
Created October 5, 2015 15:18
low memory lxml.etree.iterparse
from lxml import etree
def fast_iter(context, func, *args, **kwargs):
""" call func on each xml element chosen when create context
context = etree.iterparse('path to file', tag='your tag', events)
for event, elem in context:
func(elem, *args, *kwargs)