Skip to content

Instantly share code, notes, and snippets.

View cramhead's full-sized avatar

Marc d'Entremont cramhead

View GitHub Profile

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@cramhead
cramhead / JavaScript
Last active July 28, 2021 21:08
JS/TS Snippets
Prints nested arrays as one string. Handy for Quokka.js
```
function printNestedArray(arr, depth = 0) {
let result = ''
const indent = ' '.repeat(depth));
if (Array.isArray(arr)) {
result = result + `\n${indent}[`
for (const item of arr) {
@cramhead
cramhead / mysqlBulkUpdate.sql
Created September 13, 2019 20:26
Updates rows when the ids conflict with existing data
INSERT INTO user (id, uid) VALUES (1, 'uid1'), (2, 'uid2'), (3, 'uid3') ON DUPLICATE KEY UPDATE id=VALUES(id), uid=VALUES(uid);
@cramhead
cramhead / JavaScript Terms.md
Last active September 9, 2019 02:24
A set of terms for JavaScript

Temporal Dead Zone: term that expresses that time between which a variable is available due to it being in a valid scope and exists, i.e. is declared.

Early Activation: When a function expression has not yet been defined it can still be referenced, as long as it's not called.

Function Hoisting: All functions are available to be called when entering a scope where they are defined; as if they were hoisted to the top of the scope

Bound Variables: Variables associated with scope, e.g. parameters and local variables

Free Variables: Variables available via the enclosing environment. For example, a A function can define another function B within it. The variables defined in A, available in B.

@cramhead
cramhead / Bash.md
Last active February 11, 2019 05:44
Notes course

Bash

Variables don't put space before or after = sign. Otherwise, it expects the next thing is a command, e.g. a=1 sleep 1; echo a is $a # a is visible to the sleep command Special chars, e.g. a space, need quotes around them, e.g. echo "some stuff" set value at time of declaration. Use unset to remove it. Prefix with $ to get value

export myvar=10 # export puts the variable in your environment 
declare -x mysecondvar=20
export -f myfunc # exports a function
echo myvar is $myvar and mysecondvar is $mysecondvar #myvar is 10
  1. Debug mode Run the node process in debug mode set the npm start script to start in debug mode. This will send debugging information to port 5858 by default.
  scripts": {
   "start": "node --debug ."
  }
@cramhead
cramhead / Building Docker Images.md
Last active February 16, 2024 09:17
Docker commands with comments

Building Docker Images

Dockerfiles describe how to build docker images

docker build -t tagName . build an image from the dockerfile in the current folder and call is tagName

Each line make a new image that is used in the subsequent step. So if your program downloads a big file then the next line only uses a small bit of it the image will include the big image. Otherwise, if your program downloaded a big image and used a small bit of it on the same line the image only includes the small bit. Much better

Previous image is not modified. So if there is no change that step is not rerun. Put the parts of the code that change the most at the end of the docker file so you can leverage this feature. Note, if you want to redo an part of the code, where things didn't change, you must tell docker as it will otherwise skip it

"build": "webpack --mode production"
"start": "node dist/main.js"
const nodeExternals = require('webpack-node-externals')
module.exports = {
target: 'node',
externals: [nodeExternals()]
};