# --rbind mounts subdirectories that are required.
sudo mount /dev/sda3 /mnt/
sudo mount --rbind /proc/ /mnt/proc/
sudo mount --bind /sys/ /mnt/sys/
sudo mount --rbind /dev/ /mnt/dev/
sudo chroot /mnt/
# Repair grub in /etc/default/grub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// nestedTree is a tree structure containing subtrees under "nodes" property. d=1 is the default "depth of the tree" | |
function flatDeep(arr, d = 1) { | |
return d > 0 ? arr.reduce((acc, val) => acc.concat(Array.isArray(val.nodes) ? flatDeep(val.nodes, d - 1) : val), []) | |
: arr.slice(); | |
}; | |
let flat = flatDeep(nestedTree, Infinity); | |
// Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const idMapping = data.reduce((acc, el, i) => { | |
acc[el.id] = i; | |
return acc; | |
}, {}); | |
let root = []; | |
data.forEach(el => { | |
// Handle the root element | |
if (el.parent === null) { | |
root.push(el); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sudo /usr/local/bin/certbot-auto renew | |
sudo cp /etc/letsencrypt/live/domain.com/* /etc/lighttpd/certs/ | |
cd /etc/lighttpd/certs | |
sudo cat privkey.pem cert.pem | sudo tee merged.pem | |
sudo systemctl restart lighttpd.service | |
## Renew every two months |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# delete previous version if needed | |
INSTALL_DIR=/usr/share/code | |
if [ -d "$INSTALL_DIR" ]; then | |
echo "deleting: $INSTALL_DIR" | |
sudo rm -rf $INSTALL_DIR | |
fi | |
# download the rpm from https://code.visualstudio.com/download |
On the computer without public IP:
ssh -R 2222:localhost:22 loginOfServerWithPublicIP@publicIP
This connects to the server by SSH and builds a tunnel from the server with public IP on port 2222 to the computer without public IP on port 22 (SSH).
And then on the server:
ssh -p 2222 loginOfComputerWithoutPublicIP@locahost
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function long { | |
START=$(date +%s.%N) | |
$* | |
EXIT_CODE=$? | |
END=$(date +%s.%N) | |
DIFF=$(echo "$END - $START" | bc) | |
RES=$(python -c "diff = $DIFF; min = int(diff / 60); print('%s min' % min)") | |
result="$1 completed in $RES, exit code $EXIT_CODE." | |
echo -e "\n⏰ $result" | |
( say -r 250 $result 2>&1 > /dev/null & ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
typedef void (*functionType)(); | |
void doThis() { | |
printf("Hello World!\n"); | |
} | |
int main() { | |
functionType doVar = &doThis; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void printNumber(int nbr) | |
{ | |
printf("%d\n", nbr); | |
} | |
void myFunction(void (*f)(int)) | |
{ | |
for(int i = 0; i < 5; i++) | |
{ | |
(*f)(i); |
To change python version system-wide we can use update-alternatives command. Logged in as a root user, first list all available python alternatives:
# update-alternatives --list python
update-alternatives: error: no alternatives for python
The above error message means that no python alternatives has been recognized by update-alternatives
command. For this reason we need to update our alternatives table and include both python2.7
and python3.4
:
# update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode
NewerOlder