% !TEX TS-program = xelatex
% !TEX encoding = UTF-8 Unicode

\documentclass[9pt]{article}

% force US English hyphenation 
\usepackage[USenglish]{babel}

% more advanced expressions in \setlength
\usepackage{calc}

% more advanced command declaration
\usepackage{xparse}

% provides some extra warnings regarding deprecated practices
\usepackage[l2tabu,orthodox]{nag}

% define margin
\newlength\cvMargin
\setlength\cvMargin{0.2in}

% set defined margin as paper margin
\usepackage[margin=\cvMargin,noheadfoot]{geometry}

% set the other lengths based on the margin
\newlength\cvSideWidth
\setlength\cvSideWidth{0.3\paperwidth-\cvMargin}
\newlength\cvMainWidth
\setlength\cvMainWidth{\paperwidth-4\cvMargin-\cvSideWidth}

\newlength\cvPictureWidth
\setlength\cvPictureWidth{1.5in}

% defining some lengths for the language bar
\newlength\cvLanguageBarWidth
\setlength\cvLanguageBarWidth{5em}

\newlength\cvLanguageBarHeight
\setlength\cvLanguageBarHeight{0.75em}

% defines spacing between a section and its icon
\newlength\cvTimeDotSep
\setlength\cvTimeDotSep{0.1in}

% spacing between two items in a section
\newlength{\cvSectionSep}
\setlength{\cvSectionSep}{0.1in}

% we will define this length later, based on the widest icon
\newlength\cvHeaderIconWidth

% Determines font styles
\newcommand{\cvSection}[1]{\Large\textbf{#1}}
\newcommand{\cvEducation}[3]{{\firaMedium #1}\\ #2\\ \emph{#3}}
\newcommand{\cvExperience}[5]{{\firaMedium #1}\\ \textsc{\selectfont #2}, #3. #4\\ \emph{#5}}

% allow for links
\usepackage{hyperref}

% advanced drawing
\usepackage{tikz}
\usetikzlibrary{calc,positioning,backgrounds,matrix,node-families} %requires node-families file

% pictures
\usepackage{graphicx}

% define four main colours
\definecolor{cvColor}{HTML}{5F9CA8}
\definecolor{cvColorLight}{HTML}{99D0DA}
\definecolor{cvDark}{HTML}{2F3142}
\definecolor{cvAccent}{HTML}{474A65}

% load external fonts
\usepackage{fontspec}    

% icon font
\usepackage{fontawesome}   
   
% load external fonts
\setmainfont[Numbers={OldStyle,Monospaced}]{Open Sans}
\setsansfont{Open Sans}
\setmonofont{Open Sans}
\newfontfamily\firaMedium{Open Sans}

\pagestyle{empty}

% update default paragraph indent, and header space
\setlength{\topskip}{0pt}      % between header and text (0 needed for vertical centring)
\usepackage{parskip}           % remove paragraph indents

% setting variable from before based on widest icon
\setlength{\cvHeaderIconWidth}{\maxof{\widthof{\faBriefcase}}{\widthof{\faGraduationCap}}}

% set TikZ styles
\tikzset{%
  contactIcon/.style={%
    minimum height=\baselineskip,
  },
  contactText/.style={%
    minimum height=\baselineskip,
    text depth=0pt,
  },
  headerIcon/.style={%
    minimum width=\cvHeaderIconWidth,
    anchor=center,
  },
  languageText/.style={},
  progressArea/.style={%
    draw,
    rectangle,
    minimum width=\cvLanguageBarWidth,
    minimum height=\cvLanguageBarHeight,
    cvColor},
  progressBar/.style={%
    minimum height=\cvLanguageBarHeight,
    rectangle,
    draw,
    fill,
    cvColor,
    anchor=west},
  sectionTitle/.style={%
    anchor=north west,
    align=left},
  eventdottext/.style = {%
    text width=\cvMainWidth-\cvTimeDotSep,
    black,
    %text depth=0pt,
    anchor=north west,
  },
  sectionedutext/.style={%
    eventdottext,
    anchor=north west
  },
  invisibletimedot/.style = {%
    circle,
    minimum width=3pt,
    anchor=center
  },
  timedot/.style = {%
    invisibletimedot,
    draw,
    minimum width=3pt,
    fill,
    black,
  },
  }

% based on https://tex.stackexchange.com/questions/65731
\makeatletter
\def\cv@hrulefill{{\color{cvColor}\leavevmode\leaders\hrule height 1pt\hfill\kern\z@}}

% line before and after text (some tweaking is required here)
% based on https://tex.stackexchange.com/questions/15119
\NewDocumentCommand{\ruleline}{m}{\par\noindent\raisebox{\baselineskip/4}{\makebox[\linewidth]{\cv@hrulefill\hspace{1ex}\raisebox{-\baselineskip/4}{#1}\hspace{1ex}\cv@hrulefill}}}
\makeatother

% update global colour
\makeatletter
\NewDocumentCommand{\globalcolor}{m}{%
  \color{#1}\global\let\default@color\current@color
}
\makeatother
\AtBeginDocument{\globalcolor{cvDark}}

\NewDocumentCommand{\cvLanguage}{mm}{%
  {\globaldefs=1\relax\pgfkeys{/cv/languages/lang\the\value{languages} = #2}}
  
  \stepcounter{languages}
}

\makeatletter
\newcount\my@repeat@count
\newcommand{\cvSkill}[1]{%
  \begingroup
  \my@repeat@count=\z@
  \@whilenum\my@repeat@count<#1\do{\faCircle\advance\my@repeat@count\@ne}%
  \my@repeat@count=\numexpr5-\z@\relax
  \@whilenum\my@repeat@count>#1\do{\faCircleO\advance\my@repeat@count\m@ne}%
  \endgroup
}
\makeatother
  
\begin{document}

  \vspace*{\fill}
  % fill in sidebar
  \begin{tikzpicture}[remember picture,overlay]
    \fill[cvColorLight] (current page.north west) rectangle ++(\cvSideWidth+2\cvMargin,-\paperheight);
  \end{tikzpicture}

  % sidebar formatted as a minipage
  \begin{minipage}{\cvSideWidth}
    \begin{center}
  
      % profile photo
      \begin{tikzpicture}
        \node[
          rectangle,
          minimum size=\cvPictureWidth,
          path picture={%
            \node at (path picture bounding box.center){%
            \includegraphics[width=\cvPictureWidth]{img/rocket.png}
            };
          }]{};
      \end{tikzpicture}

      {\LARGE
      Richard Connor

      \vspace{10pt}

      Johnstone}
      
      \vspace{0.1in}
      
      {\color{cvAccent} Aerospace Engineer}
      
      \vspace{0.1in}

      \ruleline{Profile}
      
      Currently pursuing employment as an Aerospace Software Engineer while
      earning a Masters in Aerospace Engineering (focus in Astrodynamics) at the
      University of Colorado -- Boulder.
      
      \vspace{4pt}
      
      \ruleline{Contact}
      
      \vspace{8pt}
      
      \begin{tikzpicture}[every node/.style={inner sep=0pt, outer sep=0pt}]
        \matrix [
          column 1/.style={anchor=center,contactIcon},
          column 2/.style={anchor=west,align=left,contactIcon},
          column sep=5pt,
          row sep=5pt] (contact) {%
          \node{\faEnvelope}; 
            & \node{\href{mailto:connor@richardconnorjohnstone.com}{%
              {\small connor@richardconnorjohnstone.com}}};\\
          \node{\faMapMarker}; 
            & \node{690 Inca Parkway\\Boulder, CO 80303};\\
          \node{\faPhone}; 
            & \node{+1 (502) 414-1242};\\
          \node{\faGlobe}; 
            &
            \node{\href{https://richardconnorjohnstone.com}{%
              richardconnorjohnstone.com}};\\
          \node{\faGithub}; 
            & \node{\href{https://github.com/rconnorjohnstone}{rconnorjohnstone}};\\
          \node{\faLinkedinSquare}; 
            & \node{\href{https://www.linkedin.com/rconnorjohnstone}{%
              rconnorjohnstone}};\\
      };
      \end{tikzpicture}
      
      \vspace{4pt}
      
      \ruleline{Languages}
      
      \vspace{4pt}
      
      \begin{tikzpicture}[every node/.style={text depth=0pt,inner sep=0pt,outer sep=0pt}]
        \matrix [
          column 1/.style={anchor=east},
          column 2/.style={anchor=west},
          column 3/.style={anchor=east},
          column 4/.style={anchor=west},
          column sep=5pt,
          row sep=3pt,
          ] (contact) {%
          \node[font=\footnotesize]{Python}; & \node[progressArea](language 1) {};
          \node[languageText]{Julia}; & \node[progressArea] (language 2) {}; \\
          \node[languageText]{C++};  & \node[progressArea] (language 3) %
          {};
          \node[languageText]{MATLAB}; & \node[progressArea] (language 4) {}; \\
          \node[languageText]{\LaTeX}; & \node[progressArea] (language 5) %
          {};
          \node[languageText]{MathematicaIsALanguage}; & \node[progressArea] (language 6) {}; \\
          \node[languageText]{Rust}; & \node[progressArea] (language 7) {}; \\
        };
        \draw (language 1.west) 
        node[progressBar,minimum width=5/5*\cvLanguageBarWidth] {};
        \draw (language 2.west) node[progressBar,minimum width=5/5*\cvLanguageBarWidth] {};
        \draw (language 3.west) node[progressBar,minimum width=4/5*\cvLanguageBarWidth] {};
        \draw (language 4.west) node[progressBar,minimum width=4/5*\cvLanguageBarWidth] {};
        \draw (language 5.west) node[progressBar,minimum width=4/5*\cvLanguageBarWidth] {};
        \draw (language 6.west) node[progressBar,minimum width=3/5*\cvLanguageBarWidth] {};
        \draw (language 7.west) node[progressBar,minimum width=1/5*\cvLanguageBarWidth] {};
      \end{tikzpicture}

    \end{center}
  \end{minipage}
  \vspace*{\fill}
  
\begin{tikzpicture}[
  every node/.style={
    inner sep=0pt,
    outer sep=0pt
  },
  remember picture,
  overlay,
  shift={($(current page.north west)%
           +(\cvSideWidth+3\cvMargin+\cvTimeDotSep,-\cvMargin)$)}]
  % main content  
  
  \node[sectionTitle] at (0,0) (title 1) {\cvSection{Education}};
  \node[left=\cvTimeDotSep of title 1,headerIcon] {\faGraduationCap};
  \begin{scope}[on background layer]
    \draw[line width=2pt,cvColor] 
      let \p1=(title 1.south west), 
          \p2=(current page.east) in 
      (\x1,\y1-0.1cm) to (\x2,\y1-0.1cm);
  \end{scope}
  
  % item 1
  \node[
      below=\cvSectionSep of title 1.south west,
      eventdottext] 
      (item 1 header) 
      {\phantom{Evening}};
  \node[
    below=\cvSectionSep of title 1.south west,
    sectionedutext] 
    (item 1) 
    {\cvEducation{Evening class: Chinese}%
                 {Some School, City. September 2015 -- June 2016}%
                 {Achieved A2 language skill in Chinese (Mandarin).}};
  \node[
    left=\cvTimeDotSep of item 1 header,
    timedot] 
    (start) 
    {};
    
  % item 2
  \node[
      below=\cvSectionSep of item 1.south west,
      eventdottext] 
      (item 2 header) 
      {\phantom{Evening}};
  \node[
    below=\cvSectionSep of item 1.south west,
    sectionedutext] 
    (item 2) 
    {\cvEducation{Bachelor of Science in Biochemistry and Biotechnology}%
                 {University, City. September 2009 -- June 2012}%
                 {General training in the basic sciences and the molecular life science.}};
  \node[
    left=\cvTimeDotSep of item 2 header,
    timedot] 
    {};
    
  % item 3
  \node[
      below=\cvSectionSep of item 2.south west,
      eventdottext] 
      (item 3 header) 
      {\phantom{Evening}};
  \node[
    below=\cvSectionSep of item 2.south west,
    sectionedutext] 
    (item 3) 
    {\cvEducation{Master of Science in Biochemistry and Biotechnology}%
                 {University, City. September 2012 -- June 2015}%
                 {Acquisition of insight into and knowledge of possibilities for application in the area of biochemistry and biotechnology, specific with applications in biomedical application and due problem-solving reasoning skills.}};
  \node[
    left=\cvTimeDotSep of item 3 header,
    timedot] 
    {};
  \node[
    left=\cvTimeDotSep of item 3.south west,
    invisibletimedot] 
    (end) 
    {};
  \draw (start) to (end.center);
  
  %%%%%%%%%%%%%%
  % Experience %
  %%%%%%%%%%%%%%
  
  \node[below=0.6cm of item 3.south west,sectionTitle] (title 2) {\cvSection{Experience}};
  \node[left=\cvTimeDotSep of title 2,headerIcon] {\faBriefcase};
  \node[below=0.6cm of item 3.south west,sectionTitle] (title 2 dummy) {\phantom{\cvSection{Education}}};
  \begin{scope}[on background layer]
    \draw[line width=2pt,cvColor] 
      let \p1=(title 2 dummy.south west), 
          \p2=(current page.east) in 
      (\x1,\y1-0.1cm) to (\x2,\y1-0.1cm);
  \end{scope}
  
\node[
      below=\cvSectionSep of title 2.south west,
      eventdottext] 
      (item 1 header) 
      {\phantom{Evening}};
  \node[
    below=\cvSectionSep of title 2.south west,
    sectionedutext] 
    (item 1) 
    {\cvExperience%
      {Student Job}%
      {Company X}%
      {Location X}%
      {Summer 2010}%
      {Integer tincidunt dapibus consectetur. Nullam tristique aliquam luctus. Sed ut ante velit. Nulla pharetra maximus lacus at elementum. Suspendisse sodales consectetur metus, sit amet ultricies ipsum ultrices ut.}};
  \node[
    left=\cvTimeDotSep of item 1 header,
    timedot] 
    (start) 
    {};
    
  % item 2
  \node[
      below=\cvSectionSep of item 1.south west,
      eventdottext] 
      (item 2 header) 
      {\phantom{Evening}};
  \node[
    below=\cvSectionSep of item 1.south west,
    sectionedutext] 
    (item 2) 
    {\cvExperience%
      {Internship}%
      {Company Y}%
      {Location Y}%
      {June 2012 -- August 2012}%
      {Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi dictum cursus sapien, id eleifend mi pellentesque id. Etiam lobortis eu odio a sodales. Phasellus ut dolor feugiat, lacinia lectus in, blandit metus. Fusce lacinia dolor et metus gravida pulvinar sit amet et ex.}};
  \node[
    left=\cvTimeDotSep of item 2 header,
    timedot] 
    {};
    
  % item 3
  \node[
      below=\cvSectionSep of item 2.south west,
      eventdottext] 
      (item 3 header) 
      {\phantom{Evening}};
  \node[
    below=\cvSectionSep of item 2.south west,
    sectionedutext] 
    (item 3) 
    {\cvExperience{Internship}%
       {Company Z}%
       {Location Z}%
       {August 2014 -- September 2014}%
       {Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi dictum cursus sapien, id eleifend mi pellentesque id. Etiam lobortis eu odio a sodales. Phasellus ut dolor feugiat, lacinia lectus in, blandit metus.  Fusce lacinia dolor et metus gravida pulvinar sit amet et ex.}};
  \node[
    left=\cvTimeDotSep of item 3 header,
    timedot] 
    {};
  \node[
    left=\cvTimeDotSep of item 3.south west,
    invisibletimedot] 
    (end) 
    {};
  \draw (start) to (end.center);

  %%%%%%%%%%
  % Skills %
  %%%%%%%%%%
  
  \node[below=0.6cm of item 3.south west,sectionTitle] (title 3) {\cvSection{Skills}};
  \node[left=\cvTimeDotSep of title 3,headerIcon] {\faStar};
  \node[below=0.6cm of item 3.south west,sectionTitle] (title 3 dummy) {\phantom{\cvSection{Education}}};
  \begin{scope}[on background layer]
    \draw[line width=2pt,cvColor] 
      let \p1=(title 3 dummy.south west), 
          \p2=(current page.east) in 
      (\x1,\y1-0.1cm) to (\x2,\y1-0.1cm);
  \end{scope}
  
\matrix[matrix of nodes,
        below=0.6cm of title 3.south west,
        anchor=north west,
        column sep=6pt,
        row sep=6pt,
        every node/.style={Text Depth=tdSkills},
        column 1/.style={anchor=east,align=left},
        column 2/.style={anchor=west},
        column 3/.style={anchor=east,align=left},
        column 4/.style={anchor=west}] (skills) {
        \cvSkill{5} & MATLAB           & \cvSkill{5} & \LaTeX \\
        \cvSkill{4} & Python           & \cvSkill{4} & VHDL \\
        \cvSkill{4} & Microsoft Office & \cvSkill{4} & macOS \\
        \cvSkill{3} & C, C++           & \cvSkill{3} & Electrical Engineering \\};


\node[below=0.6cm of skills.south west,sectionTitle] (title 4) {\cvSection{References}};
\node[left=\cvTimeDotSep of title 4,headerIcon] {\faLink};
\node[below=0.6cm of skills.south west,sectionTitle] (title 4 dummy) {\phantom{\cvSection{Education}}};
\begin{scope}[on background layer]
  \draw[line width=2pt,cvColor] 
    let \p1=(title 4 dummy.south west), 
        \p2=(current page.east) in 
    (\x1,\y1-0.1cm) to (\x2,\y1-0.1cm);
\end{scope}


\matrix[matrix of nodes,
      below=0.6cm of title 4.south west,
      anchor=north west,
      column sep=6pt,
      row sep=6pt,
      every node/.style={Text Depth=tdRefs,anchor=west}] {
      Jane Smith           & \\
      Company ABC Co. Ltd. & \\
      Job title            & \\
      Street lane 2        & \\
      B-1150 Brussels      & \\
      +1 781 555 1212      & \\};

\end{tikzpicture}

\end{document}
