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 / which.sh
Last active February 25, 2022 07:49
sh: mimics the core routine of GNU `which` command
#!/usr/bin/env sh
#
# Mimics the core routine of UNIX `which` command[1]
#
# Implemented on the top of shell builtins to provide the way
# to resolve external dependencies (commands) for shell scripts
# whether external `which` command available or not
#
# Designed to be fully `sh` compatible, strictly honors POSIX standards
# and completely meets Shell Command Language specification[2], thus
@juliyvchirkov
juliyvchirkov / validEmail.js
Last active March 12, 2021 06:27
javascript: strict e-mail address verification
/**
* Provides strict e-mail address verification
* Includes support for unicode
*
* @param string e-mail address to verify
* @return boolean true if e-mail address is valid, false otherwise
*/
function validEmail (email) {
'use strict'
@juliyvchirkov
juliyvchirkov / typeOf.js
Last active November 30, 2022 15: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 / printsshconn.sh
Last active September 16, 2021 14:37
bash: collects and prints short summary on active ssh/sftp connections to server
#!/usr/bin/env bash
#
# Designed by https://juliyvchirkov.github.io under MIT license
#
# Collects and prints short summary on active ssh/sftp connections to server
#
# SSH/SFTP connections
# ----------------------------------
# (3) 14.88.18.1
# (1) 14.88.18.8
@juliyvchirkov
juliyvchirkov / macos-sudo-nopasswd.sh
Last active August 28, 2023 15:43
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 / 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 / __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 / 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 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
*/
/**