Last active
July 13, 2021 13:31
-
-
Save mcustiel/7a644dadd30609564f8cf26eb7b68d3b to your computer and use it in GitHub Desktop.
Useful scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
MESSAGE=$1 | |
# Idiot filter | |
if [ "$MESSAGE" = "-m" ]; then | |
MESSAGE=$2 | |
fi | |
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD` | |
# First split by / char into an array | |
set -- "$CURRENT_BRANCH" | |
IFS="/"; declare -a ARRAY=($*) | |
# Then split the position one (not sub-task or story) | |
set -- "${ARRAY[1]}" | |
IFS="-"; declare -a ARRAY=($*) | |
# Prepend the ticket name into the message | |
if [[ -z "${ARRAY[0]}" ]] || [[ -z "${ARRAY[1]}" ]] ; then | |
git commit -m "$MESSAGE" | |
else | |
git commit -m "${ARRAY[0]}-${ARRAY[1]}: $MESSAGE" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// IMPORTANT NOTE! The sum of the distributions MUST be 100. | |
const OPTIONS_DISTRIBUTION = [ | |
'option 1' => 34, | |
'option 2' => 33, | |
'option 3' => 33, | |
]; | |
reset(OPTIONS_DISTRIBUTION); | |
$probability=rand(0,99); | |
$accumulated = current(OPTIONS_DISTRIBUTION); | |
while ($probability >= $accumulated) { | |
$next = next(OPTIONS_DISTRIBUTION); | |
if ($next === false) { | |
throw new Exception('Error: Could not select randomly distributed option.'); | |
} | |
$accumulated += $next; | |
} | |
$option = key(OPTIONS_DISTRIBUTION); | |
echo 'The chosen option is: ' . $option . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment