anthony / Проверить запущен ли скрипт из терминала
0 likes
0 forks
1 files
Last active
Checks if script running under php-cli
| 1 | /** |
| 2 | * Определяет запущен ли скрипт через php-cli |
| 3 | * Checks if script running under php-cli |
| 4 | * |
| 5 | * @return bool |
| 6 | */ |
| 7 | function is_cli(): bool |
| 8 | { |
| 9 | return PHP_SAPI === 'cli' |
| 10 | || (!isset($_SERVER['DOCUMENT_ROOT']) && !isset($_SERVER['REQUEST_URI'])); |
anthony / Simple equivalents of Oracle functions
0 likes
0 forks
2 files
Last active
For those who like perversions
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Simple php equivalent of Oracle's decode() |
| 5 | * |
| 6 | * It can be used as simple oneline-alternative to switch or if operators in many |
| 7 | * cases without difficult logic. For example, get string mnemocode of some value: |
| 8 | * |
| 9 | * echo 'State: '.decode($state, 0, 'disabled', 1, 'enabled', 'unknown'); |
| 10 | * |
anthony / jq cheatsheet
0 likes
0 forks
1 files
Last active
Taken from https://gist.github.com/olih/f7437fb6962fb3ee9fe95bda8d2c8fa4
Processing JSON using jq
jq is useful to slice, filter, map and transform structured json data.
Useful arguments
When running jq, the following arguments may become handy:
| Argument | Description |
|---|
anthony / Argument parser for bash scripts without getopt or getopts
0 likes
0 forks
1 files
Last active
Taken from b167d3ec4e4f94d246ebdc4bcfdfb6ac
| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # Argument parser for bash scripts |
| 4 | # |
| 5 | # Author: Anthony Axenov (Антон Аксенов) |
| 6 | # Version: 1.6 |
| 7 | # License: MIT |
| 8 | # Description: https://git.axenov.dev/anthony/shell/src/branch/master/helpers/arg-parser |
| 9 | |
| 10 | #purpose Little helper to check if string matches PCRE |
anthony / Simple dotenv loader
0 likes
0 forks
1 files
Last active
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Loads an environment variable |
| 5 | * |
| 6 | * @param string $name |
| 7 | * @param mixed|null $def |
| 8 | * @param bool $local |
| 9 | * @return array|mixed|string|null |
| 10 | */ |
anthony / Get latest release from GitHub
0 likes
0 forks
1 files
Last active
| 1 | #!/bin/bash |
| 2 | get_latest_release() { |
| 3 | curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api |
| 4 | grep '"tag_name":' | # Get tag line |
| 5 | sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value |
| 6 | } |
Newer
Older