A lot of work on the presentation

The shell auto-image now runs code and turns the output into an image
that is embedded into the document

The prompt is configurable in /bin/prompt

The first draft is done up until the references section
master
Jonathan Hodgson 4 years ago
parent 63c02e13f9
commit 22ef5f581d
  1. 29
      Makefile
  2. 6
      README.md
  3. 7
      bin/prompt
  4. 14
      bin/tidy
  5. 6
      code-examples/python-start.py
  6. 6
      greeting.py
  7. 482
      main.latex
  8. 20
      shell/first-cat-commit-file
  9. 5
      shell/first-commit
  10. 6
      shell/first-diff
  11. 8
      shell/git-init
  12. 7
      shell/log-with-decoration
  13. 10
      shell/second-commit-with-log
  14. 12
      shell/show-staging-area
  15. 11
      shell/touch-git-status

@ -1,5 +1,7 @@
GRAPHICS_FILES = $(shell bin/get-auto-graphics)
.PHONY = open clean clean-all clean-images
main.pdf: main.latex $(GRAPHICS_FILES)
pdflatex -shell-escape -output-directory="./" main.latex
@ -9,22 +11,43 @@ with-notes.pdf: with-notes.latex
with-notes.latex: main.latex $(GRAPHICS_FILES)
sed 's/\%showNotes\%//' main.latex > with-notes.latex
only-notes.pdf: only-notes.latex
pdflatex -shell-escape -output-directory="./" only-notes.latex
only-notes.latex: main.latex $(GRAPHICS_FILES)
sed 's/\%onlyNotes\%//' main.latex > only-notes.latex
auto-images/auto-xkcd-%.png:
mkdir -p auto-images
curl https://xkcd.com/$*/info.0.json 2> /dev/null | jq '.img' | sed 's/.png/_2x.png/g' | xargs curl -s -o $@
auto-images/auto-shell-%.pdf: auto-images/auto-shell-%.svg
inkscape auto-images/auto-shell-$*.svg --export-area-drawing --batch-process --export-type=pdf --export-filename=$@
mkdir -p auto-images
inkscape auto-images/auto-shell-$*.svg --export-area-drawing --batch-process --export-type=pdf --export-filename=$@
auto-images/auto-shell-%.svg: shell-output/%.out
auto-images/auto-shell-%.svg: auto-images/%.out
mkdir -p auto-images
cat shell-output/$*.out | bin/ansi2svg > $@
cat auto-images/$*.out | bin/ansi2svg > $@
auto-images/%.out: shell/%
mkdir -p auto-images
shell/$* | bin/tidy | bin/prompt > $@
open: main.pdf
setsid zathura main.pdf &
open-with-notes: with-notes.pdf
setsid zathura with-notes.pdf &
clean:
- rm *.aux *.log *.out *.toc *.nav *.snm *.pdf *.vrb
-rm -rf _minted-main
-rm -rf _minted-with-notes
-rm -rf _minted-only-notes
- rm with-notes.latex
- rm only-notes.latex
- rm -rf /tmp/demo
clean-images:
- rm -rf auto-images/

