Meta
Before you read all these notes, these might help:
- I can read English well but I am not good at writing English.
- I don't check my grammar when writing because it will distract me.
- I mainly write about CS, programming language, and mathematics but I only have degree in mathematics (undergraduate).
- 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:
- Always write the date before an important update or paragraph.
- Use do: x as todo.
- 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
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
- Javascript The Definitive Guide 7th Edition. David Flanagan.
- Eloquent Javascript 4th Edition. Marijn Haverbeke.
- Build Your Own Test Framework. Daniel Irvine.
Post
- Douglas Crockford - Pratt parser
- Testing JavaScript without a (third-party) framework
- 7 Stages of a “Clean” WebApp
Programming Language Theory
- Partial Function Application as a Design Pattern
- Moving Beyond Type Systems
- Algebraic Effects for the Rest of Us
- Why Pipelines are Useful
- Big Resources
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
-
Prolog Programming for Artificial Intelligence. 4 ed. Ivan Bratko.
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:
- Readable
- Maintainable
- 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
- The Art of Unit Testing. Third Edition. Roy Osherove.
- Unit Testing Principles, Practices, and Patterns. Vladimir Khorikov.
- Build Your Own Test Framework. Daniel Irvine.
Link
- Node test runner doc
- Node assert doc
- Node.js native test runner is great
- Migrating 500+ tests from Mocha to Node.js
- Complete Guide to the Node.js Test Runner
- Unit testing best practices for .NET
Typescript
- Implementing the Rust Result type in TypeScript
- Creating a Result Type in TypeScript
- Using Results in TypeScript
- An introduction to type programming in TypeScript
- Proof that TypeScript's Type System is Turing Complete
Build Something
To Read
- TypeScript and Turing Completeness Implementing Smallfuck interpreter.
- Simulating a Tic Tac Toe game
Misc
-
any
vsunknown
: where we are allowed to do everything withany
, we aren’t allowed to do any thing withunknown
. -
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
Command | Meaning |
---|---|
:st | suspend |
mx | mark current position with x |
'x | go 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
Command | Meaning |
---|---|
gv | resellect last visual selection |
o | toggle end |
VIM Help
Command | Meaning |
---|---|
CTRL-] | jump to tag |
CTRL-T | to go back |
NETRW
Command | Meaning |
---|---|
D | delete file or (empty?) dir |
R | rename 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()
andit.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 makepre
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
- beepb00p
- Jethro's Braindump
- Neil's Digital Garden
- Andy's working notes
- Things and Stuff Wiki
- Simon Willison's TILs
- Purarue
- mesyeti
Uncategorized
- palaiologos.rocks
- Brad Woods Digital Garden Notes about web dev. Creative coding.
- cidoku.net
- storytotell.org
- hyperpolyglot.org
- The Quine Page
- I finally understand Declarative Programming