%%script bash

# Dependency Variables, set to match your project directories

cat <<EOF > /tmp/variables.sh
export project_dir=$HOME/vscode  # change vscode to different name to test git clone
export project=\$project_dir/teacher  # change teacher to name of project from git clone
export project_repo="https://github.com/nighthawkcoders/teacher.git"  # change to project of choice
EOF
%%script bash

# Extract saved variables
source /tmp/variables.sh

# Output shown title and value variables
echo "Project dir: $project_dir"
echo "Project: $project"
echo "Repo: $project_repo"
Project dir: /Users/sergis/vscode
Project: /Users/sergis/vscode/teacher
Repo: https://github.com/nighthawkcoders/teacher.git
%%script bash

# Extract saved variables
source /tmp/variables.sh

echo "Using conditional statement to create a project directory and project"

cd ~    # start in home directory

# Conditional block to make a project directory
if [ ! -d $project_dir ]
then 
    echo "Directory $project_dir does not exists... makinng directory $project_dir"
    mkdir -p $project_dir
fi
echo "Directory $project_dir exists." 

# Conditional block to git clone a project from project_repo
if [ ! -d $project ]
then
    echo "Directory $project does not exists... cloning $project_repo"
    cd $project_dir
    git clone $project_repo
    cd ~
fi
echo "Directory $project exists."
Using conditional statement to create a project directory and project
Directory /Users/sergis/vscode exists.
Directory /Users/sergis/vscode/teacher exists.
%%script bash

# Extract saved variables
source /tmp/variables.sh

echo "Navigate to project, then navigate to area wwhere files were cloned"
cd $project
pwd

echo ""
echo "list top level or root of files with project pulled from github"
ls

Navigate to project, then navigate to area wwhere files were cloned
/Users/sergis/vscode/teacher

list top level or root of files with project pulled from github
Gemfile
LICENSE
Makefile
README.md
_config.yml
_data
_includes
_layouts
_notebooks
_posts
assets
csa.md
csp.md
csse.md
images
index.md
indexBlogs.md
scripts
teacher
%%script bash

# Extract saved variables
source /tmp/variables.sh

echo "Navigate to project, then navigate to area wwhere files were cloned"
cd $project
pwd

echo ""
echo "list all files in long format"
ls -al   # all files -a (hidden) in -l long listing
Navigate to project, then navigate to area wwhere files were cloned
/Users/sergis/vscode/teacher

list all files in long format
total 104
drwxr-xr-x  24 sergis  staff   768 Aug 30 19:03 .
drwxr-xr-x   6 sergis  staff   192 Aug 29 14:55 ..
drwxr-xr-x  14 sergis  staff   448 Aug 30 19:03 .git
drwxr-xr-x   3 sergis  staff    96 Aug 17 21:21 .github
-rw-r--r--   1 sergis  staff   176 Aug 30 19:03 .gitignore
-rw-r--r--   1 sergis  staff   122 Aug 17 21:21 Gemfile
-rw-r--r--   1 sergis  staff  1081 Aug 17 21:21 LICENSE
-rw-r--r--   1 sergis  staff  3132 Aug 30 19:03 Makefile
-rw-r--r--   1 sergis  staff  6853 Aug 21 15:20 README.md
-rw-r--r--   1 sergis  staff   607 Aug 17 21:21 _config.yml
drwxr-xr-x   6 sergis  staff   192 Aug 17 21:21 _data
drwxr-xr-x  11 sergis  staff   352 Aug 30 19:03 _includes
drwxr-xr-x   6 sergis  staff   192 Aug 17 21:21 _layouts
drwxr-xr-x   4 sergis  staff   128 Sep  4 10:02 _notebooks
drwxr-xr-x  13 sergis  staff   416 Aug 30 19:03 _posts
drwxr-xr-x   4 sergis  staff   128 Aug 17 21:21 assets
-rw-r--r--   1 sergis  staff    92 Aug 17 21:21 csa.md
-rw-r--r--   1 sergis  staff    98 Aug 17 21:21 csp.md
-rw-r--r--   1 sergis  staff   108 Aug 17 21:21 csse.md
drwxr-xr-x  35 sergis  staff  1120 Aug 30 19:03 images
-rw-r--r--   1 sergis  staff  5149 Aug 17 21:21 index.md
-rw-r--r--   1 sergis  staff    53 Aug 17 21:21 indexBlogs.md
drwxr-xr-x   9 sergis  staff   288 Aug 21 15:20 scripts
drwxr-xr-x@ 23 sergis  staff   736 Aug 17 21:31 teacher
%%script bash

# Extract saved variables
source /tmp/variables.sh

echo "Look for posts"
export posts=$project/_posts  # _posts inside project
cd $posts  # this should exist per fastpages
pwd  # present working directory
ls -l  # list posts
Look for posts
/Users/sergis/vscode/teacher/_posts
total 192
-rw-r--r--  1 sergis  staff   7685 Aug 17 21:21 2023-08-16-Tools_Equipment.md
-rw-r--r--  1 sergis  staff   4650 Aug 17 21:21 2023-08-16-pair_programming.md
-rw-r--r--  1 sergis  staff   7139 Aug 30 19:03 2023-08-17-markdown-html_fragments.md
-rw-r--r--  1 sergis  staff   4687 Aug 30 19:03 2023-08-21-python_flask.md
-rw-r--r--  1 sergis  staff   6670 Aug 30 19:03 2023-08-23-javascript-calculator.md
-rw-r--r--  1 sergis  staff  10659 Aug 30 19:03 2023-08-30-agile_methodolgy.md
-rw-r--r--  1 sergis  staff   3850 Aug 30 19:03 2023-08-30-javascript-music-api.md
-rw-r--r--  1 sergis  staff   5312 Aug 30 19:03 2023-09-06-javascript-motion-mario-oop.md
-rw-r--r--  1 sergis  staff   4812 Aug 17 21:21 2023-09-13-java-free_response.md
-rw-r--r--  1 sergis  staff  13219 Aug 30 19:03 2023-10-16-java-api-pojo-jpa.md
-rw-r--r--  1 sergis  staff   6819 Aug 17 21:21 2023-11-13-jwt-java-spring.md
%%script bash

# Extract saved variables
source /tmp/variables.sh

echo "Look for notebooks"
export notebooks=$project/_notebooks  # _notebooks is inside project
cd $notebooks   # this should exist per fastpages
pwd  # present working directory
ls -l  # list notebooks
Look for notebooks
/Users/sergis/vscode/teacher/_notebooks
total 0
drwxr-xr-x  3 sergis  staff  96 Sep  4 10:02 ~
%%script bash

# Extract saved variables
source /tmp/variables.sh

echo "Look for images in notebooks, print working directory, list files"
cd $notebooks/images  # this should exist per fastpages
pwd
ls -l
Look for images in notebooks, print working directory, list files


bash: line 6: cd: /images: No such file or directory


/Users/sergis/newrep1207sergi/_notebooks
total 128
-rw-r--r--@ 1 sergis  staff  32323 Aug 29 15:00 2023-08-16-linux_shell.ipynb
-rw-r--r--@ 1 sergis  staff   5506 Aug 29 14:56 2023-08-17-Markdown_Table_Code_Hack.ipynb
-rw-r--r--@ 1 sergis  staff   8948 Aug 29 14:56 2023-08-21-HTML_Image_Hack.ipynb
-rw-r--r--@ 1 sergis  staff  10579 Sep 11 15:30 2023-09-08-linux-bash.ipynb
%%script bash

# Extract saved variables
source /tmp/variables.sh

echo "Navigate to project, then navigate to area wwhere files were cloned"

cd $project
echo "show the contents of README.md"
echo ""

cat README.md  # show contents of file, in this case markdown
echo ""
echo "end of README.md"

Navigate to project, then navigate to area wwhere files were cloned
show the contents of README.md

