Skip to content

Instantly share code, notes, and snippets.

View britonad's full-sized avatar
🪖
Fighting for the bright future of 🇺🇦

Vladyslav Krylasov britonad

🪖
Fighting for the bright future of 🇺🇦
View GitHub Profile

Keybase proof

I hereby claim:

  • I am britonad on github.
  • I am britonad (https://keybase.io/britonad) on keybase.
  • I have a public key ASAA90BK9r5FywFtLIhnELnw167hV99f1khkV6qUyXR5FQo

To claim this, I am signing this object:

@britonad
britonad / do-bootstrap.sh
Created April 18, 2022 07:44
A simple bootstrap script for Ubuntu 20.04 on DigitalOcean that setup firewall, creates a sudo user with a pass, installs libs, configure a locale and ssh.
#!/bin/bash
# A simple boostrap script for Ubuntu 20.04 on DigitalOcean.
# Abort script at first error, when a command exits with non-zero status
# (except in until or while loops, if-tests, list constructs)
# https://www.tldp.org/LDP/abs/html/options.html
set -eu
# update repositories and install libraries
apt update && apt upgrade -y && apt install -y make git mosh pwgen htop lnav
#!/bin/bash
# VPN bootstrap script.
# 1st step
# update repositories and install libraries
apt update && apt upgrade -y && apt install -y make git mosh pwgen htop lnav
apt install -y unbound > /dev/null 2>&1
# configure locale
locale-gen en_GB.UTF-8
@britonad
britonad / docker-compose.yml
Created August 10, 2021 11:34
Postgis container with PGAdmin4 interface for nice and easy local development when a DB needed.
version: "3.7"
services:
postgresql:
image: postgis/postgis
environment:
POSTGRES_DB: "geo"
POSTGRES_USER: "geo"
POSTGRES_PASSWORD: "geo"
@britonad
britonad / standalone.py
Last active December 7, 2021 11:28
An example of Django standalone script
#!/usr/bin/env python3
import os
import pathlib
import sys
import django
# Set a project root to a const, this file should be placed in a project root
# as well
PROJECT_ROOT = pathlib.Path(__file__).resolve().parent
@britonad
britonad / time.py
Created July 15, 2020 13:21
A dummy function to measure time consumed by a function, method, etc.
import resource
from functools import wraps
from time import time
def time_it(func):
@wraps(func)
def wrapper(*args, **kwargs):
start = time()
f = func(*args, **kwargs)
@britonad
britonad / mem.py
Last active March 18, 2021 16:25
A dummy decorator function to measure memory usage of a Python function, method, etc.
import resource
from functools import wraps
def mem_it(func):
@wraps(func)
def wrapper(*args, **kwargs):
pre = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1024
print(f'Pre-memory usage: {pre} (mb)')
f = func(*args, **kwargs)
@britonad
britonad / cap_vs_len.go
Last active June 25, 2020 16:14
How `cap` built-in differs from `len` one in Golang.
package main
import "fmt"
func main() {
/*
array address is 0xc000016420.
array values are [5]int{1, 2, 3, 4, 5}.
array type is [5]int.
array length is 5.
@britonad
britonad / main.go
Last active June 24, 2020 22:57
How pointers works in Golang.
package main
import "fmt"
func main() {
/*
i initial value is 0
j initial value is 0
i initial address is 0xc0000b4010
j initial address is 0xc0000b4018
import re
import subprocess
from collections import defaultdict
from dataclasses import dataclass, field
from pprint import pprint
TEMPLATE = """## {code} ({text_code})
### :x: Problematic code: