Monday 15 November 2021

Lab 8 - Jest Enough

Step 1: Choosing Jest

Last week was rough and I had to fix code before doing Lab 8.  Basically, we are implementing Automated Testing to our existing ssg  I chose to use Jest because I am using Node.js as my main language.  I feel like this week I was completely burnt out and needed a few days to rest.

I use npm install to install jest and added the following two lines to package.json


Step 2: First Tests

My first set of tests involve file checking, whether a path is a file, folder and nothing related to the files I needed, which are ".md" and ".txt".

STEP 3: Test the Core of SSG

My next set of tests involve whether I utilized the correct input files.

Running my tests yielded the following results on Jest.


Step 4: Updating Documentation

I updated the CONTRIBUTION.md file

Step 6: Merging to Master

Conclusion

I learnt that writing test for existing code that does not have tests is much harder than writing tests from the start.  I feel like I have to refactor some of my code in order for my tests to run.  I believe the benefit of this open-source class and community is that you can ask questions and help each other out during harder labs and releases.  I have done testing before, but not with Jest, so it was a good experience.

My pull request

Live to code another day...

Wednesday 3 November 2021

[OSD600] Lab 7 - Static Analysis Tooling

Introduction 

From the lab we are working on the following this week,

  • an automatic source code formatter
  • a source code linter
  • command-line or project build scripts to run your static analysis tooling
  • editor/IDE integration of your static analysis tooling
  • write contributor documentation to setup and use your tools
I created a branch called lab7.

Moved related Documentation to CONTRIBUTING.md


As the title suggests, I moved all relevant documentation to CONTRIBUTING.md file.

I added a developer checks section as shown below as well.


Automatic source code Formatter

The obvious choice is Prettier because I am using a node.js project for cmd-ssg

I added using npm install --save-dev --save-exact prettier

# ignore artifacts:
build
dist
added to .prettierignore

Under package.json, I had scripts for prettier such as the following
"prettier-check": "npx prettier --check .",
"prettier": "npx prettier --write .",
You type and execute "npm run prettier-check" in terminal to check format.

Source Code Linter

Eslint seems the sensible choice for my project where you use the commands
$ npm install eslint --save-dev
eslint --init
I edited .eslintrc with
{
  "env": {
    "browser": true,
    "es2021": true
  },
  "extends": "eslint:recommended",
  "parserOptions": {
    "ecmaVersion": 12,
    "sourceType": "module"
  },
  "rules": {
    "indent": ["error", 2],
    "linebreak-style": 0,
    "quotes": ["error", "double"],
    "semi": ["error", "always"]
  }
}

Editor Integration and VS Code Settings

For automatic formatting and linting i added the following to extensions.json
{
  "recommendations": [
    "editorconfig.editorconfig",
    "dbaeumer.vscode-eslint",
    "esbenp.prettier-vscode",
    "streetsidesoftware.code-spell-checker"
  ]
}
Under settings I added the following to settings.json in vs code
...
  "editor.insertSpaces": true,
  "editor.tabSize": 2,
  "editor.detectIndendations": false,
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "files.eol": "\n",
  "files.insertFinalNewline": true
...

Pre-commit Hook

As the lab 7 suggests, I used Husky as my pre-commit hook

Issues

I did not have many major issues, except I had to ignore some of the checks done on the project because I had a helper javascript file that is separate from the index.js, the dependencies on the parent is not on child. I used what I learned in Web222 and integrated prettier and eslint ahead of time so there we not many issues.

My commit is here cc92dc8

Cheers,

Eugene

Friday 29 October 2021

Translated Chinese version of AlphaZero Hacktoberfest

 Introduction

    I grew up playing Chinese chess with my father as well as a physical chess computer program he bought me during the time of Windows 98 came out.  Here is a picture below, a one of a kind physical Chinese chess computer with 32k memory and 16000 moves, with 20 max depth search.  I was only able to beat Master level once at the age of ten, but I am only an intermediate player.


    The lights on the top and bottom will light up indicating where on the board the computer wants to move and you use tactile sensors to press down on the start and end position to finalize a move.  Thus, I was man vs machine ever since a child.  Fast track 16 years, and the team from "openAI" beat the world champion in the game of Go, making history of machine overcoming human intelligence.  During the Hacktoberfest I found no sign of such chess programs, but I did come across the "cchess-zero" repo, which is an attempt to implement alpha zero like chess into Chinese chess.  There have been attempts to remake Alpha zero in the form of Leela chess being the most popular, none made in Chinese chess I have come across.  The problem with this repository is its all written in Chinese and I am very slow at reading Chinese and only understanding partially.  I wanted to incorporate this opportunity with Hacktoberfest and the fact that the repository is under the MIT license, I want to make non-Chinese speaking individuals to access this resource as well and learn from it.  Thus I created an issue for it.

 Translation

    Thus, I took the liberty to translate as much of the two papers and source code to English while maintaining the Chinese text.  I also fixed the broken links as well as the images that are not showing up on Github.  The author mentioned that he doesn't get why the local images are not showing up in markdown, but I know the answer and fixed it.  Since the author has limited knowledge in English as mentioned on his paper, I tried to also translate my pull request as well as what I am trying to do in Chinese as well.  With the help on powerful Chinese to English translators I was able to translate over 600 lines/paragraphs of text in the pull-request.  In the author's original README, he encourages others to share the repository, so it makes sense that being in a popular language such as English will receive more views.

Hacktoberfest

    This issue was self created and not part of Hacktoberfest, so I also did a Hacktoberfest approved translation work on Microsoft's repository at https://github.com/microsoft/Data-Science-For-Beginners with issue and pull request.  This was a quick translation work for a README for Data Science tutorial, so it is what it is.

Thoughts on This Experience

    Overall, the Hacktoberfest is a great way to get real world experience and build confidence in working on other people's code, while respecting the rules and courtesy that you need to show as a representative of Seneca College.  The fact that it is run every year despite the fake pull requests people try to do, means it is valuable to the Open Source communities, to first timers, to veterans, to train future developers.  If I were to do this again,  I would have tried to do more issues in parallel as I have more than two repositories that didn't make it to the four pull requests this month.  The amount you get out of it is how much time and effort you put into it.

Aside

Here is a bonus game between world champion Magnus Calsen (age 8 simulated) and me (NeoLinux) at age 29.


 You can checkout the English Translation version of Chinese Chess Alpha Zero:

https://github.com/ycechungAI/cchess-zero

Thanks for Reading,

Eugene Chung

What I learned from Project 1 of Udacity's Data Science with Python bootcamp

Introduction As part of the project I completed successfully, I used SQL to explore a database related to movie rentals. SQL queries was ran...