## Teacher Blog site
This site is intended for the development of Teacher content.  This blogging site is built using GitHub Pages [GitHub Pages](https://docs.github.com/en/pages/getting-started-with-github-pages/creating-a-github-pages-site).
- The purpose is to build lessons and distribute across different Computer Science sections (CSSE, CSP, CSA), a pathway that covers 3 years of High School Instruction.
- The primary languages and frameworks that are taught are `JavaScript/HTML/CSS`, `Python/Flask`, `Java/Spring`.  Read below for more details.
- In this course, Teacher content is not exclusively developed by Teachers.  In fact, many Students have been invited to develop and publish content into this repository.  Their names will appear as authors on the content which they aided in producing.
- This site has incorporated ideas and has radically modified scripts from the now deprecated [fastpages](https://github.com/fastai/fastpages) repository.
- This site includes assistance and guideance from ChatGPT, [chat.openai.com](https://chat.openai.com/) 

### Courses and Pathway
The focus of the Del Norte Computer Science three-year pathway is `Full Stack Web Development`.  This focus provides a variety of technologies and exposures.  The intention of the pathway is breadth and exposure.
- `JavaScript` documents are focused on frontend development and for entry class into the Del Norte Computer Science pathway.  JavaScript documents and materials are a prerequisites to Python and Java classes.
- `Python` documents are focused on backend development and requirements for the AP Computer Science Principles exam.
- `Java` documents are focused on backend development and requirements for the AP Computer Sciene A exam.
- `Data Structures` materials embedded into JavaScript, Python, or Java documents are focused on college course articulation.

### Resources and Instruction
The materials, such as this README, as well as `Tools`, `DevOps`, and `Collaboration` resources are integral part of this course and Computer Science in general.  Everything in our environment is part of our learning of Computer Science. 
- `Visual Studio Code` is key the code-build-debug cycle editor used in this course, [VSCode download](https://code.visualstudio.com/).  This is an example of a resource, but inside of it it has features for collaboration.
- `Tech Talks`, aka lectures, are intended to be interactive and utilize `Jupyter Notebooks` and Websites.  This is an example of blending instruction and tools together, which in turn provide additional resources for learning.  For instance, deep knowledge on  GitHub Pages and Notebooks are valuable in understanding principles behind Full Stack Development and Data Science. 

## GitHub Pages
All `GitHub Pages` websites are managed on GitHub infrastructure. GitHub uses `Jekyll` to tranform your content into static websites and blogs. Each time we change files in GitHub it initiates a GitHub Action that rebuilds and publishes the site with Jekyll.  
- GitHub Pages is powered by: [Jekyll](https://jekyllrb.com/).
- Publised teacher website: [nighthawkcoders.github.io/teacher](https://nighthawkcoders.github.io/teacher/)

## Preparing a Preview Site 
In all development, it is recommended to test your code before deployment.  The GitHub Pages development process is optimized by testing your development on your local machine, prior to files on GitHub

Development Cycle. For GitHub pages, the tooling described below will create a development cycle  `make-code-save-preview`.  In the development cycle, it is a requirement to preview work locally, prior to doing a VSCode `commit` to git.

Deployment Cycle.  In the deplopyment cycle, `sync-github-action-review`, it is a requirement to complete the development cycle prior to doing a VSCode `sync`.  The sync triggers github repository update.  The action starts the jekyll build to publish the website.  Any step can have errors and will require you to do a review.

### WSL and/or Ubuntu installation requirements
- The result of these step is Ubuntu tools to run preview server.  These procedures were created using [jekyllrb.com](https://jekyllrb.com/docs/installation/ubuntu/)
```bash
# 
# WSL/Ubuntu setup
#
mkdir mkdir vscode
git clone https://github.com/nighthawkcoders/teacher.git
# run script, path vscode/teacher are baked in script
~/vscode/teacher/scripts/activate_ubuntu.sh
#=== !!!Start a new Terminal!!! ===
#=== Continue to next section ===
```

### MacOs installation requirements 
- Ihe result of these step are MacOS tools to run preview server.  These procedures were created using [jekyllrb.com](https://jekyllrb.com/docs/installation/macos/). 

```bash
# 
# MacOS setup
#
mkdir mkdir vscode
git clone https://github.com/nighthawkcoders/teacher.git
# run script, path vscode/teacher are baked in script
~/vscode/teacher/scripts/activate_macos.sh
#=== !!!Start a new Terminal!!! ===
#=== Continue to next section ===
```


### Run Preview Server
- The result of these step is server running on: http://0.0.0.0:4100/teacher/.  Regeneration messages will run in terminal on any save and update site upon refresh.  Terminal is active, press the Enter or Return key in the terminal at any time to see prompt to enter commands.

- Complete installation
```bash
cd ~/vscode/teacher
bundle install
make
```
- Run Server.  This requires running terminal commands `make`, `make stop`, `make clean`, or `make convert` to manage the running server.  Logging of details will appear in terminal.   A `Makefile` has been created in project to support commands and start processes.

    - Start preview server in terminal
    ```bash
    cd ~/vscode/teacher  # my project location, adapt as necessary
    make
    ```

    - Terminal output of shows server address. Cmd or Ctl click http location to open preview server in browser. Example Server address message... 
    ```
    Server address: http://0.0.0.0:4100/teacher/
    ```

    - Save on ipynb or md activiates "regeneration". Refresh browser to see updates. Example terminal message...
    ```
    Regenerating: 1 file(s) changed at 2023-07-31 06:54:32
        _notebooks/2024-01-04-cockpit-setup.ipynb
    ```

    - Terminal message are generated from background processes.  Click return or enter to obtain prompt and use terminal as needed for other tasks.  Alway return to root of project `cd ~/vscode/teacher` for all "make" actions. 
        

    - Stop preview server, but leave constructed files in project for your review.
    ```bash
    make stop
    ```

    - Stop server and "clean" constructed files, best choice when renaming files to eliminate potential duplicates in constructed files.
    ```bash
    make clean
    ```

    - Test notebook conversions, best choice to see if IPYNB conversion is acting up.
    ```bash
    make convert
    ```
    
end of README.md
%%script bash

# This command has no dependencies

echo "Show the shell environment variables, key on left of equal value on right"
echo ""

env
Show the shell environment variables, key on left of equal value on right

MANPATH=/opt/homebrew/share/man::
VSCODE_CRASH_REPORTER_PROCESS_TYPE=extensionHost
GEM_HOME=/Users/sergis/gems
TERM=xterm-color
SHELL=/bin/zsh
CLICOLOR=1
TMPDIR=/var/folders/xp/txhvx_t12sb_pwbx7syqrrf80000gn/T/
HOMEBREW_REPOSITORY=/opt/homebrew
CONDA_SHLVL=1
PYTHONUNBUFFERED=1
CONDA_PROMPT_MODIFIER=(base) 
ORIGINAL_XDG_CURRENT_DESKTOP=undefined
MallocNanoZone=0
PYDEVD_USE_FRAME_EVAL=NO
PYTHONIOENCODING=utf-8
USER=sergis
COMMAND_MODE=unix2003
CONDA_EXE=/Applications/anaconda3/bin/conda
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.lxbjHNhZGV/Listeners
__CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0
PAGER=cat
ELECTRON_RUN_AS_NODE=1
VSCODE_AMD_ENTRYPOINT=vs/workbench/api/node/extensionHostProcess
PATH=/opt/homebrew/bin:/Users/sergis/Library/Python/3.11/bin:/Users/sergis/.rbenv/shims:/Users/sergis/.rbenv/shims:/Applications/anaconda3/bin:/Applications/anaconda3/condabin:/Users/sergis/.rbenv/shims:/Users/sergis/gems/bin:/Users/sergis/gems/bin:/Users/sergis/gems/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Library/Frameworks/Python.framework/Versions/3.11/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/sergis/.rbenv/shims:/Users/sergis/.rbenv/shims:/Applications/anaconda3/bin:/Applications/anaconda3/condabin:/Users/sergis/.rbenv/shims:/Users/sergis/gems/bin:/Users/sergis/gems/bin:/Users/sergis/gems/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Library/Frameworks/Python.framework/Versions/3.11/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin
__CFBundleIdentifier=com.microsoft.VSCode
CONDA_PREFIX=/Applications/anaconda3
PWD=/Users/sergis/newrep1207sergi/_notebooks
VSCODE_HANDLES_UNCAUGHT_ERRORS=true
MPLBACKEND=module://matplotlib_inline.backend_inline
XPC_FLAGS=0x0
FORCE_COLOR=1
RBENV_SHELL=zsh
XPC_SERVICE_NAME=0
SHLVL=1
HOME=/Users/sergis
APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL=1
VSCODE_NLS_CONFIG={"locale":"en-us","osLocale":"en-us","availableLanguages":{},"_languagePackSupport":true}
PYDEVD_IPYTHON_COMPATIBLE_DEBUGGING=1
HOMEBREW_PREFIX=/opt/homebrew
LOGNAME=sergis
CONDA_PYTHON_EXE=/Applications/anaconda3/bin/python
LC_CTYPE=UTF-8
VSCODE_IPC_HOOK=/Users/sergis/Library/Application Support/Code/1.81-main.sock
VSCODE_CODE_CACHE_PATH=/Users/sergis/Library/Application Support/Code/CachedData/6c3e3dba23e8fadc360aed75ce363ba185c49794
CLICOLOR_FORCE=1
CONDA_DEFAULT_ENV=base
VSCODE_PID=54444
INFOPATH=/opt/homebrew/share/info:
HOMEBREW_CELLAR=/opt/homebrew/Cellar
GIT_PAGER=cat
VSCODE_L10N_BUNDLE_LOCATION=
VSCODE_CWD=/
_=/usr/bin/env
%%script bash

# This example has error in VSCode, it run best on Jupyter
cd /tmp

file="sample.md"
if [ -f "$file" ]; then
    rm $file
fi

tee -a $file >/dev/null <<EOF
# Show Generated Markdown
This introductory paragraph and this line and the title above are generated using tee with the standard input (<<) redirection operator.
- This bulleted element is still part of the tee body.
EOF

echo "- This bulleted element and lines below are generated using echo with standard output (>>) redirection operator." >> $file
echo "- The list definition, as is, is using space to seperate lines.  Thus the use of commas and hyphens in output." >> $file
actions=("ls,list-directory" "cd,change-directory" "pwd,present-working-directory" "if-then-fi,test-condition" "env,bash-environment-variables" "cat,view-file-contents" "tee,write-to-output" "echo,display-content-of-string" "echo_text_>\$file,write-content-to-file" "echo_text_>>\$file,append-content-to-file")
for action in ${actions[@]}; do  # for loop is very similar to other language, though [@], semi-colon, do are new
  action=${action//-/ }  # convert dash to space
  action=${action//,/: } # convert comma to colon
  action=${action//_text_/ \"sample text\" } # convert _text_ to sample text, note escape character \ to avoid "" having meaning
  echo "    - ${action//-/ }" >> $file  # echo is redirected to file with >>
done

echo ""
echo "File listing and status"
ls -l $file # list file
wc $file   # show words
mdless $file  # this requires installation, but renders markown from terminal

rm $file  # clean up termporary file
File listing and status
-rw-r--r--@ 1 sergis  wheel  809 Sep 12 21:11 sample.md
      15     132     809 sample.md


bash: line 30: mdless: command not found



---------------------------------------------------------------------------

TokenError                                Traceback (most recent call last)

Cell In[3], line 1
----> 1 get_ipython().run_cell_magic('script', 'bash', '\n# This example has error in VSCode, it run best on Jupyter\ncd /tmp\n\nfile="sample.md"\nif [ -f "$file" ]; then\n    rm $file\nfi\n\ntee -a $file >/dev/null <<EOF\n# Show Generated Markdown\nThis introductory paragraph and this line and the title above are generated using tee with the standard input (<<) redirection operator.\n- This bulleted element is still part of the tee body.\nEOF\n\necho "- This bulleted element and lines below are generated using echo with standard output (>>) redirection operator." >> $file\necho "- The list definition, as is, is using space to seperate lines.  Thus the use of commas and hyphens in output." >> $file\nactions=("ls,list-directory" "cd,change-directory" "pwd,present-working-directory" "if-then-fi,test-condition" "env,bash-environment-variables" "cat,view-file-contents" "tee,write-to-output" "echo,display-content-of-string" "echo_text_>\\$file,write-content-to-file" "echo_text_>>\\$file,append-content-to-file")\nfor action in ${actions[@]}; do  # for loop is very similar to other language, though [@], semi-colon, do are new\n  action=${action//-/ }  # convert dash to space\n  action=${action//,/: } # convert comma to colon\n  action=${action//_text_/ \\"sample text\\" } # convert _text_ to sample text, note escape character \\ to avoid "" having meaning\n  echo "    - ${action//-/ }" >> $file  # echo is redirected to file with >>\ndone\n\necho ""\necho "File listing and status"\nls -l $file # list file\nwc $file   # show words\nmdless $file  # this requires installation, but renders markown from terminal\n\nrm $file  # clean up termporary file\n')


File ~/Library/Python/3.11/lib/python/site-packages/IPython/core/interactiveshell.py:2484, in InteractiveShell.run_cell_magic(self, magic_name, line, cell)
   2480 # The code below prevents the output from being displayed
   2481 # when using magics with decodator @output_can_be_silenced
   2482 # when the last Python token in the expression is a ';'.
   2483 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, True):
-> 2484     if DisplayHook.semicolon_at_end_of_expression(cell):
   2485         return None
   2487 return result


File ~/Library/Python/3.11/lib/python/site-packages/IPython/core/displayhook.py:101, in DisplayHook.semicolon_at_end_of_expression(expression)
     98 """Parse Python expression and detects whether last token is ';'"""
    100 sio = _io.StringIO(expression)
--> 101 tokens = list(tokenize.generate_tokens(sio.readline))
    103 for token in reversed(tokens):
    104     if token[0] in (tokenize.ENDMARKER, tokenize.NL, tokenize.NEWLINE, tokenize.COMMENT):


File /opt/homebrew/Cellar/python@3.11/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/tokenize.py:525, in _tokenize(readline, encoding)
    523 else:                                  # continued statement
    524     if not line:
--> 525         raise TokenError("EOF in multi-line statement", (lnum, 0))
    526     continued = 0
    528 while pos < max:


TokenError: ('EOF in multi-line statement', (33, 0))