Skip to content

Instantly share code, notes, and snippets.

View wellic's full-sized avatar

Valerii Savchenko wellic

View GitHub Profile
@wellic
wellic / nested_flatten_dict.py
Created September 26, 2019 13:25
Nested dict <-> path (flatten dict)
import json
SEPARATOR = '/'
def encode_value(value):
return json.dumps(value, indent=2, sort_keys=True)
def decode_value(item_value):
if hasattr(item_value, 'decode'):
item_value = item_value.decode()
@wellic
wellic / js_vars
Created November 6, 2019 12:04
Add env vars to js applications
1) Способ доставки в приложение любых переменных в яваскрипт
https://www.simonewebdesign.it/how-to-get-environment-variables-in-the-browser/
2) А это как применить красиво
https://engineering.contaazul.com/handling-environment-variables-in-the-browser-bbde35661798
Идея:
1) генерим любым способом json-файл vars.js вида:
window.my_vars = {
v1: ...,
v2: ...
@wellic
wellic / git-apply-patch.md
Created February 12, 2020 08:24 — forked from emmanueltissera/git-apply-patch.md
Generate a git patch for a specific commit

Creating the patch

git format-patch -1 <sha>
OR
git format-patch -1 HEAD

Applying the patch

git apply --stat file.patch # show stats.
git apply --check file.patch # check for error before applying

@wellic
wellic / foo.log
Created February 21, 2020 08:51 — forked from ibeex/foo.log
Flask logging example
A warning occurred (42 apples)
An error occurred
//create bookmark with name dev_mode:
//add to url code:
//javascript:n='var_anyname_dev_mod'; v=document.cookie.match('(^|; )'+n+'=([^;]+)'); document.cookie=n+'='+(v?';path=/;expires='+(new Date(0)).toGMTString()+';':'1;path=/;');window.location.reload();
n='var_anyname_dev_mod';
v=document.cookie.match('(^|; )'+n+'=([^;]+)');
document.cookie=n+'='+(v?';path=/;expires='+(new Date(0)).toGMTString()+';':'1;path=/;');
window.location.reload();
@wellic
wellic / gmail-github-filters.md
Created April 15, 2020 14:08 — forked from ldez/gmail-github-filters.md
Gmail and GitHub - Filters

Gmail and GitHub

Create new filters and create new labels.

Pull Request

from:([email protected]) AND {"Patch Links" "approved this pull request." "requested changes on this pull request." "commented on this pull request." "pushed 1 commit." "pushed 2 commits." "pushed 3 commits."}

label: gh-pull-request

@wellic
wellic / dict_merge.py
Last active April 18, 2020 11:00 — forked from drts01/dict_merge.py
Recursive dictionary merge in Python
# Recursive dictionary merge
# Copyright (C) 2016 Paul Durivage <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@wellic
wellic / nested_dicts.py
Created April 18, 2020 13:17
work with nested dicts
import collections
import os
import re
from copy import deepcopy
from functools import reduce
from operator import getitem
def update_nested_dicts(base_dct, new_dct, only_existed_keys=False):
# IN[]:
@wellic
wellic / deadsnakes-python38-ubuntu-bionic.md
Created October 13, 2020 06:28
Deadsnakes python 3.8 on Ubuntu 18.04 LTS

Deadsnakes python 3.8.0 on Ubuntu 18.04 LTS

The deadsnakes PPA make the latest stable versions of python available on LTS distributions. I now find it preferable to installing from source, whether from download or using pyenv.

The following was tested on a stock Ubuntu 18.04.3 LTS desktop with python 2.7.15 and 3.68 as the shipping system python versions. The pip3 binary was install using the stock python3-pip package, updated with pip3 install --upgrade pip.

One of the key reasons this works for me is that I've been aggressive about individually virtualizing project environments with venv.

First, add the deadsnakes PPA to apt:

@wellic
wellic / getter_and_setter.py
Created December 21, 2020 10:22 — forked from luhn/getter_and_setter.py
Using getters and setters with SQLAlchemy
class Table(Base):
id = Column(Integer, primary_key=True)
_name = Column('name', String(24))
@property
def name(self):
return self._name;
@name.setter
def name(self, value):