Introduction

What ?

Brain is like a draft notebook. A place to store all my notes.

Why ?

While browsering dev.to, I found this article :

Then I decide to give this concept a shot.

Licence

You can do whatever the fuck you want with this.

        DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                Version 2, December 2004

Copyright 2017 papey

Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.

        DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

 0. You just DO WHAT THE FUCK YOU WANT TO.

Dev

Web

All dev web stuff goes here

front

Babel and babel-preset-stage-2

If you want use the "Spead Operator" eg ... in javascript, you need babel-preset-stage-2.

yarn add -D babel-preset-stage-2

Then enable it your babelrc :

{
    "presets": [
        ["es2015", { "modules": false }],
        ["stage-2"]
    ]
}

js

Presentation of the main ES6 features

Spread Operator

It allows an iterable to expand items in it.

array = [1, 2];
appended = [3,4];

all = [...aray, ...appended]
console.log(all)

This can be usefull in some situations like this one :

array = [1, 2, 3, 4];
console.log(Math.min(...array));

instead of the old syntax

array = [1, 2, 3, 4];
console.log(Math.min.apply(null, array));

Rest Operator

Represent infinite number or args in an array

const sum = (...numbers) => {
    return numbers.reduce((previous, current) => {
        return previous + current;
    });
};

Arrow Function

Function can now be written like this

const f = (a, b) => a + b;
console.log(f(1,2));

instead of

function f(a, b) {
    return a + b;
}
console.log(f(1,2));

Default parameters

With arrow syntax !

const f = (a = 10) => console.log(a);
f();
f(1);

Destructuring (arrays and objects)

With arrays

const array = [1, 2];
const [a, b] = array;
console.log(a, b)

or objects

const person = { name: "Jesus", age: "33" };
const { name, age } = person;
console.log(name, age);

Tools

Git

Fetch a remote branch

  • Create a local branch that tracks a remote branch
git checkout --track origin/develop

If you want to change the name of the local branch (NOT A GOOD IDEA)

git checkout --track -b gniagnia origin/develop

Ammend without editing commit message

git commit --ammend --no-edit

Copy current HEAD sha sum to clipboard

git rev-parse HEAD | xclip

SVN

Commit only selected files

svn commit -m "Message" README src/example/script.pl

Ops

Shell Tips

Find stuff eating all SWAP (kudos gardouille)

find /proc -maxdepth 2 -type f -iname status -exec grep -HR VmSwap {} \; | grep -v " 0 kB"

Tools

Ansible

List all tags

ansible-playbook -i host.targets -v site.yml --list-tags

Start at a specific task (life savior)

ansible-playbook -i host.targets -v site.yml --start-at-task "The audacious task"

List hosts

ansible-playbook -i host.targets -v site.yml --list-hosts

Limit hosts

ansible-playbook -i host.targets -v site.yml --limit hostname

Jinja2, templates & carriage return

To tell Jinja2 to not mess with carriage return in templates add

#jinja2: trim_blocks:False
---

at the top of the template file

Docker

Inspect

Get container ip

docker container inspect --format='{{range .NetworkSettings.Networks }}{{ .IPAddress }}{{ end }}' upbeat_babbage

MongoDB

Non interactive conn from CLI (kudos lukhas)

Docs says

mongo --username user --password 'passwd'

Reality says

mongo --username user --password='passwd'

OpenSSL

Checking

CSR

openssl req -text -noout -verify -in request.csr

Key

openssl rsa -in privkey.key -check

Cert

openssl x509 -in certficate.crt -text -noout