add recent Mac notes

This commit is contained in:
thomasabishop 2023-01-16 14:56:28 +00:00
parent 04a97a8951
commit f73f3ce110
6 changed files with 121 additions and 7 deletions

View file

@ -36,7 +36,7 @@ An example would be `CHAR(10)` or `CHAR(3)`. Here we set the upper limit but it
As above but allowing for variable-length strings.
A common example is `VARCHAR(255)`. The 255 refers to the maximal character length, not the byte length. We must put `255` as the parameter even if our character lengths will be below this but where we don't know the minimum and maximum length.
A common example is `VARCHAR(255)`. The 255 refers to the maximal character length, not the byte length. It is the largest number of characters that can be accommodated by an 8-bit number (byte). We must put `255` as the parameter even if our character lengths will be below this but where we don't know the minimum and maximum length.
## Large object storage

View file

@ -0,0 +1,14 @@
---
categories:
- DevOps
tags: [git]
---
# Reset to remote version of a branch
The scenario: your local Git history has become corrupted in some way and you want a clean history based on the current state of the remote. We will demonstrate with `main`.
```
git fetch origin
git reset --hard origin/master
```

View file

@ -16,7 +16,7 @@ With a full-scale Node application you will typically run three environments:
## Accessing the current environment
To determine the current environment we can use the variable **`process.env.NODE_ENV`**. This works globally regardless of the kind of Node app we are building.
To determine the current environment we can use the variable **`process.env.NODE_ENV`** from the [global process object](/Programming_Languages/Node/Architecture/Process_object.md). This works universally regardless of the kind of Node app we are building.
If you have not manually set up your environments, **`process.env.NODE_ENV`** will return `undefined`.
@ -61,8 +61,8 @@ For example:
Then to utilise config variables:
```js
const config = require('config');
console.log('Application name:' + config.get('name'));
const config = require("config");
console.log("Application name:" + config.get("name"));
```
If we toggled the different environments, we would see different outputs from the above code (assuming we had different config files in `/config` with different names).
@ -92,7 +92,7 @@ Then in our custom variable file:
We can then safely reference this value in the course of our normal code:
```js
console.log(config.get('password'));
console.log(config.get("password"));
```
<p style="color:red">! But how would this be achieved in a production server?</p>

View file

@ -0,0 +1,86 @@
---
categories:
- Programming Languages
tags:
- backend
- node-js
---
# The `process` object in Node.js
`process` is a global object accessible from anywhere in a Node application. It contains functionality that allows us to interact with information about the current process instance.
For example, we can use it to get environment information, read environment variables, communicate with the terminal and exit the current process.
## Managing runtime environments
See [Managing Environments](/Programming_Languages/Node/Architecture/Managing_environments.md).
## Accessing arguments: `process.argv`
We can use `process.argv` to return an array containing the command-line arguments passed when a Node process was launched. This could be a whole-app entrypoint (i.e. `index.js`) or a single file we are running.
For instance if we run the following file:
```js
// process-demo.js
console.log(3 + 3);
console.log(process.argv);
```
We get:
```bash
6
[
'/Users/thomasbishop/.nvm/versions/node/v16.10.0/bin/node',
'/Users/thomasbishop/prepos/testNode.js'
]
```
The first value is a reference to the Node runtime binary. The second is the file that was passed to node.
If we passed in a parameter we would get that too:
```
node process-demo.js --fakeFlag
```
Gives us:
```bash
[
"/Users/thomasbishop/.nvm/versions/node/v16.10.0/bin/node",
"/Users/thomasbishop/prepos/testNode.js",
"--fake-flag",
]
```
When writing command line Node applications we could easily write functions that parse standard input. For example:
```js
function parseStandardInput(flag) {
let indexAfterFlag = process.argv.indexOf(flag);
console.log(process.argv[indexAfterFlag]);
}
```
Say we ran a program that took in a username:
```bash
node userName.js --user Thomas
```
Then `parseStandardInput("--user")` would give us `"thomas"`
## Standard input and output `process.stdout`
```js
// alpha.js
process.stdout.write("Hello from file \n");
```
```bash
$ node alpha.js
$ Hello from file
```

View file

@ -56,6 +56,8 @@ N.Nisan, S.Schoken. 2021. **The Elements of Computing Systems** (Second Edition)
[NAND latch](http://hyperphysics.phy-astr.gsu.edu/hbase/Electronic/nandlatch.html)
[Lessons in Electric Circuits](https://www.allaboutcircuits.com/textbook/) [full textbook]
## General programming
R.C.Martin. 2008. **Clean Code**

View file

@ -7,8 +7,8 @@
- If it returns multiple values, how to isolate and loop through them
- What the weird variable symbols mean like errors and stuff
- Read up properly about `find` and `read`
- `.list` file extension
- Error handling
- `.list` file extension
- Error handling
## SQL
@ -35,3 +35,15 @@
- How can you rollback without a hard-reset, i.e. how can you keep the future state (from the point of view of the rolled-back branch) accessible?
- Tagging (also in relation to Git flow)
- See if there is an advanced Git course on LinkedIn
## JavaScript
Look into these new features:
- Proxy object
- `Object.hasOwn()`
- Top level `await`
- `Error.Prototype.cause()`
- Dynamic import
- Temporal
- `Promise.allSettled()`, `Promise.any()`