diff --git a/til.md b/til.md index dbefec1..593cbfb 100644 --- a/til.md +++ b/til.md @@ -5,26 +5,26 @@ Write code like it's synchrone ```javascript -let get = async (URL) => { - const retval = await fetch(URL) - if (retval.ok) { - this.playlists = await retval.json() - } else { - console.error("doh! network error") - } -} -get() +let get = async URL => { + const retval = await fetch(URL); + if (retval.ok) { + this.playlists = await retval.json(); + } else { + console.error("doh! network error"); + } +}; +get(); ``` Or use promise chaining ```javascript fetch(URL) - .then(stream => stream.json()) - .then(data => this.playlists = data) - .catch(error => console.error(error)) + .then(stream => stream.json()) + .then(data => (this.playlists = data)) + .catch(error => console.error(error)); ``` - + ## bash auto-reply `y` on installations or `fsck` repairs @@ -40,7 +40,6 @@ network diff FILE=/tmp/a diff -ru <(sort -u "$FILE") <(ssh user@host "sort -u $FILE") - ## ffmpeg extract audio-only from video file with ID3 tags @@ -51,15 +50,23 @@ record screen ffmpeg -f x11grab -s 1366x768 -i :0.0 -r 25 -threads 2 -c:v libx264 -crf 0 -preset ultrafast output.mkv - ## html ```html ``` @@ -74,33 +81,33 @@ drop all incomming ssh connections iptables -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j DROP - ## docker Delete all containers - * `docker rm $(docker ps -a -q)` +- `docker rm $(docker ps -a -q)` Delete all images - * `docker rmi $(docker images -q)` +- `docker rmi $(docker images -q)` Delete all dangling images - * `docker rmi $(docker images -f dangling=true -q)` +- `docker rmi $(docker images -f dangling=true -q)` Create docker network - * `docker network create mynet` +- `docker network create mynet` clean up - * `docker system prune` - * `docker volume rm $(docker volume ls -q --filter dangling=true)` +- `docker system prune` +- `docker volume rm $(docker volume ls -q --filter dangling=true)` run two docker `img` container with different names `foo` and `bar` and the can reach each other with domain name `foo` and `bar` - * `docker run --name foo --net mynet img` - * `docker run --name bar --net mynet img` + +- `docker run --name foo --net mynet img` +- `docker run --name bar --net mynet img` copy files from an image to `/tmp/some.file` @@ -127,7 +134,7 @@ create a patch from a modified file apply a diff patch git apply this.patch - + checkout a pull request add `fetch = +refs/pull/*/head:refs/remotes/origin/pr/*` to `.git/config` under the `[remote "origin"]` section. @@ -150,19 +157,18 @@ for rom converting community/ecm-tools 1.03-1 [Installiert] Error Code Modeler - `ecm2bin rom.img.ecm` # ufw list all rules - * `ufw status` +- `ufw status` disable/enable firewall - * `ufw enable` - * `ufw disable` +- `ufw enable` +- `ufw disable` # systemd @@ -215,7 +221,7 @@ http { listen 80; server_name 127.0.0.1; - + location / { proxy_redirect off; proxy_set_header Host $host; @@ -223,16 +229,16 @@ http { proxy_set_header Authorization "Basic ZW5lcmdpY29zOmVuZXJnaWNvcw=="; set $cors "1"; - + if ($request_method = 'OPTIONS') { set $cors "${cors}o"; } - + if ($cors = "1") { more_set_headers 'Access-Control-Allow-Origin: $http_origin'; more_set_headers 'Access-Control-Allow-Credentials: true'; } - + if ($cors = "1o") { more_set_headers 'Access-Control-Allow-Origin: $http_origin'; more_set_headers 'Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE'; @@ -242,7 +248,7 @@ http { add_header Content-Type text/plain; return 204; } - + proxy_pass https://some.url; } } @@ -291,10 +297,15 @@ http { insert on duplicated for MariaDB/MySQL ```javascript -async function insert_on_duplicated(table, data){ - let insert = knex(table).insert(data).toString(); - let update = knex(table).update(data).toString().replace(/^update .* set /i, ''); - return await knex.raw(`${insert} on duplicate key update ${update}`); +async function insert_on_duplicated(table, data) { + let insert = knex(table) + .insert(data) + .toString(); + let update = knex(table) + .update(data) + .toString() + .replace(/^update .* set /i, ""); + return await knex.raw(`${insert} on duplicate key update ${update}`); } ``` @@ -302,7 +313,7 @@ async function insert_on_duplicated(table, data){ list secrets - * `kubectl -n kube-system get secret` +- `kubectl -n kube-system get secret` https://blog.alexellis.io/kubernetes-in-10-minutes/ @@ -324,13 +335,14 @@ place key and sected into `.aws/credentials` aws_access_key_id = ... aws_secret_access_key = ... ``` + and do - ./goofys --endpoint ams3.digitaloceanspaces.com melmac /home/ec2-user/t/ +./goofys --endpoint ams3.digitaloceanspaces.com melmac /home/ec2-user/t/ # python -Python json dump with datetime. every time `JSON` doesn't know how to convert a value, it calls +Python json dump with datetime. every time `JSON` doesn't know how to convert a value, it calls the `default()` function. ``` @@ -342,45 +354,44 @@ print(json.dumps(my_py_dict_var, default = dtconverter)) ``` - ## ML ->> Neural networks are universal approximators - meaning that for any function F and error E, there exists some neural network (needing only a single hidden layer) -that can approximate F with error less than E. +> > Neural networks are universal approximators - meaning that for any function F and error E, there exists some neural network (needing only a single hidden layer) +> > that can approximate F with error less than E. -* https://en.wikipedia.org/wiki/Artificial_neural_network#Theoretical_properties -* https://en.wikipedia.org/wiki/Multilayer_perceptron +- https://en.wikipedia.org/wiki/Artificial_neural_network#Theoretical_properties +- https://en.wikipedia.org/wiki/Multilayer_perceptron ->> Normalisation is required so that all the inputs are at a comparable range. +> > Normalisation is required so that all the inputs are at a comparable range. -With two inputs (x1 and x2), where x1 values are from range 0 to 0.5 and x2 values are from range to 0 to 1000. When x1 is changing by 0.5, the change is 100%, and a +With two inputs (x1 and x2), where x1 values are from range 0 to 0.5 and x2 values are from range to 0 to 1000. When x1 is changing by 0.5, the change is 100%, and a change of x2 by 0.5 is only 0.05%. ## puppet -* list all nodes +- list all nodes - puppet cert list --all + puppet cert list --all -* remove a node +- remove a node - puppet cert clean + puppet cert clean -* add / accept a node +- add / accept a node - puppet cert sign + puppet cert sign # MySQL / MariaDB dump a live system without blocking -* for MyISAM -`nice -n 19 ionice -c2 -n 7 mysqldump --lock-tables=false > dump.sql` +- for MyISAM + `nice -n 19 ionice -c2 -n 7 mysqldump --lock-tables=false > dump.sql` -* for InnoDB -`nice -n 19 ionice -c2 -n 7 mysqldump --single-transaction=TRUE > dump.sql` +- for InnoDB + `nice -n 19 ionice -c2 -n 7 mysqldump --single-transaction=TRUE > dump.sql` -* allow user to create databases with prefix +- allow user to create databases with prefix ``` GRANT ALL PRIVILEGES ON `dev\_%` . * TO 'dev'@'%';` @@ -400,7 +411,7 @@ pkg_add bash nano ``` modload lua luactl create mycpu -luactl load mycpu ./cpu.lua +luactl load mycpu ./cpu.lua ``` print to `/var/log/messages` using systm module @@ -438,8 +449,6 @@ decrypt message with private openssl rsautl -decrypt -inkey ~/.ssh/my.key -in encrypted_message - - # nextcloud call `cron.php` from nextcloud which is running in a docker container @@ -452,7 +461,6 @@ mount with `davfs2` `sudo mount -t davfs https://nextcloud/remote.php/webdav /mount/point` - # xfs increase filesystem @@ -462,30 +470,28 @@ increase filesystem # yubikey In general you got - * 2 Slots - * 32 oath credentials storage +_ 2 Slots +_ 32 oath credentials storage #### oath-hotp 2nd slot for ssh auth - 1. generate secret - `dd if=/dev/random bs=1k count=1 | sha1sum` + `dd if=/dev/random bs=1k count=1 | sha1sum` 2. flash yubi key slot 2 with generated secret - `ykpersonalize -2 -o oath-hotp -o oath-hotp8 -o append-cr -a ` + `ykpersonalize -2 -o oath-hotp -o oath-hotp8 -o append-cr -a ` -#### oath totp for aws - -* set - `ykman oath add -t aws-username ` -* get - `ykman oath code bergholm -s` -* list - `ykman oath list` +#### oath totp for aws +- set + `ykman oath add -t aws-username ` +- get + `ykman oath code bergholm -s` +- list + `ykman oath list` # ansible -run tests in docker container +run tests in docker container `bin/ansible-test units -v --python 3.7 --docker default` @@ -499,4 +505,22 @@ variables with an `admin-` prefix are ADMIN variables, and you should use these UPDATE global_variables SET variable_value='admin:N3wP4ssw3rd!' WHERE variable_name='admin-admin_credentials'; SAVE MYSQL VARIABLES TO DISK; LOAD MYSQL VARIABLES TO RUNTIME; -``` \ No newline at end of file +``` + +# btrfs + +on small devices + +`sudo mkfs.btrfs --mixed -f /dev/nvme1n1` + +mount with zstd compression + +```yaml +- name: mount with zstd compression + mount: + path: /mnt/ + src: /dev/nvme1n1 + fstype: btrfs + opts: compress=zstd,discard,nofail,defaults + state: present +```