Skip to content

Instantly share code, notes, and snippets.

@mcustiel
Last active July 13, 2021 13:31
Show Gist options
  • Save mcustiel/7a644dadd30609564f8cf26eb7b68d3b to your computer and use it in GitHub Desktop.
Save mcustiel/7a644dadd30609564f8cf26eb7b68d3b to your computer and use it in GitHub Desktop.
Useful scripts
#!/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
<?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;
#!/usr/bin/env bash
for tag in `git tag` ; do git tag -d $tag; done && git fetch --tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment