Last active
November 6, 2016 19:12
-
-
Save Bajron/4bd72de42f7fd2756086b6acabbb7ecf to your computer and use it in GitHub Desktop.
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
if [ "${BASH_SOURCE[0]}" == "${0}" ]; then | |
echo "* This file is supposed to be sourced!" | |
echo "" | |
echo "Usage:" | |
echo " source $0" | |
exit 1 | |
fi | |
function rosalind_help() { | |
cat<<EOF | |
Rosalind helpers for http://rosalind.info | |
Works best with minimake utility. | |
Available features: | |
rosalind_sample [file[.cpp]] : download sample input | |
rosalind_expected [file[.cpp]] : show expected output for sample input | |
rosalind_setup [file[.cpp]] : download sample, setup minimake default | |
and prepare stub .cpp file (if not present) | |
rosalind_refresh : reload helpers | |
rosalind_clean : unload helpers | |
All funtions can be used with minimake default variable. | |
Helpers are defined in $rosalind_SOURCE | |
EOF | |
} | |
function rosalind_init() { | |
if [ "$rosalind_SOURCE" ]; then | |
rosalind_refresh | |
else | |
echo "Rosaling helpers loaded. Type rosalind_help for details." | |
fi | |
} | |
function rosalind_sample() { | |
local p="${1:-${minimake_DEFAULT}}"; p="${p#.cpp}"; [ "$p" ] || return | |
curl -s "rosalind.info/problems/${p}/" | pup '#sample-dataset + div > pre text{}' > "${p}.in" | |
} | |
function rosalind_expected() { | |
local p="${1:-${minimake_DEFAULT}}"; p="${p#.cpp}"; [ "$p" ] || return | |
curl -s "rosalind.info/problems/${p}/" | pup '#sample-output + div > pre text{}' | |
} | |
function rosalind_setup() { | |
local p="${1:-${minimake_DEFAULT}}"; p="${p#.cpp}"; [ "$p" ] || return | |
rosalind_sample "${p}" | |
[ "${minimake_SOURCE}" ] && mm_set "${p}" && n "${p}" | |
} | |
function rosalind_refresh() { | |
local src="$rosalind_SOURCE" | |
rosalind_clean | |
source "$src" | |
} | |
function rosalind_clean() { | |
unset -f rosalind_sample | |
unset -f rosalind_expected | |
unset -f rosalind_setup | |
unset -f rosalind_clean | |
unset -f rosalind_init | |
unset -f rosalind_refresh | |
unset -f rosalind_help | |
unset -v rosalind_SOURCE | |
} | |
rosalind_init | |
rosalind_SOURCE="$(readlink -f ${BASH_SOURCE[0]})" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment