Ciro Santilli OurBigBook.com $£ Sponsor €¥ 中国独裁统治 China Dictatorship 新疆改造中心、六四事件、法轮功、郝海东、709大抓捕、2015巴拿马文件 邓家贵、低端人口、西藏骚乱
Cheatsheet on HTML, Cascading Style Sheets and JavaScript.
Old cheat on separate repo: web.
Now moving to either:
  • separate files under: web-cheat/ for the boring stuff
  • subsections under this section for the more exciting stuff!
Examples under:

World Wide Web

words: 10 articles: 2
Video 1. Why web tech is like this by Steve Sanderson (2022) Source.

Webdev's Creed

words: 314
This is my stack. There are many like it, but this one is mine.
My stack is my best friend. It is my life. I must master it as I must master my life.
Without me, my stack is useless. Without my stack, I am useless. I must fire my requests true. I must shoot straighter than my hackers who are trying to kill me. I must shoot him before he shoots me. I will ...
My stack is human, even as I am human, because it is my life. Thus, I will learn it as a brother. I will learn its weaknesses, its strength, its parts, its accessories, its ORMs and its asset bundlers. I will keep my stack clean and ready, even as I am clean and ready. We will become part of each other. We will ...
Before God, I swear this creed. My stack and I are the defenders of my website. We are the masters of our enemy. We are the saviors of my life.
So be it, until victory is mine and there is no enemy, but peace!
Explanation: this is an allusion to the Rifleman's Creed. This particular version talks about the website stack chosen for a website, i.e. the libraries used.
Ciro Santilli has always felt that choosing a stack is an almost religious choice. It is perhaps part of why the prayer style of the original Rifleman's Creed resonates with the web stack choice.
It is very hard to know how things are going go, the ups and downs, before putting big hours into it.
And once you start, it is hard, though not impossible, to move away.
The same allusion would make sense with any complex library choice, but it is particularly apparent in web development since there are so many different web stacks to choose from. A bit like rifles, they are all somewhat fungible, though of course not as much.

HTML

words: 57 articles: 7
Examples:

HTML element

words: 24 articles: 6

HTML canvas

