Created
November 28, 2016 22:39
-
-
Save mariotti/6705ee0771de0fe42a7d6b7ef15912c6 to your computer and use it in GitHub Desktop.
make json from markdown - markdown to json
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/sh | |
# | |
QQ="QUESTIONS.md" | |
#QQ="bin/makeJSONfromQ.QUESTIONS.test.md" | |
cat ${QQ} | tail +4 | sed 's/"/``/g' | \ | |
awk 'BEGIN { Ccount=0; Qcount=0; QCcount=0; Ncount=0; firtsC=0; firstQ=0 } \ | |
/^\*\*/ {Ccount++; QCcount=0; gsub(/^\*\*/,"",$0);gsub(/\*\*$/,"",$0);\ | |
if (Ccount >1) \ | |
{print "\t\t\t}\n\t\t]\n\t\t},"} | |
else {print "{ \"TechQuestions\" :\n\t{ \"category\" :\n\t["}; \ | |
catName=$0; | |
tagsCnum = split(catName,tagsCname,","); | |
printf("\t\t{ \"idC\" : \"C%d\", \"name\" : \"%s\",",Ccount,$0)} \ | |
/^- / {Qcount++; QCcount++; gsub(/^- */,"",$0);gsub(/^ /,"",$0);gsub(/[ ]+$/,"",$0); if (QCcount >1) {\ | |
if (Ncount > 0) {Ncount = 0;print "\"";}; \ | |
print "\t\t\t},"; \ | |
} \ | |
else { \ | |
print "\n\t\t\"question\" : [ "}; \ | |
printf("\t\t\t"); \ | |
printf("{"); \ | |
printf("\"categoryname\" : \"%s\",",catName); \ | |
printf("\"idC\" : \"C%d\",",Ccount); \ | |
printf("\"idCQ\" : \"C%dQ%d\",",Ccount, QCcount); \ | |
printf("\"idQ\" : \"Q%d\",",QCcount); \ | |
printf("\"ID\" : \"Q%d\",",Qcount); \ | |
printf("\"name\" : \"%s\"",$0); \ | |
} \ | |
/^ / {Ncount++; if (Ncount > 1) \ | |
{gsub(/^[ \t]+/,"",$0);gsub(/[ \t]+$/,"",$0);printf("%s",$0);} \ | |
else {gsub(/^[ \t]+/,"",$0);gsub(/[ \t]+$/,"",$0);printf("\t\t\t,\n\t\t\t\"notes\" : \"%s",$0)}} | |
END { print "\t\t\t}\n\t\t]\n\t\t}\n\t]\n}\n}"}' | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This snippet translates a "specific" markdown file into a JSON data file. As in the actual project this file will disappear I thought to save it as gist.
The file in question is:
https://github.com/mariotti/technical_interview_questions/blob/master/QUESTIONS.md
A short version is:
Technical Interview Questions
General
Find the most frequent integer in an array
Given 2 integer arrays, determine if the 2nd array is a rotated version of the 1st array.
Ex. Original Array A={1,2,3,5,6,7,8} Rotated Array B={5,6,7,8,1,2,3}
We’re going to find “Word Twins”, which are pairs of English words, at least 4 letters long, where the first three letters of one are the last three letters of another. For example, “strategy” and “Egypt”.
Given a 3*3 matrix, and 1-8 numbers in random order, 1 place as space.
Write code to find the min exchange of numbers to make the matrix in order.
There is k parenthesis, write code to calculate how many permutations could have.
For 2 parenthesis, there is 2 permutations: ()() and (()).
HARD: Given a 2D array of 1s and 0s, count the number of "islands of 1s" (e.g. groups of connecting 1s)
Strings
Trees