Skip to content

Instantly share code, notes, and snippets.

View denisdubovitskiy's full-sized avatar

Denis Dubovitskiy denisdubovitskiy

View GitHub Profile
import (
"context"
"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
clientv3 "go.etcd.io/etcd/client/v3"
)
{{ $decorator := .Vars.DecoratorName }}
func (i *Implementation) WithMask(ctx context.Context, req *desc.WithMaskRequest) (*desc.WithMask, error) {
response := &desc.WithMask{}
fs := NewFieldSet(req.FieldMask)
if fs.IsFieldRequested("field1") {
response.Field1 = fillField1()
}
if fs.IsFieldRequested("field2") {
response.Field2 = fillField2()
}
if fs.IsFieldRequested("nested1") {
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
import "google/api/annotations.proto";
message Nested2 { string field4 = 2; }
message Nested1 {
string field3 = 1;
Nested2 nested2 = 2;
}
res, err := client.WithOptionsHandler(ctx, &desc.RequestWithOptions{
Options: []desc.RequestWithOptions_Option{
desc.RequestWithOptions_OPT_BASIC_INFO,
desc.RequestWithOptions_OPT_AVAILABILITY,
},
})
res, err := client.WithMask(ctx, &desc.WithMaskRequest{
FieldMask: &fieldmaskpb.FieldMask{
Paths: []string{
"field1",
"field2",
"nested1.field3",
"nested1.nested2.field4",
// ...
},
},
@denisdubovitskiy
denisdubovitskiy / pytest_flask_fixtures.py
Created July 30, 2018 14:28 — forked from qodot/pytest_flask_fixtures.py
Pytest Fixtures (Flask, SQLAlchemy, Alembic)
import sys
import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from alembic.command import upgrade as alembic_upgrade
from alembic.config import Config as AlembicConfig
from wsgi import create_app
from config import config
#!/bin/bash
set -x
readonly internal="eDP-1"
readonly external="HDMI-1"
readonly screen_h="1368"
readonly screen_v="768"
readonly mode="${screen_h}x${screen_v}_60.00"
# Check if mode created
@denisdubovitskiy
denisdubovitskiy / typechecker.js
Created June 19, 2018 10:12
Function parameter type checker example
const add = (a, b) => a + b;
/**
* Ensure that input is a Number
* @param input {*}
*/
const typeNumber = (input) => {
if (typeof input !== 'number') {
throw new Error(`${input} is not a number`);
}
def print_list(lst):
"""for number in lst: print(number)
Linear algorythm to recursion
"""
if not lst:
return
print(lst[0])
return print_list(lst[1:])

Описание задачи

Нужно, используя SQLAlchemy, написать несколько функций, выполняющих роль CRUD (создание, чтение, обновление, удаление).

Пример модели post:

id: integer (primary key) - идентификатор записи, генерится автоматом в СУБД

title: varchar - заголовок поста, обязательное поле