Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Meta

Before you read all these notes, these might help:

  1. I can read English well but I am not good at writing English.
  2. I don't check my grammar when writing because it will distract me.
  3. I mainly write about CS, programming language, and mathematics but I only have degree in mathematics (undergraduate).
  4. Everything can change drastically. In any case you might want to refer to the commit history.

I should make some rules and style guides to follow when writing this. These will change as I write more and find suitable style for me:

  1. Always write the date before an important update or paragraph.
  2. Use do: x as todo.
  3. Use read: y as to be read.

TODO

  • Move vimping here.
  • Move blog posts from jonesangga.codeberg.page to here.
  • Add TIL page.
  • Add review pages for books (and maybe anime, manga, music).

C

  • Don't do x = b[i] + i++.
  • Don't do push(pop() - pop()).

These are from Misra-C.

  • Use maximum 31 characters for identifier.
  • No inner scope identifier have the same name as outer scope.
  • If an object only used in one function, define it there. Don't make it global.
  • Only declare extern in one header file and include this header file.
  • Define an external object only in its implementation file and link to this unit.
  • Always use static for non external global object.
  • Don't use nested assignment.
  • Don't use comma operator.
  • Don't use bitwise operators on signed types.
  • Don't use assigment inside if conditional.
  • Don't test floating point expression for equality or inequality.
  • Don't modify the iterator inside loop body.
  • Don't create function with variable length argument.
  • If an object pointed by pointer parameter will not modified, use const.
  • In function-like macro, all parameters must be used with parentheses. Unless it is operand for # or ##.

Haskell

Started following this tutorial. Somehow I cannot run

ghc hello.hs

I need to use

stack exec -- ghc hello.hs
  • Learn Haskell by building a blog generator [mdbook] [repo]

J

03-04-25

Trying J again. Reading book J for C Programmers by Henry Rich, 2007. This book already in my J folder. I don't remember where I got it. Maybe from J wiki.

After reading some chapters, this book remind me that what makes you don't like something is because you learn it from wrong resource. So I dropped this book.

Javascript

Book

  1. Javascript The Definitive Guide 7th Edition. David Flanagan.
  2. Eloquent Javascript 4th Edition. Marijn Haverbeke.
  3. Build Your Own Test Framework. Daniel Irvine.

Post

  1. Douglas Crockford - Pratt parser
  2. Testing JavaScript without a (third-party) framework
  3. 7 Stages of a “Clean” WebApp

Programming Language Theory

Lua

Prolog

IO

write/1.
write(real).
write('real').
write(2).
write([1,2,'a']).

`nl/0`.

read/1.
read(X).
|: real.
X = real.

put/1
put(97).
a

get0/1
get0(N).
|: a
N = 97

get/1
same as get but ignoring left white space chars

Resources

Reading List

Holding a program in one's head

"The reason to finish is to start something new."

Here is the format

#### dd-mm-yy

[Status (, Status date)*]  <br>
Title/link. Short description.

Status is one of these:
    Plan    to be read
    Cancel  remove from to be read, give your reason
    Start   started reading
    Pause   stop for now, will continue later
    Drop    not continuing again, give your reason
    Done    finished
    Review  wrote a review
    Impl    built a project from the book

05-04-25

[Plan]
Creating the Bolt Compiler. 11 parts tutorial with OCaml and LLVM.

04-04-25

[Start]
OCaml From the Very Beginning. John Whitington.

[Plan]
Mathematical Logic Through Python. 2022. https://www.logicthrupython.org/

03-04-25

[Start]
C Traps and Pitfalls.

[Plan]
5000 Years of Geometry. Christoph J. Scriba, Peter Schreiber. Birkhauser.

01-04-25

[Start, Done 03]
Misra-C:2024. I have been looking for this. Got from X comment section. This looks easier to read than SEI CERT.

Rust

Testing

The general guideline for integration testing is to cover the longest happy path and any edge cases that can't be exercised by unit tests.


From The Art of Unit Testing book.

Criteria of good test:

  1. Readable
  2. Maintainable
  3. Trustworthy

Technically, one the biggest benefits of TDD is that by seeing a test fail, and then seeing it pass without changing the test, you are basically testing the test itself.

Format:

describe("unit name under test", () => {
    it("expectation, scenario", () => {
        // Arrange.

        // Act.

        // Assert.
    });
})

Use parameterized test or test.each() (p.54).

describe('one uppercase rule, with vanilla JS for', () => {
    const tests = {
        'Abc': true,
        'aBc': true,
        'abc': false,
    };
    for (const [input, expected] of Object.entries(tests)) {
        test('given ${input}, ${expected}', () => {
            const result = oneUpperCaseRule(input);
            expect(result.passed).toEqual(expected);
        });
    }
});
  • Don't use beforeEach and afterEach. Reason: scroll fatigue (p.47).

  • Avoid magic values.

  • Avoid logic in unit test.

  • Avoid dynamically creating the expected value in your asserts; use hardcoded values when possible.

  • Separate asserts from actions. Below is bad.

    expect(verifier.verify("any value")[0]).toContain("fake reason");
    
  • Don't test multiple exit points (p.158). If you’re testing more than one thing, giving the test a good name that indicates what’s being tested is difficult

  • Sometimes it’s perfectly okay to assert multiple things in the same test, as long as they are not multiple concerns.

  • BAD: Looping inside test().

  • GOOD: Looping the test().

Resources

Book

  1. The Art of Unit Testing. Third Edition. Roy Osherove.
  2. Unit Testing Principles, Practices, and Patterns. Vladimir Khorikov.
  3. Build Your Own Test Framework. Daniel Irvine.
  1. Node test runner doc
  2. Node assert doc
  3. Node.js native test runner is great
  4. Migrating 500+ tests from Mocha to Node.js
  5. Complete Guide to the Node.js Test Runner
  6. Unit testing best practices for .NET