words: 24 articles: 2
developer.mozilla.org/en-US/docs/Web/API/Canvas_API
Allows us to draw with JavaScript pixel by pixel! Great way to create computational physics demos!
Here is an animation demo with some useful controls:
new class extends OurbigbookCanvasDemo {
  init() {
    super.init('hello');
    this.pixel_size_input = this.addInputAfterEnable(
      'Pixel size',
      {
        'min': 1,
        'type': 'number',
        'value': 1,
      }
    );
  }
  draw() {
    var pixel_size = parseInt(this.pixel_size_input.value);
    for (var x = 0; x < this.width; x += pixel_size) {
      for (var y = 0; y < this.height; y += pixel_size) {
        var b = ((1.0 + Math.sin(this.time * Math.PI / 16)) / 2.0);
        this.ctx.fillStyle =
          'rgba(' +
          (x / this.width) * 255 + ',' +
          (y / this.height) * 255 + ',' +
          b * 255 +
          ',255)'
        ;
        this.ctx.fillRect(x, y, pixel_size, pixel_size);
      }
    }
  }
}
Bibliography: developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_animations">https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_animations
WebGL
articles: 1
developer.mozilla.org/en-US/docs/Web/API/WebGL_API/By_example
new class extends OurbigbookCanvasDemo {
  init() {
    super.init('webgl', {context_type: 'webgl'});
    this.ctx.viewport(0, 0, this.ctx.drawingBufferWidth, this.ctx.drawingBufferHeight);
    this.ctx.clearColor(0.0, 0.0, 0.0, 1.0);
    this.vertexShaderSource = `
#version 100
precision highp float;
attribute float position;
void main() {
  gl_Position = vec4(position, 0.0, 0.0, 1.0);
  gl_PointSize = 64.0;
}
`;

    this.fragmentShaderSource = `
#version 100
precision mediump float;
void main() {
  gl_FragColor = vec4(0.18, 0.0, 0.34, 1.0);
}
`;
    this.vertexShader = this.ctx.createShader(this.ctx.VERTEX_SHADER);
    this.ctx.shaderSource(this.vertexShader, this.vertexShaderSource);
    this.ctx.compileShader(this.vertexShader);
    this.fragmentShader = this.ctx.createShader(this.ctx.FRAGMENT_SHADER);
    this.ctx.shaderSource(this.fragmentShader, this.fragmentShaderSource);
    this.ctx.compileShader(this.fragmentShader);
    this.program = this.ctx.createProgram();
    this.ctx.attachShader(this.program, this.vertexShader);
    this.ctx.attachShader(this.program, this.fragmentShader);
    this.ctx.linkProgram(this.program);
    this.ctx.detachShader(this.program, this.vertexShader);
    this.ctx.detachShader(this.program, this.fragmentShader);
    this.ctx.deleteShader(this.vertexShader);
    this.ctx.deleteShader(this.fragmentShader);
    if (!this.ctx.getProgramParameter(this.program, this.ctx.LINK_STATUS)) {
      console.log('error ' + this.ctx.getProgramInfoLog(this.program));
      return;
    }
    this.ctx.enableVertexAttribArray(0);
    var buffer = this.ctx.createBuffer();
    this.ctx.bindBuffer(this.ctx.ARRAY_BUFFER, buffer);
    this.ctx.vertexAttribPointer(0, 1, this.ctx.FLOAT, false, 0, 0);
    this.ctx.useProgram(this.program);
  }
  draw() {
    this.ctx.clear(this.ctx.COLOR_BUFFER_BIT);
    this.ctx.bufferData(this.ctx.ARRAY_BUFFER, new Float32Array([Math.sin(this.time / 60.0)]), this.ctx.STATIC_DRAW);
    this.ctx.drawArrays(this.ctx.POINTS, 0, 1);
  }
}

HTML details tag

articles: 2
html/details-toc.html
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>HTML details tag</title>
<style>
details { margin-left: 20px; }
div { margin-left: 30px; }
</style>
</head>
<body>
<h1>HTML details tag</h1>
<p><a href="https://cirosantilli.com/html-details-tag">https://cirosantilli.com/html-details-tag</a></p>
<details open="true"><summary>1.</summary>
  <details open="true"><summary>1.1</summary>
    <details open="true"><summary>1.1.1</summary>
      <div>1.1.1.1</div>
      <div>1.1.1.2</div>
    </details>
    <details open="true"><summary>1.1.2</summary>
      <div>1.1.2.1</div>
      <div>1.1.2.2</div>
    </details>
  </details>
  <details open="true"><summary>1.2</summary>
    <details open="true"><summary>1.2.1</summary>
      <div>1.2.1.1</div>
      <div>1.2.1.2</div>
    </details>
    <details open="true"><summary>1.2.2</summary>
      <div>1.2.2.1</div>
      <div>1.2.2.2</div>
    </details>
  </details>
</details>
</body>
</html>

Cascading Style Sheets (CSS)

words: 209 articles: 2

CSS flex

words: 118
Other examples include:
That example calculates and displays the final widths via JavaScript, making it easier to understand the calculations being done.
Answers: stackoverflow.com/questions/28473807/how-does-flex-grow0-get-interpreted/69995712#69995712
Bibliography:
The more of their syntax gets merged into mainline Cascading Style Sheets, the better the world will be.
External libraries

Asset bundler

words: 393 articles: 6
In order to make websites efficient and portable, a lot of transpilation is needed.

webpack

articles: 5
This section is present in another page, follow this link to view it.

Web browser

words: 88 articles: 5

Chromium (Web browser)

words: 33 articles: 1
Google is trying to kill it as of 2021: www.omgubuntu.co.uk/2021/01/chromium-sync-google-api-removed The lack of sync is a major major blow. So selfish. Google makes billions, and it won't give in a little bit of settings storage...
stackoverflow.com/questions/13405383/how-to-disable-javascript-in-chrome-developer-tools

Google Chrome

words: 55 articles: 1
Lol it is note possible what a joke. Notably this makes it harder to have of a superior third party password manager like Proton Pass (though there seems to be an autocomplete app as an alternative path), and an ad blocker. Fuck Google.
Also, Chromium is not available on Google Play by default, you can install the apk, but you will miss updates:

Web framework

words: 2k articles: 19
Per programming language:
How to select one:

Hello world website

words: 503 articles: 4

A blog in every web framework

words: 491 articles: 2
A (multi-user) blog is the hello world of the web, so creating one of those is the best way to quickly evaluate web technology, i.e. time to Hello World.
Some new frameworks like FeathersJS are making a chat app instead, as that highlights the push notifications a bit better.
gothinkster/realworld
words: 449 articles: 1
github.com/gothinkster/realworld
Ciro Santilli's implementation: node Express Sequelize Next.js realworld example app.
Ahh, you can't have new ideas anymore!
Basically puts together every backend with Front-end web framework to create the exact same website.
The reference live demo can be found at: demo.realworld.io/#/ It is based on Angular.js as it links to: github.com/gothinkster/angularjs-realworld-example-app TODO backend?
There are however also live demos of other frontends, e.g.:
Note that all those frontends communicate with the same backend.
As of 2021 Devs are seemed a bit too focused on monetizing the project through their "how to use this project" premium tutorial, and documentation could be better: just getting the hello world of the most popular backend with the most popular frontend is not easy... come on.
github.com/gothinkster/realworld/issues/578 asks for community support, as devs have moved on since unfortunately.
Remember:
  • by default, the frontends hardcode the upstream public data API: https://conduit.productionready.io/api so you have to hack their code to match the port of the backend. And each backend can have a different port.
  • when you switch between backends, you must first manually clear client-side storage cookies/local new run will fail due to authentication issues!
Important missing things from the minimum base app:
First you should the most popular backend/frontend combination running, which is the most likely to be working. We managed to run on Ubuntu 20.10, React + Node.js Express.js as described at github.com/gothinkster/node-express-realworld-example-app/pull/116:
Then just:
npm install
npm start
on both server and client, and then visit the client URL: localhost:4100/
You have to hit the Enter key to add tags, it's terrible: github.com/gothinkster/react-redux-realworld-example-app/issues/151#issuecomment-808417846
One cool thing is that the main repo has unified backend API tests:
git clone https://github.com/gothinkster/realworld
cd realworld
git checkout e7adc6b06b459e578d7d4a6738c1c050598ba431
cd api
APIURL=http://localhost:3000/api USERNAME="u$(date +%s)" ./run-api-tests.sh
so the per-repository tests are basically useless, and that single test can test everything for any backend! There is no frontend testing however: github.com/gothinkster/realworld/issues/269 so newb.
Setups we've tried:

TodoMVC

words: 12
todomvc.com/
Front-end only, so infinitely simpler, and generally much less useful than gothinkster/realworld.

Front-end web framework

words: 1k articles: 13
You need those because it is hard to do the following:
  • client JavaScript sends a request to server
  • server sends back data
  • client updates what the user sees
This is hard to do notably because when the update happens, several things might need to change on the webpage at the same time.
Notably, new elements might need to be added to the webpage, which in turn means that new bindings such as button clicks have to be added to those, in a way that keeps the page working.
The only way to do this basically is to have a functional dependency graph that keeps everything in the page in working state as updates come.

List of front-end web frameworks

words: 1k articles: 9
React.js
React
words: 2 articles: 5
This section is present in another page, follow this link to view it.
Vue.js
articles: 1

Tagged

Ancestors

  1. Software
  2. Computer
  3. Information technology
  4. Area of technology
  5. Technology
  6. Ciro Santilli's Homepage

Synonyms