Skip to content

Instantly share code, notes, and snippets.

View wellic's full-sized avatar

Valerii Savchenko wellic

View GitHub Profile
@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 / 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 / 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

//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 / foo.log
Created February 21, 2020 08:51 — forked from ibeex/foo.log
Flask logging example
A warning occurred (42 apples)
An error occurred
@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 / 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 / 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 / singleton.py
Last active November 29, 2019 12:40
Example python 3.6+ Singleton
from weakref import WeakValueDictionary
METHOD_GET_INSTANCE = 'get_instance'
METHOD_REMOVE_INSTANCE = 'remove_instance'
METHOD_CLEAR_INSTANCE = 'clear_instance'
class MetaSingleton(type):
"""
Singleton metaclass
Based on Python Cookbook 3rd Edition Recipe 9.13
@wellic
wellic / arrow-table.js
Created September 26, 2019 13:16
Add arrays key to table
(function ($, undefined) {
//Plugin for navigationg
(function () {
'use strict';
var PLUGIN_NAMESPACE = 'keys_control_table';
var DEFAULT_LISTEN_INPUTS_SELECTOR = 'input';
var DEFAULT_DEBOUNCE_TIME = 50;
var DEFAULT_CARET_MODE = true;
var DEFAULT_SELECT_AFTER_MOVE = true;