Typescript

  1. Implementing the Rust Result type in TypeScript
  2. Creating a Result Type in TypeScript
  3. Using Results in TypeScript
  4. An introduction to type programming in TypeScript
  5. Proof that TypeScript's Type System is Turing Complete

Build Something

  1. Fizz Buzz
  2. Implementing Arithmetic Within TypeScript’s Type System

To Read

  1. TypeScript and Turing Completeness Implementing Smallfuck interpreter.
  2. Simulating a Tic Tac Toe game

Misc

  • any vs unknown: where we are allowed to do everything with any, we aren’t allowed to do any thing with unknown.

  • Passing an object with too many properties directly to a function will trigger excess property checks

  • Use tsc --noEmit --watch.

VIM

Colorschemes

  • nofrils activate: :colo nofrils-acme or :colo nofrils-light.

  • envy make sure set termguicolors. activate: :colo envy.

VIM Cheat Sheet

CommandMeaning
:stsuspend
mxmark current position with x
'xgo to line marked by x
*search word below cursor
''return to previous mark or context
delete to start word, also works on ex command and terminal
delete to the start line, also works on ex command and terminal

Visual Mode

CommandMeaning
gvresellect last visual selection
otoggle end

VIM Help

CommandMeaning
CTRL-]jump to tag
CTRL-Tto go back

NETRW

CommandMeaning
Ddelete file or (empty?) dir
Rrename file

Useful Tricks

  • Always do 0 before moving up or down.

Geometry

Demo

TIL

Below are short and trivial things that I just learned. For a slighly longer see sub chapters.

  • Ctrl-y to select first option of vim completion.

  • Skipping test with describe.skip() and it.skip() in node test.

  • Local server

    • npx http-server /path/to/project -o -p 9999.
    • python -m http.server.
  • There is Number.EPSILON in javascript which equals 2.220446049250313e-16. It should not be used for checking equality with error like abs(a-b) < Number.EPSILON.

  • g<Tab> go to the last accessed tab in vim.

  • Setting position: absolute to html tag will make pre element selected when clicking empty region.

Get and Change Default Browser

02-04-25

When I run mdbook serve --open it always open in brave browser. I want to change to firefox. I found this tutorial.

Get the default browser.

$ xdg-settings get default-web-browser
brave-browser.desktop

Change to firefox.

$ xdg-settings set default-web-browser firefox.desktop

Posts

This is a collection of blog post I write.

Deploy this mdBook using github action

01-04-25

I want to push the source code not the built page. I follow this guide on section "Using deploy via actions".

At the first time it didn't work until I figured out that I don't use main branch. So I just need to change to master.

name: Deploy
on:
  push:
    branches:
      - master

jobs:
  deploy:
    runs-on: ubuntu-latest
    permissions:
      contents: write  # To push a branch
      pages: write  # To push to a GitHub Pages site
      id-token: write # To update the deployment status
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Install latest mdbook
        run: |
          tag=$(curl 'https://api.github.com/repos/rust-lang/mdbook/releases/latest' | jq -r '.tag_name')
          url="https://github.com/rust-lang/mdbook/releases/download/${tag}/mdbook-${tag}-x86_64-unknown-linux-gnu.tar.gz"
          mkdir mdbook
          curl -sSL $url | tar -xz --directory=./mdbook
          echo `pwd`/mdbook >> $GITHUB_PATH
      - name: Build Book
        run: |
          # This assumes your book is in the root of your repository.
          # Just add a `cd` here if you need to change to another directory.
          mdbook build
      - name: Setup Pages
        uses: actions/configure-pages@v4
      - name: Upload artifact
        uses: actions/upload-pages-artifact@v3
        with:
          # Upload entire repository
          path: 'book'
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4

mdBook

01-04-25

My last experience with Jekyll and Hugo are bad. For Jekyll, I have trouble with related ruby gems. For Hugo, it is often fail to live reload the served page.

Then there was time I made my own static site generator using Make and Bash. It doesn't scale because that time I don't know about parsing hence I cannot implement a slightly complex markup template.

Then there was time I manually write html and css. It was a trouble to change a common code like menu items or footnote.

Then I accidently found mdBook from this compiler tutorial. It uses Rust. I already have Rust. I build mdBook. It succeed.

Now by just doing

$ mdbook init my-first-book
$ cd my-first-book
$ mdbook serve --open

I have a page open in browser that automatically refresh with a nice default theme.

But I check Codeberg cannot build these from source like Github. I don't want to put the built html pages. So I think this time I will place the repo in Github.

I won't change anything, just use the default.

Setup Dictionary in Linux

02-04-25

I followed arch linux wiki.

First install dictd.

$ sudo pacman -S dictd

I want to use it offline. Disable online mode by going to /etc/dict/dict.conf and comment line server dict.org.

server localhost
# server dict.org

Then install WordNet and Moby Thesaurus.

$ yay -S dict-wn
$ yay -S dict-moby-thesaurus

Enable and start the service.

$ systemctl enable dictd.service
$ systemctl start dictd.service

Now to list installed dictionaries:

$ dict -I
  dictd 1.13.3/rf on Linux 6.11.9-arch1-1
  On magic: up 93.000, 3 forks (116.1/hour)

  Database      Headwords         Index          Data  Uncompressed
  wn                 147483       3005 kB       9278 kB         29 MB
  moby-thesaurus      30263        528 kB         28 MB         28 MB

To query the dictionary just enter a word:

$ dict word

Old Internet

Other's Braindump

Uncategorized