Skip to content

Instantly share code, notes, and snippets.

View horpto's full-sized avatar
💭
machine learning simpleton

horpto

💭
machine learning simpleton
  • Russia, St. Petersburg
  • 22:47 (UTC +03:00)
  • X @horpto
View GitHub Profile
package main
import (
"context"
"fmt"
"time"
)
// LongProcess refers to a long network request
func LongProcess(ctx context.Context, duration time.Duration, msg string) {
@horpto
horpto / gist:073dd5882ea2e99c15ba9c3c02536d57
Created February 7, 2022 20:15
import from wrong code
# /usr/local/lib/python3.10/site-packages/pkg_resources/extern/__pycache__/__init__.cpython-310.pyc matches /usr/local/lib/python3.10/site-packages/pkg_resources/extern/__init__.py
# code object from '/usr/local/lib/python3.10/site-packages/pkg_resources/extern/__pycache__/__init__.cpython-310.pyc'
import 'pkg_resources.extern' # <_frozen_importlib_external.SourceFileLoader object >
# /usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/__pycache__/__init__.cpython-310.pyc matches /usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/__init__.py
# code object from '/usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/__pycache__/__init__.cpython-310.pyc'
import 'pkg_resources._vendor' # <_frozen_importlib_external.SourceFileLoader object >
# possible namespace for /usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/jaraco
import 'pkg_resources._vendor.jaraco' # <_frozen_importlib_external._NamespaceLoader object >
import 'pkg_resources.extern.jaraco' # <pkg_resources.extern
@horpto
horpto / diff.diff
Created February 7, 2022 19:13
diff of bad and ok versions.py
user@horpto:~/develop/notes/gevent$ diff wrong.py ok.py
479,540d478
< # possible namespace for /usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/jaraco
< import 'pkg_resources._vendor.jaraco' # <_frozen_importlib_external._NamespaceLoader object >
< import 'pkg_resources.extern.jaraco' # <pkg_resources.extern.VendorImporter object >
< # /usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/jaraco/text/__pycache__/__init__.cpython-310.pyc matches /usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/jaraco/text/__init__.py
< # code object from '/usr/local/lib/python3.10/site-packages/pkg_resources/_vendor/jaraco/text/__pycache__/__init__.cpython-310.pyc'
< # /usr/local/lib/python3.10/importlib/__pycache__/resources.cpython-310.pyc matches /usr/local/lib/python3.10/importlib/resources.py
< # code object from '/usr/local/lib/python3.10/importlib/__pycache__/resources.cpython-310.pyc'
< # /usr/local/lib/python3.10/importlib/__pycache__/_common.cpython-310.pyc matches /usr/local/lib/pyt
@horpto
horpto / fast_bulk_update.py
Created October 19, 2020 12:41
pseudo fast_bulk_update
def fast_bulk_update(model, values, fields, batch_size=1000):
# pg_specific and only simple values
from psycopg2.extras import execute_values
model_name = model._meta.db_table
assert model_name != 'vals'
pk_field = model._meta.pk
fields = tuple(model._meta.get_field(field) for field in fields)
fields_expr = ','.join(field.attname for field in fields)
@horpto
horpto / prepare-commit-msg.py
Created October 16, 2020 15:40
Adding automatic commit message
#!/usr/bin/python3
import re
import sys
NOTICKET_PREFIX = 'NOTICKET'
ISSUE_PREFIX = 'ZVN'
TICKET_BRANCH = re.compile(f'f/({ISSUE_PREFIX}-\d+).*?', re.I)
MESSAGE_RE = re.compile(f'((f/)?({ISSUE_PREFIX}-\d+)|{NOTICKET_PREFIX}) .+?', re.I)

##assertQueue([queue, [options]]) - queue - string or '' (random name) - options: + exclusive - если true, то очередь видна только в этом connection + durable - очередь не исчезает при рестарте брокера (сообщение не теряются) + autoDelete - удалить очередь, когда число консьюмеров станет 0 + arguments - брокер-специфик расширения + messageTtl (0<= n < 2^32) миллисекунды + expires (0 < n < 2^32) - уничтожить очередь после n мс не использования

  • deadLetterExchange (string) - exchange в который попадает сообщение deadLetterRoutingKey
from pprint import pprint
def diags(matrix):
x = len(matrix[0])
yield [matrix[i][i] for i in range(x)]
yield [matrix[i][x - 1 - i] for i in range(x)]
for i in range(1, x):
PREDICATES
nondetermclear_string(string, string)
CLAUSES
clear_string("", "").
clear_string(Str, Res) :-
frontstr(1, Str, Fchar, Rest),
Fchar = " ", !,
def NarayanaNextPerm(a):
n = len(a)
k = n - 2
# step 1
while a[k] >= a[k+1] && k >= 0:
k -= 1
if k == -1:
return 0
#ifndef VECTOR_H
#define VECTOR_H
#include <stddef.h>
#include <string.h>
#include <malloc.h>
/* Динамически растущий велосипед */
#define SINGLE_ARG(...) __VA_ARGS__