@ -18,6 +18,12 @@ To build with speaker notes:
make with-notes.pdf
```
To only build the speaker notes:
```bash
make only-notes.pdf
```
## Auto Images
The build system will generate certain types of graphics for the presentation as part of the build system. The resultant files will always go in the `auto-images` folder. As a result, this folder is not under version control.

@ -0,0 +1,7 @@
#!/usr/bin/env bash
BLUE='\033[34m'
NC='\033[0m' # No Color
cat - | sed "s/^\\\$/$(echo -e "$BLUE")$(echo -e "$NC")/"
#cat - | sed "s/^\\\$/$(echo -e "$BLUE")\$$(echo -e "$NC")/"

@ -0,0 +1,14 @@
#!/usr/bin/env bash
fixAnsiReset(){
FIND="$(echo -e "\033[m")"
REPLACE="$(echo -e "\033[0m")"
#sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g"
cat - | sed -r 's/\x1B\[m/\x1B\[0m/g'
}
fixTab(){
cat - | sed 's/\t/ /g'
}
cat - | fixAnsiReset | fixTab

@ -0,0 +1,6 @@
import sys
def main():
print("Hello")
if __name__ == "__main__":
main()

@ -0,0 +1,6 @@
import sys
def main():
print("Hello")
if __name__ == "__main__":
main()

@ -4,12 +4,22 @@
\usepackage{pgfpages}
%showNotes%\setbeameroption{show notes on second screen=right}
%\setbeamertemplate{note page}{\pagecolor{yellow!5}\insertnote}
\setbeamertemplate{note page}{\setlength{\parskip}{12pt}\pagecolor{yellow!5}\vfill\insertnote\vfill}
%showNotes%\setbeamertemplate{note page}{\setlength{\parskip}{12pt}\pagecolor{yellow!5}\vfill\insertnote\vfill}
%onlyNotes%\setbeameroption{show only notes}
%onlyNotes%\setbeamertemplate{note page}{ \begin{center} \insertslideintonotes{0.3} \end{center} \setlength{\parskip}{12pt} \pagecolor{yellow!5} \tiny\insertnote }
\setlength{\parskip}{12pt}
\usepackage{palatino}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{pdfpages}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\tikzstyle{commit} = [circle, text centered, line width=2, minimum size=1.5cm, draw=blue, fill=blue!80, text=white]
\tikzstyle{branch} = [ellipse, text centered, text=green]
\tikzstyle{arrow} = [thick, <-, draw=blue]
\usepackage{dirtree}
\usepackage{csquotes}
%\usepackage{gitdags}
@ -96,35 +106,6 @@
\end{frame}
\begin{frame}
\frametitle{Let's avoid this}
\dirtree{%
.1 Project.
.2 draft.
.3 some.
.3 files.
.2 final-draft.
.3 some.
.3 files.
.2 final.
.3 some.
.3 files.
.2 real-final.
.3 some.
.3 files.
.2 actual-real-final.
.3 some.
.3 files.
}
\note{%
I think, being honest, we have all done this. This sort of works, if you're working on something by yourself. Once you start collaborating on software, you are going to have a bad time.
However, this is a simple approach and not a million miles from what Git does internally.
I want this to be quite interactive so first things first, let's get Git setup.
}
\end{frame}
\begin{frame}[fragile]
\frametitle{Install}
@ -176,6 +157,9 @@
\textbf{Pick One}
\begin{minted}{bash}
# Set editor to vim
git config --global core.editor "vim"
# Set editor to nano
git config --global core.editor "nano"
@ -194,12 +178,191 @@
\end{frame}
\begin{frame}[fragile]
\frametitle{Create a repository}
\frametitle{Setting It Up}
\framesubtitle{Preferences}
\textbf{Pick One}
\begin{minted}{bash}
mkdir Project
cd Project
git init
# No colour
git config --global color.ui never
# Auto colour
git config --global color.ui auto
# Force colour
git config --global color.ui always
# Overide for a command
git -c color.ui=always status > ~/some-file
\end{minted}
\note{%
On Linux systems, this is set to auto by default. Might be different on a Mac. Generally auto is probably what you want. It will be coloured unless you are piping the output to a file or another process.
Take note of the incorrect spelling of colour.
You can override all configuration options on an individual command basis if you like.
}
\end{frame}
\begin{frame}
\frametitle{Terminology}
\framesubtitle{Objects}
\textbf{Blob} In Git, a file is called a blob.
\textbf{Tree} In Git, a directory is called a tree.
\textbf{Commit} A snapshot of your code
All of these are referenced by a hash and stored in the \mintinline{bash}{.git/objects/} directory.
\note{%
Most Git tutorials I have come across focus on memorizing commands. This way, the commands feel like magic and there is never really any understanding of what the commands do under the hood.
}
\end{frame}
\begin{frame}
\frametitle{Naïve Approach}
\dirtree{%
.1 Project.
.2 draft.
.3 some.
.3 files.
.2 final-draft.
.3 some.
.3 files.
.2 final.
.3 some.
.3 files.
.2 real-final.
.3 some.
.3 files.
.2 actual-real-final.
.3 some.
.3 files.
}
\note{%
I think, being honest, we have all done this. This sort of works, if you're working on something by yourself. Once you start collaborating on software, you are going to have a bad time.
However, this is a simple approach and not a million miles from what Git does internally.
I want this to be quite interactive so first things first, let's get Git setup.
}
\end{frame}
\begin{frame}
\frametitle{Model it}
\begin{center}
\begin{tikzpicture}
%\draw (-1.5,-1.5) rectangle (7.5,1.5);
%\node at (-2.5,0) {master};
\node[commit,minimum size=2cm] at (0,0) (commit1) {Draft};
\node[commit,minimum size=2cm] at (3,0) (commit2) {Final Draft};
\node[commit,minimum size=2cm] at (6,0) (commit3) {Final};
\draw[arrow] (commit1) -- (commit2);
\draw[arrow] (commit2) -- (commit3);
\node[draw,text width=1.8cm,anchor=north,align=center] at (0, -1.5) {\small \vdots\\[0.1cm] };
\node[draw,text width=1.8cm,anchor=north,align=center] at (3, -1.5) {\small \vdots\\[0.1cm] Draft };
\node[draw,text width=1.8cm,anchor=north,align=center] at (6, -1.5) {\small \vdots\\[0.1cm] Final Draft };
\end{tikzpicture}
\end{center}
\note{%
\begin{itemize}
\item This is a simple representation of the folder structure we saw, although for simplicity, I'm only showing 3 revisions.
\item Notice that so the computer knows the order, somewhere in each "snapshot", we include a reference to the previous snapshot
\end{itemize}
}
\end{frame}
\begin{frame}
\frametitle{Commits}
\begin{center}
\begin{tikzpicture}
%\draw (-1.5,-1.5) rectangle (7.5,1.5);
%\node at (-2.5,0) {master};
\node[commit] at (0,0) (commit1) {93e4d3d\ldots};
\node[commit] at (3,0) (commit2) {2557962\ldots};
\node[commit] at (6,0) (commit3) {od68560\ldots};
\draw[arrow] (commit1) -- (commit2);
\draw[arrow] (commit2) -- (commit3);
\node[draw,text width=1.8cm,anchor=north,align=center] at (0, -1.5) {\small \vdots\\[0.1cm] };
\node[draw,text width=1.8cm,anchor=north,align=center] at (3, -1.5) {\small \vdots\\[0.1cm] 93e4d3d\ldots };
\node[draw,text width=1.8cm,anchor=north,align=center] at (6, -1.5) {\small \vdots\\[0.1cm] 2557962\ldots };
\end{tikzpicture}
\end{center}
\note{%
\begin{itemize}
\item Rather than human readable names, Git references each snapshot (called a commit) by a cryptographic hash. Currently using a hardened sha1 but there is an effort to move to sha256.
\item Similarly to the model above, each commit references the previous (except the first obviously)
\item The commit also includes meta information such as the committer, a timestamp and a message.
\item We will look at this in more detail a bit later.
\end{itemize}
}
\end{frame}
\begin{frame}
\frametitle{Commits / Branches}
\begin{center}
\begin{tikzpicture}
%\draw (-1.5,-1.5) rectangle (7.5,1.5);
%\node at (-2.5,0) {master};
\node[commit] at (0,0) (commit1) {};
\node[commit] at (2,0) (commit2) {A};
\node[commit] at (4,0) (commit3) {B};
\node[commit] at (4,-2) (commit3b) {C};
\draw[arrow] (commit1) -- (commit2);
\draw[arrow] (commit2) -- (commit3);
\draw[arrow] (commit2) -- (commit3b);
\end{tikzpicture}
\end{center}
\note{%
The linear graph we just saw is an overly simplistic representation. In reality, Git represents history using a Directed acyclic graph which allows parents to be shared my multiple commits. This is useful because it allows for Branches. We will look at these a bit more later.
It is good practice to develop features on a separate branch. This allows for multiple people to work on a project as well as allowing things like bug-fixes to be deployed without having to worry about interference from a new feature.
}
\end{frame}
\begin{frame}
\frametitle{Commits / Branches}
\begin{center}
\begin{tikzpicture}
%\draw (-1.5,-1.5) rectangle (7.5,1.5);
%\node at (-2.5,0) {master};
\node[commit] at (0,0) (commit1) {};
\node[commit] at (2,0) (commit2) {};
\node[commit] at (5,0) (commit4) {A};
\node[commit] at (8,0) (commit5) {C};
\node[commit] at (4,-2) (commit3b) {};
\node[commit] at (6,-2) (commit4b) {B};
\draw[arrow] (commit1) -- (commit2);
\draw[arrow] (commit2) -- (commit4);
\draw[arrow] (commit4) -- (commit5);
\draw[arrow] (commit2) -- (commit3b);
\draw[arrow] (commit3b) -- (commit4b);
\draw[arrow] (commit4b) -- (commit5);
\end{tikzpicture}
\end{center}
\note{%
As well as 2 commits' ability to share a parent, the opposite is also true, Here, we see that a commit is able to have multiple parents.
This is called a merge commit - because it merges two branches. In a lot of situations git is smart enough to auto-merge branches although at times human intervention is necessary.
By default, git creates a branch called Master when you create a repository.
}
\end{frame}
\begin{frame}
\frametitle{Create a repository}
\begin{center}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-shell-git-init.pdf}
\end{center}
\note{%
Do this in a live terminal. MAKE SURE YOU MAKE YOUR FONT BIGGER
@ -209,52 +372,271 @@
\begin{frame}[fragile]
\frametitle{Git status}
\begin{center}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-shell-touch-git-status.pdf}
\end{center}
\note{%
Create repo and create a file called greeting.py. Make sure to mark it as executable.
}
\end{frame}
\begin{frame}[fragile]
\frametitle{Staging Area}
\begin{minted}{bash}
git status
# Add files / or directories
git add <file|directory> [<file|directory>...]
# Add everything not in gitignore
git add -A
\end{minted}
\note{%
The staging area is where you put things that you want to be committed.
It can often be useful to manually split changes up into different commits. You might be working on feature A and feature B simultaneously. It is good practice to have each feature as a separate commit so you could add feature A to the staging area, commit it, then do the same for feature B.
We will talk about \mintinline{bash}{.gitignore} in a bit.
}
\end{frame}
\begin{frame}
\frametitle{Staging Area}
\begin{center}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-shell-git-status.pdf}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-shell-show-staging-area.pdf}
\end{center}
\note{%
Here can use git status to see what is in the staging area. They are listed in the "Changes to be committed" section. By default, they will also be green if you have colour switched on.
}
\end{frame}
\begin{frame}[fragile]
\frametitle{Committing}
\begin{minted}{bash}
git commit
\end{minted}
\begin{itemize}
\item First line should be concise summary around 50 chars
\item Body Should be wrapped to around 70 chars
\item There should be an empty line separating summary from body
\item If contributing to a project, check per-project guidelines
\begin{itemize}
\item Normally in contributing.md or similar
\end{itemize}
\item Use the imperative: "Fix bug" and not "Fixed bug" or "Fixes bug."
\end{itemize}
\note{%
First line is often shown by various tools
70 chars allows for good email etiquette. Allowing for 80 char hard wrap with after a few reply indents
Generally you will want to write in imperative as this is what automatic commits like merge do.
}
\end{frame}
\begin{frame}
\frametitle{Terminology}
\frametitle{When should you commit?}
\framesubtitle{Commit early, commit often}
\begin{itemize}
\item Every time you complete a small change or fix a bug
\item You don't normally want to commit broken code (intentionally at least)
\item In some instances you might want to auto-commit - but probably not too often.
\begin{itemize}
\item Normally this works if changes can't break something. E.g. Password Manager
\end{itemize}
\end{itemize}
\note{%
Unfortunately, this doesn't have one simple answer.
\textbf{Blob} In Git, a file is called a blob.
Some examples of auto-committing are for your password manager.
}
\end{frame}
\textbf{Tree} In Git, a directory is called a tree.
\begin{frame}
\frametitle{Commit Messages}
\begin{center}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-xkcd-1296.png}
\end{center}
\note{%
In case you hadn't noticed, I quite like Randall Munroe.
\textbf{Root} The top level directory is called the root.
I am bad for this, particularly on personal projects.
}
\end{frame}
\begin{frame}[fragile]
\frametitle{Commit}
\begin{minted}{bash}
# Open editor for message
git commit
# Read message from file
git commit -F <file or - for stdin>
# Provide message directly
git commit -m "<message>"
\end{minted}
\begin{center}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-shell-first-commit.pdf}
\end{center}
\note{%
Pretty simple stuff.
Running git commit will open your editor.
Because we don't have enough roots in Linux. :/
I only really use -F if I am doing so from a script
}
\end{frame}
Now we can start doing stuff
\begin{frame}[fragile]
\frametitle{Diff}
\begin{minted}{bash}
# Diff between last commit and current state
git diff
# Diff between 2 commits or references
git diff commit1..commit2
# Same as above but on a single file
git diff a/file
\end{minted}
\note{%
Diff is pretty smart. It will normally work for whatever combinations of commits, references (more on that later) or files.
}
\end{frame}
\begin{frame}
\frametitle{Diff}
\begin{center}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-shell-first-diff.pdf}
\end{center}
\note{%
These are hopefully quite easy to understand. Red lines mean a line was removed, green means a line was added.
}
\end{frame}
\begin{frame}
\frametitle{Log}
\begin{center}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-shell-second-commit-with-log.pdf}
\end{center}
\note{%
Here we see a commit done with the -m flag. I generally only use -m if it is a trivial change like this and there is no need to have a body.
You can see that the log shows a list of the two commits we have made on this project.
The git log command has a lot of flags. We will see some of them later.
}
\end{frame}
\begin{frame}
\frametitle{Commits}
\frametitle{Under the hood}
\begin{center}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-xkcd-1296.png}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-shell-first-cat-commit-file.pdf}
\end{center}
\note{%
I said earlier that we would be looking at how all this works at quite a low level. This is where that starts.
We can also use the cat-file command built into git to do the same thing. We can see that Commits, trees and blobs are all stored in the same way.
You will also see that you can often use a prefix of the first 4 or more characters of a hash. It is quite common to use the first 7 or 8.
Hopefully you will see from this that the inner workings of git isn't that complicated.
}
\end{frame}
\begin{frame}
\frametitle{Commit Messages}
\frametitle{References}
\begin{itemize}
\item We have just seen that commits are simply (compressed) text files, addressed by a hash.
\item References are a way of addressing them without remembering the hash.
\item Unlike the hashes, references can change - and they do change.
\end{itemize}
\note{%
We've seen a couple of these (sort of)
Master and Head
}
\end{frame}
\begin{frame}
\frametitle{References}
\begin{center}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-xkcd-1296.png}
\includegraphics[width=\textwidth,height=0.8\textheight,keepaspectratio]{auto-shell-log-with-decoration.pdf}
\end{center}
\note{%
There are two references we can see here, master and HEAD.
}
\end{frame}
\begin{frame}
\frametitle{When should you commit?}
\frametitle{Branch References}
\note{%
}
\end{frame}
\begin{frame}
\frametitle{gitignore}
\end{frame}
\begin{frame}
\frametitle{Useful supporting tools}
\framesubtitle{Bat}
\note{%
Bat is described as cat with wings.
It adds syntax highlighting to files. Useful even if you're not using Git
As this is a git talk, it shows lines that have changed since the last commit
}
\end{frame}
\begin{frame}
\frametitle{Useful supporting tools}
\framesubtitle{RigGrep / Fd}
\note{%
Alternatives to grep and find
Fd, in particular, is not a full replacement for find but does most of what you want
Both (by default) will respect your gitignore file.
}
\end{frame}
\begin{frame}
\frametitle{Useful supporting tools}
\framesubtitle{Delta}
\note{%
This is a tool that can make your diff output look better.
}
\end{frame}
\begin{frame}
\frametitle{Useful supporting tools}
\framesubtitle{Shell Integration}
\note{%
Takes 2 forms. Prompt and completion
}
\end{frame}
\begin{frame}
\frametitle{Useful supporting tools}
\framesubtitle{Pass}
\note{%
Password manager
}
\end{frame}
\begin{frame}
\frametitle{Useful supporting tools}
\framesubtitle{BFG Repo Cleaner}
\begin{itemize}
\item You'll need something like this when you realise you have just committed your ssh keys
\item Mistakes happen
\end{itemize}
\note{%
For the time that you accidentally commit your ssh keys.
I accidentally committed a database for an Woocommerce site.
}
\end{frame}
\end{document}
%\textbf{Staging area} Waiting area before a commit

@ -0,0 +1,20 @@
#!/usr/bin/env bash
cd /tmp/demo
currentCommit="$(git rev-parse HEAD)"
fileName="$(echo $currentCommit | sed 's/\(..\)/\1\//')"
echo -e "\$ zlib-flate -uncompress < .git/objects/$fileName"
zlib-flate -uncompress < ".git/objects/$fileName" | tr '\000' '␀'
echo "\$ zlib-flate -uncompress < .git/objects/$fileName | sha1sum"
echo -e "$currentCommit"
currentCommitTree="$(git cat-file -p $currentCommit | grep tree | cut -d' ' -f2)"
echo "\$ git cat-file -p $(echo $currentCommitTree | grep -o '^.......') "
git -c color.ui=always cat-file -p "$currentCommitTree"
aFile="$(git cat-file -p $currentCommitTree | grep blob | head -n 1 | cut -d' ' -f3 | cut -d' ' -f1)"
echo "\$ git cat-file -p $(echo $aFile | grep -o '^.......') "
git -c color.ui=always cat-file -p "$aFile"

@ -0,0 +1,5 @@
#!/usr/bin/env bash
cd /tmp/demo/
echo '$ git commit'
echo -e "Add greeting.py\n\nAdds the first file, currently always prints Hello" | git -c color.ui=always commit -F -

@ -0,0 +1,6 @@
#!/usr/bin/env bash
cd /tmp/demo
sed -i 's/Hello/Hello World/' ./greeting.py
echo '$ git diff'
git -c color.ui=always diff

@ -0,0 +1,8 @@
#!/usr/bin/env bash
rm -rf /tmp/demo/
echo '$ mkdir /tmp/demo'
mkdir -p /tmp/demo/
echo '$ cd /tmp/demo'
cd /tmp/demo/
echo '$ git init'
git -c colour.ui=always init

@ -0,0 +1,7 @@
#!/usr/bin/env bash
cd /tmp/demo/
git config colour.ui always
echo '$ git log'
git -c color.ui=always log --decorate=short

@ -0,0 +1,10 @@
#!/usr/bin/env bash
cd /tmp/demo/
echo "$ git commit -m \"Change \\\"Hello\\\" to \\\"Hello World\\\"\""
git add greeting.py
git commit -m "Change \"Hello\" to \"Hello World\""
echo "..."
echo "$ git log"
git -c color.ui=always log

@ -0,0 +1,12 @@
#!/usr/bin/env bash
cd /tmp/demo
echo '$ git status'
git -c color.ui=always status
echo '$ git add greeting.py'
git add greeting.py
echo '$ git status'
git -c color.ui=always status

@ -0,0 +1,11 @@
#!/usr/bin/env bash
DIR="$(dirname "$(readlink -f "$0")")"
cd /tmp/demo
echo '$ touch greeting.py'
cp "${DIR}/../code-examples/python-start.py" greeting.py
echo '$ chmod +x !$'
chmod +x greeting.py
echo '$ vim greeting.py'
echo '$ git status'
git -c color.ui=always status
Loading…
Cancel
Save