Skip to content

fdiblen/fish-memory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 

Repository files navigation

Fish memory

Tips & Tricks to help my fish memory and not to google the same stuff over and over again.

Networking

List active tcp ports

watch ss -antlp

Shell

Find and replace in many files

grep -iR 'search' | xargs sed -i 's/search/replace/g'

Git

Undo last commit

Source

$ git commit -m "Something terribly misguided" # (0: Your Accident)
$ git reset HEAD~                              # (1)
<< edit files as necessary >>                  # (2)
$ git add .                                    # (3)
$ git commit -c ORIG_HEAD                      # (4)

Merge branches

git checkout master
git merge dev
git push origin master

Push to different remote branch

git push origin master:newBranch

Fetch a file/folder from diffrent branch

git checkout <branch_name> -- <paths>

To get package.json from dev branch to current branch:

git checkout dev -- package.json

Commit current changes to different (existing )branch

git stash
git checkout other-branch
git stash pop

The first stash hides away your changes (basically making a temporary commit), and the subsequent stash pop re-applies them.

Commit current changes to new branch

git stash
git checkout -b new-branch
git stash pop

Remove folder from entire git history

git filter-branch -f --tree-filter "rm -rf FOLDERNAME" --prune-empty HEAD
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
echo FOLDERNAME/ >> .gitignore
git add .gitignore
git commit -m "Removing FOLDERNAME from git history"
git gc
git push origin master --force

Sign commits by default

git config --global user.signingkey <YOUR_SIGNING_KEY>
git config --global commit.gpgsign true
git config --global gpg.program gpg

GPG

List keys

gpg --list-secret-keys --keyid-format LONG

Export key

gpg --armor --export 189ABH19KLDU83

SSH(FS)

Mounting a remote system:

sshfs -p 22 -C -o follow_symlinks,auto_cache,reconnect ~/MOUNT_FOLDER USERNAME@SERVERIP:/home/USERNAME

Save ssh passphrase in (gnome)keyring

Install seahorse

sudo pacman -S seahorse
/usr/lib/seahorse/ssh-askpass ~/.ssh/id_rsa

SSH password auth

user=test
useradd -m -d /home/$user -s /bin/bash $user
ssh-keygen -b 2048 -t rsa -f ./$user'_sshkey' -q -N ""
mv $user'_sshkey' $user'_sshkey'.private
mkdir -p /home/$user/.ssh
cat $user'_sshkey'.pub > /home/$user/.ssh/authorized_keys
chown -R $user:$user /home/$user/.ssh
chmod 600 /home/$user/.ssh/authorized_keys
chmod 700 /home/$user/.ssh
cat $user'_sshkey'.private

Docker

Run GUI apps

xhost +si:localuser:root
docker run --rm -it --net=host \
    --privileged \
    -e DISPLAY \
    --device /dev/dri \
    --device /dev/snd \
    --device /dev/video0 \
    --device /dev/input \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -v /etc/localtime:/etc/localtime:ro \
    -v $(pwd):/app \
    ubuntu /bin/bash

Linux iso --> bootable USB drive

dd bs=4M if=path/to/distro.iso of=/dev/sdX status=progress oflag=sync

GPUs

NVIDIA devices

docker run --rm -ti --runtime=nvidia nvidia/cuda nvidia-smi

PyTorch

docker run -it --rm --runtime=nvidia --shm-size=1g -e NVIDIA_VISIBLE_DEVICES=0,1 nvcr.io/nvidia/pytorch

Tensorflow

docker run \
    --runtime=nvidia \
    --rm \
    -ti \
    -v "${PWD}:/app" \
    gcr.io/tensorflow/tensorflow:latest-gpu \
    python /app/benchmark.py cpu 10000

OpenGL

xhost +si:localuser:root
docker run --runtime=nvidia -ti --rm -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix nvcr.io/nvidia/pytorch

Deployment

Heroku

docker build --network=host -t spot .

New image

npm install -g heroku
heroku login
heroku container:login
heroku create
heroku container:push spot
heroku container:release spot
heroku open

Exisiting image

#docker tag registry.heroku.com//

docker tag nlesc/spot registry.heroku.com/nlesc-spot/dev

#docker push registry.heroku.com//

docker push registry.heroku.com/nlesc-spot/dev

Python

Http server

python3 -m http.server --directory ./ 8080

Pyenv installation (Archlinux)

yay -S pyenv
pyenv install --list
pyenv install 3.7.2
pyenv global 3.7.2
pip install --upgrade pip

Virtual environment

venv

python3 -m venv .venv
. .venv/bin/activate.fish # fish shell
. .venv/bin/activate # bash
pip install --upgrade pip

pipenv

pip install -U pipenv
cd my_project
pipenv install

Quick tutorial

Use virtualenvironment in Visual studio code

https://code.visualstudio.com/docs/python/environments

Clear variable on IPython/Jupyter

%reset
%reset_selective variable_name

Upgrade outdated Python packages

pip install $(pip list --outdated | awk 'NR>2 { print $1 }') --upgrade

Anaconda

Create an environment
conda create -n nso python=3.7 pandas
Export environment
conda env export -c conda-forge -n nso --override-channels | grep -v "^prefix: "  > environment.yml
List environments
conda env list
Create an environment from a file
conda env create -f environment.yml
Deactivate an environment
conda deactivate
Remove the environment
conda env remove -n nso

Nodejs

Update outdated packages

npm i -g npm-check-updates && ncu -u && npm i

GNOME

Set Nautilus as default file manager

xdg-mime default org.gnome.Nautilus.desktop inode/directory

add Desktop bookmark to nautilus (files)

gsettings set org.gnome.desktop.background show-desktop-icons true
gsettings set org.gnome.desktop.background draw-background true

Xterm

Start xterm with a proper font.

xterm -fa 'Monospace' -fs 15

UFW

sudo ufw enable
sudo ufw default deny
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 22
sudo ufw logging on
sudo ufw status

Systemd

list targets

systemctl list-units -t target --all

get default target

systemctl get-default

see what target needs

systemctl show -p "Wants" graphical.target

show enabled services

systemctl list-unit-files --state enabled

show failed services

systemctl list-units --failed

show logs of a service

journalctl -u optimus-manager.service

About

Tips & Tricks to help my fish momery

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published