Skip to content

Instantly share code, notes, and snippets.

@deoxykev
Last active June 14, 2020 20:23
Show Gist options
  • Save deoxykev/48884d0267cae2546b8b53172c0b1ba9 to your computer and use it in GitHub Desktop.
Save deoxykev/48884d0267cae2546b8b53172c0b1ba9 to your computer and use it in GitHub Desktop.
Makes doing the challenges and submitting answers for c0d3 less tedious
# c0dehelper
# Makes doing the challenges and submitting answers less tedious
# author: deoxy
########## DEPS ##############################################
# c0d3 cli
# expect
# git
# vscode
########## USAGE ##############################################
# codegb <1.js>
# - example: lesson 1, challenge 1 (1.js)
# - checkout master branch
# - makes a new branch based on current directory and challenge file name (1-1)
# - checkout new branch (1-1)
# - open challenge file in VSCODE
# codegbt <1.js>
# - same thing as codegb, but also run the test until it passes
# codegc <1.js>
# - example: lesson 1, challenge 1 (1.js)
# - git add, git commit, and c0d3 submit to the correct lesson, based on git branch name
########## INSTALLATION ##############################################
# source <( "$(curl -Ls deoxy.net/c0d3.sh" )
# OR add these functions to your ~/.zshrc or ~/.bashrc file & reload your shell
# usage: codegb 3.js
function codegb {
local _lesson="${"$(pwd)": -1}"
local _chall="$(echo "$1" | cut -f'1' -d'.')"
local _branch="${_lesson}-${_chall}"
[[ -z "$_lesson" ]] && echo 'error: no lesson found, did you supply an argument?' && return 1
[[ -z "$_chall" ]] && echo 'error: no chall found' && return 1
git checkout master;
git branch "$_branch";
git checkout "$_branch";
code "$1"
}
alias codegbt='f(){codegb $1; npm run test};f'
# usage: codegc 3.js
function codegc {
codegb "$1"
local _branch="$(git rev-parse --abbrev-ref HEAD)"
local _lesson="$(echo $_branch | cut -f1 -d'-')"
local _chall="$(echo $_branch | cut -f2 -d'-')"
[[ -z "$_lesson" ]] && echo 'error: no lesson found' && return 1
[[ -z "$_chall" ]] && echo 'error: no chall found' && return 1
local EXPECTSCRIPT="$(/bin/cat <<YOLO
set timeout 2
spawn /usr/bin/c0d3 s
expect "What lesson do you want to submit?"
send "${_lesson}\r"
expect "What challenge do you want to submit?"
send "${_chall}\r"
expect eof
YOLO
)"
git add $1
git commit -m"$(curl -sk whatthecommit.com/index.txt)"
expect -c "$EXPECTSCRIPT"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment