Skip to content

Instantly share code, notes, and snippets.

View drew2a's full-sized avatar
:octocat:
Looking for a job: https://www.linkedin.com/in/drew2a

Andrei Andreev drew2a

:octocat:
Looking for a job: https://www.linkedin.com/in/drew2a
View GitHub Profile
1. Install `flack8` and `import-order` plugin:
Note: Below all examples imply the use of venv for the project.
```
python3 -m pip install flake8
python3 -m pip install flake8-import-order
```
2. Add `File Watcher`:
def kilo(value):
return f'{value / 1000:.1f}kN'
def fall_force(m, fall_factor, elongation_factor=0.3):
return (9.8 * 2 * m * fall_factor) / elongation_factor
print(kilo(fall_force(80, 2))) # 10.5kN
print(kilo(fall_force(80, 1.7))) # 8.9kN
import argparse
import asyncio
import logging
from pathlib import Path
from types import SimpleNamespace
import libtorrent
from pony.orm import db_session
from tribler_core.modules.libtorrent.torrentdef import TorrentDef
@dataclass
class Ping:
...
@dataclass
class Pong:
...
@drew2a
drew2a / gist:a0a1123f9b976fe45df64ca0bb413de0
Created September 13, 2022 10:23
mergeGitRepositories.sh
#!/bin/bash
#
################################################################################
## Script to merge multiple git repositories into a new repository
## - The new repository will contain a folder for every merged repository
## - The script adds remotes for every project and then merges in every branch
## and tag. These are renamed to have the origin project name as a prefix
##
## Usage: mergeGitRepositories.sh <new_project> <my_repo_urls.lst>
## - where <new_project> is the name of the new project to create
"""
Pydantic configuration BaseModels for IPv8.
If you want to see the available configuration options, print the schema as follows:
::
from json import dumps
print(dumps(format_schema_recursive(IPv8Configuration), indent=4))
import asyncio
import datetime
import logging
import math
import time
from pathlib import Path
from typing import Optional
from elastic_transport import TransportError
from elasticsearch import Elasticsearch
import sys
from elasticsearch import Elasticsearch
elastic_client = Elasticsearch('http://localhost:9200', request_timeout=120)
print('query:')
for line in sys.stdin:
query = {
"simple_query_string": {
@drew2a
drew2a / branch_age.py
Created November 22, 2023 11:29
Calculate a git branch age
import datetime
import subprocess
def run_git_command(command, repo_path):
return subprocess.check_output(command, cwd=repo_path, shell=True).decode('utf-8').strip()
# Repository path
repo_path = 'path/to/tribler/repo'
@drew2a
drew2a / fetch_issues_and_releases.py
Last active December 14, 2023 11:16
Fetch issues with 'type: bug' label and visualise them
import json
import requests
def fetch_github_data(repo, endpoint, params={}):
""" Fetch data from a GitHub repository endpoint. """
data = []
page = 1
base_url = f'https://api.github.com/repos/{repo}/{endpoint}'