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 21, 2024 07:25
sh: world known common command which, implemented as shell function, fully POSIX compliant

Which

World known regular command which, implemented as sh shell function, fully POSIX compliant

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

@juliyvchirkov
juliyvchirkov / validEmail.js
Last active January 15, 2025 21:26
javascript: strict e-mail address verification
/**
* Provides strict verification of e-mail address
* Includes support for unicode
*
* @param string E-mail address to verify
* @return boolean True if e-mail address is valid, false otherwise
*/
const validEmail = (email) =>
Object.prototype.toString.call(email).slice(8, -1) === String.name &&
@juliyvchirkov
juliyvchirkov / itemType.js
Last active January 15, 2025 21:33
javascript: identifies the exact type of an object or a primitive
/**
* Returns a string indicating the type of an object or a primitive
* Throws if invoked w/o arguments
*
* @param any An object or a primitive whose type is to be determined
* @return string The type of probed item
*
* Unlike native typeof operator identifies Null as is (not as Object)
* Delivers the exact type of an item not limited to 9 basic types Undefined,
* Null, Boolean, Number, BigInt, String, Function, Symbol and Object
@juliyvchirkov
juliyvchirkov / macos-sudo-nopasswd.sh
Last active December 17, 2024 09:05
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
@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 / __git_ps1.sh
Last active January 15, 2025 21:14
sh: simplified custom function __git_ps1 to display current branch or tag name in git repo
#!/bin/sh
############ *posix* #############
# shellcheck shell=sh enable=all #
##################################
#
# If one is missing the original *__git_ps1* function from @git/git package, this wrapper can be utilized as
# temporary solution
#
# @see https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh
#
@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 / string.polyfill.php
Last active March 7, 2025 11:39
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 / 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 / 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 [email protected] https://juliyvchirkov.github.io/ 12/07/2021
# Globals
VERSION=0.2
OSSEC_HOME=/var/ossec
SERVER=updates.atomicorp.com