Skip to content

Instantly share code, notes, and snippets.

@andmax
andmax / migrate_git_submodule
Last active March 30, 2021 14:42
Teaches migration of git repo from one url to another + git submodule
### To simply clone as git submodule do:
git submodule add <clone_repo_url>
git commit -am "new submodule added"
### To migrate git repo into submodule
git clone <old_repo_url>
git remote add <new_repo_name> <new_repo_url>
git push <new_repo_name> master
@andmax
andmax / git_master_pointing_another_branch
Last active September 28, 2020 12:34
Git master branch merge (pointing to) another branch
1. The problem is to make changes in <another_branch> until satisfied
2. having several branches with different versions that maybe entitled
3. to be the master branch, and then selecting <another_branch>
4. to be the master branch:
git checkout <another_branch>
<make changes as needed>
git merge -s ours master
git checkout master
git merge <another_branch>
git push origin master
@andmax
andmax / rename_git_branch
Created September 28, 2020 12:33
Rename an existing git branch
1. The problem is to rename a git branch named <current_branch_name>
2. that already exists to a new name <new_branch_name>:
git checkout <current_branch_name>
git branch -m <new_branch_name>
git push origin -u <new_branch_name>
git push origin --delete <current_branch_name>
@andmax
andmax / git_head_detached
Created November 10, 2020 16:13
Teaches a simple fix when git HEAD is detached
1. Sometimes a git submodule may lose its head during commit
2. It appears as: HEAD detached ...
3. This may be because the commit done as submodule creates
4. a "virtual" branch (hopefully will be fixed in the future)
5. One way to fix it is to do:
cd <submodule dir>
git add <changed files in submodule>
git commit -m <message>
git status # showing HEAD detached
git branch tmp
@andmax
andmax / simple_ssh_tunnel_jupyter
Created November 19, 2020 13:48
Simple way to do ssh tunnel to access jupyter notebook on server
1. On server side do:
$ jupyter notebook --port 9999 --ip=* --no-browser
2. On client side do:
$ ssh -NL 9999:localhost:9999 user@server
3. Then open browser and access:
htpp://localhost:9999
4. Put the token that appear on the server side
@andmax
andmax / allow_conda_env_in_jupyter_notebook
Last active January 6, 2021 15:30
How to allow different conda environment inside jupyter notebook
1. For example:
conda create --name tf
conda activate tf
conda install -c conda-forge tensorflow
2. It is good to have the conda tab in jupyter notebook:
conda install nb_conda
3. It is also good to update conda env. kernels automatically:
conda install nb_conda_kernels
4. You should have ipython kernel in the environment:
conda install ipykernel
@andmax
andmax / bash_if_file_exists_sed_path
Created January 14, 2021 19:14
If file exists in bash to fix path with sed
1. The problem is with a file created by someone
2. (docker or nimbix internal configuration or ...)
3. in profile.d that sets PATH without appending to it
4. removing the previous content of PATH that can be set
5. by /etc/environment (a global system wide way of setting
6. environment variables such as PATH) the fix tests if the
7. bug file exists in a bash script to then replace its
8. content with a sed replacing substring "PATH=" by "PATH+=\:".
9. The result is:
if [ -f "/etc/profile.d/00-container-environment.sh" ]; then
@andmax
andmax / sed_last_line_replace_last_char
Created January 14, 2021 19:22
Replace the last character of the last line of a file with sed
1. The problem is to add a new entry to the PATH
2. environment variable for all users system wide
3. for both logged-in (interactive) and non-logged-in
4. (non-interactive) shells using the /etc/environment
5. (the /etc/profile.d scripts are only applied to logged-in shells)
6. which is not a bash script rather a list of one variable set
7. (without appending) per line and I want to replace the already
8. existing PATH in the last line (there is only one line)
9. by removing the last character (a double quote) with a
10. colon (:) and then appending the new entry to PATH
@andmax
andmax / snaps_remove_all
Last active March 17, 2021 13:26
Remove ubuntu snaps
# The problem is to get rid off many buggy file systems when doing
# "df -h" because of this "snaps" from Ubuntu, it is just better to
# remove all snaps and then it will clean the list of disk usage:
sudo rm -rf /var/cache/snapd/
sudo apt autoremove --purge snapd gnome-software-plugin-snap
rm -rf ~/snap
@andmax
andmax / https_proxy_in_wget_xmeters
Last active March 17, 2021 13:37
HTTP(s) Proxy in wget to download XMeters
# Sometimes it is better to use wget to download a file from a link,
# e.g. when an .exe file (such as XMetersSetup to install XMeters on
# windows --- a nice tool to monitor CPU/memory in the taskbar) is
# blocked by clicking on it using the web browser, and then wget
# itself may be blocked by proxy, wget command has several arguments
# to set the proxy using an already set environment variable, via:
wget -e use_proxy=yes -e https_proxy=$https_proxy https://entropy6.com/xmeters/downloads/XMetersSetup.exe