Skip to content

Instantly share code, notes, and snippets.

View DAVIDhaker's full-sized avatar

Mr. DAVIDhaker DAVIDhaker

View GitHub Profile
@DAVIDhaker
DAVIDhaker / measure_execution_time.py
Created April 16, 2024 20:57
Simple and beautiful code to measure execution time in Python
import functools
from datetime import datetime
class measure_execution_time:
"""
Декоратор и контекстный менеджер для измерения времени выполнения кода
Примеры использования
@DAVIDhaker
DAVIDhaker / ljust.php
Created March 19, 2020 12:10
Pad unicode string right (like Python str.ljust)
<?php
function ljust($str, $len, $fill_char) {
$str_len = mb_strlen($str);
$out = range(0, max($str_len, $len));
$out_len = count($out);
for ($i = 0; $i < $out_len; $i++)
$out[$i] = $i < $str_len ? mb_substr($str, $i, 1) : $fill_char;
return implode("", $out);
@DAVIDhaker
DAVIDhaker / Recreate selected database.sql
Last active October 31, 2019 22:00
Snippet for HeidiSQL (and other DB managers)
-- BE ATTENTIVE BEFORE USE!
SELECT DATABASE() INTO @db;
DO
@qdrop := CONCAT("DROP DATABASE `", @db, "`"),
@qcreate := CONCAT("CREATE DATABASE `", @db, "` /*!40100 COLLATE 'utf8mb4_general_ci' */");
PREPARE stmt FROM @qdrop;
EXECUTE stmt;
@DAVIDhaker
DAVIDhaker / backup_astra.sh
Last active September 19, 2019 11:16
Backup ASTRA (cesbo) config
#!/bin/bash
# Place of packups
path=/mnt/raid1/backup/astra
# Astra admin login/pass
auth=admin:password
# List of ip`s of servers
servers=(