Skip to content

Instantly share code, notes, and snippets.

View juliyvchirkov's full-sized avatar
🇺🇦
old but not obsolete

Juliy V. Chirkov juliyvchirkov

🇺🇦
old but not obsolete
View GitHub Profile
@juliyvchirkov
juliyvchirkov / readme.md
Last active June 14, 2024 03:36
sh: extended implementation of ”YesNoPrompt” shell function, fully POSIX compliant

YesNoPrompt

Extended implementation of world known common shell function, fully POSIX compliant

The project has been significantly improved and moved to the new permanent location github.com/juliyvchirkov/sh.yesnoprompt

@juliyvchirkov
juliyvchirkov / getOptionValue.sh
Created October 4, 2022 07:24
bash: long options parser
##
# long option format: --option=value
#
# usage: value="$(getOptionValue option "${@}")"
# script.sh --pidfile=/run/pidfile.pid ➙ pidfile="$(getOptionValue pidfile "${@}")"
##
getOptionValue() {
local option
@juliyvchirkov
juliyvchirkov / oum
Last active December 7, 2021 01:35
bash: /usr/sbin/oum fixes
#!/usr/bin/env bash
# Copyright Atomicorp 2020
# AGPL 3.0
# Modified by Juliy V. Chirkov juliyvchirkov@gmail.com https://juliyvchirkov.github.io/ 12/07/2021
# Globals
VERSION=0.2
OSSEC_HOME=/var/ossec
SERVER=updates.atomicorp.com
@juliyvchirkov
juliyvchirkov / annotation.rst
Last active June 16, 2024 15:26
bash: backup of live kvm machines

Backup of live kvm machines

Note

Work on routine update and annotation in progress

  • apparmor.d - /etc/apparmor.d/local/{usr.sbin.libvirtd,libvirt-qemu,usr.lib.libvirt.virt-aa-helper}, root:root 0644 (-rw-r--r--)
  • kvmbackup.cron - /etc/cron.d/kvmbackup.cron, root:root 0644 (-rw-r--r--)
@juliyvchirkov
juliyvchirkov / string.polyfill.php
Last active April 14, 2024 22:24
php: polyfills of string functions str_starts_with, str_contains and str_ends_with
<?php declare(strict_types = 1);
/**
* Provides polyfills of string functions str_starts_with, str_contains and str_ends_with,
* core functions since PHP 8, along with their multibyte implementations mb_str_starts_with,
* mb_str_contains and mb_str_ends_with
*
* Covers PHP 4 - PHP 7, safe to utilize with PHP 8
*/
/**
@juliyvchirkov
juliyvchirkov / mageRoot.mjs
Last active August 16, 2022 20:36
nodejs, php, bash: Magento 1 / 2 baseDir autodetection
import { realpathSync, existsSync } from 'node:fs'
import { basename, dirname } from 'node:path'
export default (() => {
let mageRoot = dirname(realpathSync(import.meta.url.slice(7)))
while (!(existsSync(`${ mageRoot }/app/Mage.php`) || existsSync(`${ mageRoot }/bin/magento`))) {
if (mageRoot === '/') {
throw new Error(`${ basename(import.meta.url.slice(7)) } should be placed inside Magento project tree`)
}
@juliyvchirkov
juliyvchirkov / __git_ps1.sh
Last active June 23, 2022 03:42
bash: simplified custom function __git_ps1 to display current branch or tag name in git repo
#!/usr/bin/env bash
#
# If one is missing the original *__git_ps1* function from @git/git package, this wrapper can be utilized as
# temporary solution. Just like the original, it prints current branch name like *main*, *dev* etc. or tags
# like *v1.4.0*, or nothing, if current directory is outside of any git tree
#
# @see https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
#
# Significantly updated 06/18/2022
#
@juliyvchirkov
juliyvchirkov / termTestTruecolor.sh
Last active March 13, 2021 02:14
bash: terminal truecolor test. proof of concept, completely made of pure bash builtins
#!/usr/bin/env bash
#
# Terminal truecolor test
# Proof of concept, completely made of pure bash builtins
#
# Accepts an integer from 14 up to infinity to set the length of test snake
# By default the snake is 88 symbols long
#
# Execute or source termTestTruecolor.sh to export function
#
@juliyvchirkov
juliyvchirkov / apt.sh
Last active May 30, 2022 16:05
bash: apt bootstrap to implement options shortcuts
#!/usr/bin/env bash
#
# Provides shortcuts for apt options
#
# @see https://gist.github.com/juliyvchirkov/7ee6591b9744c36fa9ab73a1ca2ef544#file-quickinstall-rst
case ${1} in
i)
arg1st="install" ;;
ri)
@juliyvchirkov
juliyvchirkov / macos-sudo-nopasswd.sh
Last active October 12, 2024 14:42
bash: sudo without a password on macOS
#!/bin/bash
#
# Enable nopasswd mode for sudo on macOS from the userspace in fast and totally non-interactive way
#
# Type the password last time to apply the new mode and forget it for any console task for ages
# Use the rollback to restore password protection
#
# Developed and tested by https://juliyvchirkov.github.io/ under the MIT license on macOS Big Sur 11.2.0
#
# Get latest version at https://gist.github.com/juliyvchirkov/3ca76582ed6b6a8366c9e7d60644960d