Skip to content

Instantly share code, notes, and snippets.

View wellic's full-sized avatar

Valerii Savchenko wellic

View GitHub Profile
@wellic
wellic / 00-setup.sql
Created October 7, 2021 09:39 — forked from apneadiving/00-setup.sql
Tree structure query with PostgreSQL
-- Create tables
CREATE TABLE groups (id serial NOT NULL, name character varying NOT NULL);
CREATE TABLE network_group_members (pid integer, cid integer NOT NULL);
-- Insert the groups
INSERT INTO groups (name) VALUES ('GROUP 1'),('GROUP 2'),('GROUP 3'),('GROUP 4'),('GROUP 5'),('GROUP 6'),('GROUP 7'),('GROUP 8'),('GROUP 9'),('GROUP 10'),('GROUP 11'),('GROUP 12'),('GROUP 13');
-- Build the "Network"
INSERT INTO network_group_members(pid,cid) VALUES (1,2),(1,3),(1,4),(2,5),(5,6),(5,7),(7,8),(3,9),(4,10),(4,11),(11,12),(12,13);
@wellic
wellic / localstack.md
Created October 6, 2021 14:13 — forked from lobster1234/localstack.md
Working with localstack on command line

Starting localstack

C02STG51GTFM:localstack mpandit$ make infra
. .venv/bin/activate; exec localstack/mock/infra.py
Starting local dev environment. CTRL-C to quit.
Starting local Elasticsearch (port 4571)...
Starting mock ES service (port 4578)...
Starting mock S3 server (port 4572)...
Starting mock SNS server (port 4575)...
@wellic
wellic / uuid_regex.py
Created July 6, 2021 09:08 — forked from kgriffs/uuid_regex.py
UUID regular expressions (regex) with usage examples in Python
import re
# RFC 4122 states that the characters should be output as lowercase, but
# that input is case-insensitive. When validating input strings,
# include re.I or re.IGNORECASE per below:
def _create_pattern(version):
return re.compile(
(
'[a-f0-9]{8}-' +
@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):
@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 / 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

@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 / jsonhandler.py
Created September 3, 2018 15:18 — forked from mminer/jsonhandler.py
A JSON request handler for Tornado.
import json
import tornado.web
class JsonHandler(BaseHandler):
"""Request handler where requests and responses speak JSON."""
def prepare(self):
# Incorporate request JSON into arguments dictionary.
if self.request.body:
try: