Fun tech quiz questions directly in your terminal

Fun tech quiz questions directly in your terminal

Written by Bobby Iliev on Jun 8th, 2020 Views Report Post

3um936quha6qp3q3o18y.png

Introduction

Quizzes are a great way to test your knowledge on a specific topic. So I decided to create a tool called the Quiz API!

Quiz API is a simple HTTP REST API for technical quizzes including a wide variety of topics like: Linux, DevOps, Programming (PHP, JS, Python and etc.), Docker, Kubernetes and lots more!

It is free for developers and I've just released a beta version and started adding some cool questions!

As the Quiz API returns the output in a JSON format, I created a bash script that allows you to answer questions whenever you feel like directly via your terminal!

QuizAPI Demo

Prerequisites

In order to be able to use the Quiz API bash script you need to have the following:

Download the Quiz bash script

In order to download the bash script which would allow you to consume the QuizAPI and take questions directly via your terminal, you just need to run this command here:

wget https://quizapi.io/quiz.sh

Make sure to check the script before running it! This bash script is also available on git and you can check it's contents here:

https://github.com/QuizApi/QuizAPI-BASH/blob/master/quiz.sh

Any pull requests with improvements are more than welcome!

Install jq

The jq command-line tool is is a lightweight and flexible command-line JSON processor. It is great for parsing JSON output in your terminal and it is required by the Quiz API bash script.

If you try to run the script without having jq installed you will get the following message:

The jq command is required! Please install it and then try again

If you don't have jq already installed, you can do that by running one of the following commands depending on your OS:

Linux

  • Ubuntu/Debian:
sudo apt-get install jq
  • Fedora:
sudo dnf install jq
  • openSUSE:
sudo zypper install jq
  • Arch:
sudo pacman -S jq

Mac:

  • Homebrew:
brew install jq
  • MacPort
port install jq

If you are on a different system, follow the steps from the official documentation here:

https://stedolan.github.io/jq/download/

Usage

Once you have your API Key and jq installed you can execute the script by running the following commands:

  • Make the script executable:
chmod +x quiz.sh
  • Execute the script:
./quiz.sh

As we did not specify the API key, you will get the following output

Usage: quiz.sh -a API_KEY [-c Category] [-d Difficulty] [-t Tags]

In order for the script to work, we need to pass our API key as an argument. One of the ways to do that is to define our API key as an environment variable:

export API_KEY=your_api_key_here

Note: change the your_api_key_here with your actual Quiz API key!

Then run the following:

./quiz.sh -a ${API_KEY}

The script will make a curl request to the Quiz API and it would pars the output for you in a nice interactive cli multiple choice quiz like this:

 "How to dump pod logs (stdout) in Kubernetes?"
  1 ) "kubectl log my-pod"
  2 ) "kubectl pod logs my-pod"
  3 ) "kubectl logs my-pod"
  4 ) "kubectl pods logs my-pod"
Check an option (again to uncheck, ENTER when done):

You will be able to select 1 or multiple answers and then press enter:

"How to dump pod logs (stdout) in Kubernetes?"
  1 ) "kubectl log my-pod"
  2 ) "kubectl pod logs my-pod"
  3+) "kubectl logs my-pod"
  4 ) "kubectl pods logs my-pod"
"kubectl logs my-pod" was checked
Check an option (again to uncheck, ENTER when done):

Selected was:  "kubectl logs my-pod"
Correct: is:  "kubectl logs my-pod"
Correct Answer!

Available arguments

The script allows you to specify different parameters so that you could get the questions that you want.

The available arguments are:

  • -c - get questions only for a specific category
  • -d - get questions only for a specific difficulty (Easy, Medium and Hard)
  • -t - get questions for a specific topic/tag, this lets you combine multiple topics

For example, if you wanted to get easy Docker questions only, you could run:

./quiz.sh -a ${API_KEY} -d hard -t docker

Contributions

We have added about 1000 questions for the beta version! But we are planning to add a lot more than that in the future.

As the Quiz API is free for developers, any contributions would be greatly appreciated. If you are feeling adventurous, you could do so via this link here:

https://quizapi.io/contribute

If you notice a wrong question feel free to report it as well:

https://quizapi.io/contact

Conclusion

Quizzes can be a fun way to test and improve your knowledge, with the Quiz API you are going to be able to do so via your terminal at any time!

For more information make sure to check out the official documentation here:

https://quizapi.io/docs/1.0/overview

Also, feel free to reach out and say hi on twitter:

https://twitter.com/quizapi_io

Comments (0)