Skip to content

Instantly share code, notes, and snippets.

View konverner's full-sized avatar

Konstantin Verner konverner

  • Niort, France
View GitHub Profile
@konverner
konverner / display-project-tree.sh
Created April 20, 2026 10:16
display python project tree without utility files like cache
tree -L 3 -I "__pycache__|*.pyc|*.egg-info|.venv|.git"
@konverner
konverner / setup-docker-psql.sh
Created April 6, 2026 12:50
Production Server Setup Script (Docker + PostgreSQL Backup)
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
###############################################################################
# Production Server Setup Script (Docker + PostgreSQL Backup)
#
# What the script does:
# 1. Installs Docker Engine and Docker Compose (if not installed)
@konverner
konverner / setup-docker-psql-ssl.sh
Last active April 6, 2026 12:44
This script prepares a Linux server (Ubuntu) for running web app in production
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
###############################################################################
# Production Server Setup Script
#
# This script prepares a Linux server (Ubuntu) for running a production
# Docker-based web application with HTTPS and automated PostgreSQL backups.
@konverner
konverner / load-variables-from-dot-env.bash
Last active January 5, 2026 10:04
One-liner that loads values from .env for environment variables
export $(sed -e 's/#.*//g' -e '/^$/d' .env | xargs)
@konverner
konverner / subprocess_with_timeout.py
Created October 12, 2024 09:33
run the script for N seconds for M arguments
import subprocess
import time
timeout = 40 # Set timeout to 40 seconds
with open('items.txt', 'r') as file:
items = file.read().strip().split('\n')
for item in items:
item = item.strip() # Clean up any extra whitespace
@konverner
konverner / extract_json_block.py
Created September 23, 2024 19:42
Extract json content from markdown content
import json
def extract_json_from_text(text):
# Find the first '{' character
start = text.find('{')
if start == -1:
print("No JSON block found in the text.")
return None
# Use a stack to track nested braces
@konverner
konverner / load_env.py
Last active September 20, 2024 21:54
Load environment variables from .env in Python
# pip install python-dotenv
import os
from dotenv import find_dotenv, load_dotenv
# load variables from .env
load_dotenv(find_dotenv(usecwd=True))
MY_VAR = os.getenv("MY_VAR")
@konverner
konverner / create_keyfile_dict.py
Last active December 22, 2024 09:42
a function allows to generate json key file used by google api from environment variables
"""
A function allows to generate json key file used by google api from environment variables. Example of `.env` file:
```
TYPE="my_service_account"
PROJECT_ID="my_project_id"
PRIVATE_KEY_ID="my_private_key_id"
PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
my_private_key_content
-----END PRIVATE KEY-----
@konverner
konverner / spans_to_conll.py
Last active February 5, 2024 12:47
convert spans NER annotation to conll BIO format
import json
from typing import Any, Dict, List
import spacy
from spacy.training.iob_utils import biluo_to_iob, doc_to_biluo_tags
from tqdm import tqdm
def spans_to_conll(
samples: List[Dict[str, Any]],
@konverner
konverner / fix_ner_spans.py
Created February 1, 2024 00:00
fix corrupted spans in NER annotation
def fix_span(text: str, span: dict):
# let us check that spans are correctly extracted
fixed_span = span.copy()
# span starts with a space or a punctuation
while text[fixed_span["start"]] in [" ", ".", ",", ";", ":", "!", "?"]:
fixed_span["start"] += 1
# span is cut in the begging: e.g. "ashington DC"