4.05.2024

Linux systemd services

https://www.tecmint.com/list-all-running-services-under-systemd-in-linux/

1. List all services
# systemctl --type=service

2. Get service status
# systemctl status sentinel_26379.service

3. Restart service
# systemctl restart sentinel_26379.service

8.10.2020

iterm2 Clear all Sessions on Current Tab

On mac, save this as /Users/[username]/Library/Application Support/iTerm2/Scripts/AutoLaunch/clear_current_tab.py
#!/usr/bin/env python3

import asyncio
import iterm2
import time

async def main(connection):
    app = await iterm2.async_get_app(connection)
    @iterm2.RPC
    async def clear_current_tab():
        code = b'\x1b' + b']1337;ClearScrollback' + b'\x07'
        window = app.current_terminal_window
        tab = window.current_tab
        for session in tab.sessions:
            await session.async_inject(code)
    await clear_current_tab.async_register(connection)

iterm2.run_forever(main)
Now bind it to a keystroke in Prefs > Keys by selecting the action Invoke Script Function and giving it the invocation clear_current_tab().

7.14.2020

Use nvm For Managing Dev Environments For Any Version of Angular

Install nodejs
1. Install xcode
$ xcode-select --install
2. Install nvm
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
3. Open another bash session to get settings from nvm install
4. List installed node versions
$ nvm list
5. Or list from the cloud (last 9 versions)
$ nvm ls-remote | tail -n9
6. Install v14.5.0
$ nvm install v14.5.0
7. Setup this version as default
$ nvm use v14.5.0
$ nvm alias default v14.5.0
8. Check node version
$ node -v
v14.5.0
9. Update npm
$ npm install -g npm
10. Check npm version
$ npm -v
6.14.6

Install yarn package manager
1. $ npm install -g yarn

Install angular cli on local project
1. Go to project base directory
$ cd ./project/ui
2. Add angular cli (with versioning if needed)
$ yarn add @angular/cli@9.1.12
3. Check version
$ ng --version
Angular CLI: 9.1.12
Node: 14.5.0
OS: darwin x64
Angular: 9.1.12

3.20.2020

Revert back to previous Django Migration

This procedure is only for the development environment while actively working on changes. Say you have several migrations already created but since after making changes realized that some of them are unnecessary and you want to come up with just one migration before checking in code for production deploy. This procedure will revert back migrations to previous level and then will give opportunity to create just one migration file that can then be deployed to production. This can potentially damage databases if not applied properly so use your discernment.
1. Show migrations for an app
$ python3 manage.py showmigrations orchestrator
...
 [X] 0051_auto_20191217_2328
 [X] 0052_auto_20200212_2250
 [X] 0053_job_miscellaneous

2. If you want to revert back the last 2 migrations
$ python3 manage.py migrate orchestrator 0051_auto_20191217_2328
Operations to perform:
  Target specific migration: 0051_auto_20191217_2328, from orchestrator
Running migrations:
  Rendering model states... DONE
  Unapplying orchestrator.0053_job_miscellaneous... OK
  Unapplying orchestrator.0052_auto_20200212_2250... OK

3. Show migrations again
$ python3 manage.py showmigrations orchestrator
...
 [X] 0051_auto_20191217_2328
 [ ] 0052_auto_20200212_2250
 [ ] 0053_job_miscellaneous

4. Delete the undesired migration files
$ rm 0052_auto_20200212_2250.py 0053_job_miscellaneous.py

5. Show migrations again
$ python3 manage.py showmigrations orchestrator
...
 [X] 0051_auto_20191217_2328

6. Now make a new migration. This will have all latest changes in model
$ python3 manage.py makemigrations
Migrations for 'orchestrator':
  orchestrator/migrations/0052_job_miscellaneous.py
    - Add field miscellaneous to job

7. Now apply new migration
$ python3 manage.py migrate
Running migrations:
  Applying orchestrator.0052_job_miscellaneous... OK

3.08.2019

Use CSS flexbox for elements to wrap automatically while centered

I learned from this post:
.flex-container-center {
  padding: 0 20px 0 20px;
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}

12.13.2018

Getting Started with Angular NgRx

1. Install ngrx
$ yarn add @ngrx/store

2.  Install Redux Store dev tools
Install chrome browser Redux DevTools extension
$ yarn add @ngrx/store-devtools

3. Install NgRx Effects
$ yarn add @ngrx/effects

12.12.2018

Typescript (Javascript) Cheat Sheet

1. Falsy values
false — boolean false
0 — number zero
“” — empty string
null
undefined
NaN — Not A Number

2. Immutability conversion
mutable:
this.currentUser.classes.push(classId);

immutable:
this.currentUser = Object.assign({}, this.currentUser,
     {classes: this.currentUser.classes.concat([classId])});

mutable:
user.classes = user.classes || [];
this.currentUser = user;

immutable:
this.currentUser = Object.assign({}, user,
     {classes: user.classes || []});