Skip to content

Instantly share code, notes, and snippets.

@andmax
andmax / httpserver.service
Created April 27, 2020 14:06
Ubuntu systemd service for HTTP server
On /etc/systemd/system/httpserver.service:
[Unit]
Description = Http server
Documentation=man:SimpleHTTPServer(1)
After = network.target
[Service]
Type=simple
WorkingDirectory=/home/deepstation/www
ExecStart=/usr/bin/python -m SimpleHTTPServer 9188 &
@andmax
andmax / ssh_passphrase_once
Created May 7, 2020 17:35
Type in passphrase for SSH private key only once
ssh-agent bash
ssh-add ~/.ssh/id_rsa
@andmax
andmax / windows_sshd_config
Last active May 10, 2020 11:14
Make OpenSSH server work on Windows changing the sshd_config file
1- win > apps and features > optional features > add a feature
2- Install OpenSSH Server
3- win > services > Start OpenSSH SSH Server
4- It will create files on: %ProgramData%\ssh
5- Edit: %programdata%\ssh\sshd_config (%programdata% == C:\ProgramData)
6- Change default port by uncommenting first configuration line:
Port <some port other than 22>
7- Find line below, uncomment it and change to not allow password:
PasswordAuthentication no
8- Comment last two lines with:
@andmax
andmax / sed_grep_inset_algebra_vars.sh
Last active May 18, 2020 13:53
Use double quotes for commands within variables and shell $expr for algebraic expressions within variables
#!/bin/bash
################################################################################
# The following is an explanation of the one-line command below:
# First grep to make sure the search string is present in the log file.
# Second do the sed -i (edit log file in place) by removing a range of
# lines defined in the double quotes. (Double quotes here are very important
# to allow to insert shell variables defined by dollar sign $ inside it.)
# The range of lines is from the first line to an L line number as "1,Ld".
# The line number L is defined by an algebraic expression N-2 as $(expr N - 2).
# (The spaces in-between elements inside the expression are very important.)
@andmax
andmax / clear_swap_memory
Created May 13, 2020 14:14
Clear linux swap memory
sudo swapoff -a && sudo swapon -a
@andmax
andmax / ssh_remote_add_pub_key
Created May 22, 2020 10:34
Add SSH public key from local .ssh/id_rsa.pub to remote .ssh/authorized_keys
ssh <user>@<machine> "echo \"`cat ~/.ssh/id_rsa.pub`\" >> .ssh/authorized_keys"
@andmax
andmax / Setup_SLURM
Last active October 30, 2023 14:26
Tips to compile, install and run jobs using SLURM
1- The problem is to make SLURM (https://slurm.schedmd.com/) work properly
2- SLURM is very intricate and difficult to set up (here is SLURM 20.02)
3- It may be important to have NVIDIA library path added, e.g.:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/nvidia-410
4- SLURM depends on MUNGE that can be installed using apt as:
sudo apt-get update
sudo apt-get install libmunge-dev libmunge2 munge
sudo apt-get clean
5- The same is not true for SLURM itself as its apt package is old
6- So it seems important to compile it from source code, wgetting aa:
@andmax
andmax / about_ip_slash_notation_sub_nets
Last active June 9, 2020 13:47
About IP address/subnet number or the slash notation to define sub-net masks
1- Understand slash notation and subnet mask as:
2- IP address / number of 1's in the subnet mask, i.e.:
3- An IP of 192.168.42.23 with a subnet mask of 255.255.255.0
4- Will have a slash notation as: 192.168.42.23/24
5- That is there are 24 number ones in 255.255.255.0 or
6- 11111111.11111111.11111111.00000000
7- A subnet mask says what parts of the IP address can change (0)
8- and cannot change (1), so the above mask (255.255.255.0) is
9- saying only the last part of the IP address can vary or: 192.168.42.*
10- When using iptables to setup rules to access a host machine
@andmax
andmax / N_dimension_neighbors
Last active June 26, 2020 17:08
List all neighbor indices at a certain distance from a given pixel position
# The problem is to find all neighbor indices l_neighbors at a distance d from a given pixel position pp in any dimension
# It uses itertools.product to do n-dimensional list cross product
import itertools
pp, d = [2, 2], 2 # Example pp pixel position and d distance
li = [ list(range(ppi-d, ppi+d+1)) for ppi in pp ] # list of each 1-dimensional pp neighbors for each dimension
l_neighbors = [ pli for pli in itertools.product(*li) if any([ p in [l[0], l[-1]] for p, l in zip(pli, li) ]) ]
@andmax
andmax / copy_package_between_conda_envs
Created June 26, 2020 17:47
Copying one package from one conda environment to another
1- The problem is to copy one specific package (e.g. mypackage) in (Ana)conda
2- Environment (e.g. base env) to another conda env (e.g. myenv), it may be
3- Built or directly installed (via pip or not) and exist three files called:
4- mypackage.cp37-win_amd64.pyd, mypackage.py, mypackage-1.0-py3.7.egg-info
5- In the site-packages of the base conda env (here Anaconda 3) in:
6- ~/Anaconda3/Lib/site-packages/
7- And we can just copy these files from there to the target conda env as:
cp ~/Anaconda3/Lib/site-packages/mypackage* ~/Anaconda3/envs/myenv/Lib/site-packages/
8- This copying does not guarantee that all packages dependencies (requirements) of
9- The mypackage being copied is satisfied in the target environment,